使用Broker Load无缝加载Hive ETL Union表到StarRocks
背景描述
Python脚本读取hive库表文件,通过Broker Load把数据导入starrocks
问题描述
表etl_deploy_table是几个表通过ETL union之后输出的表,当我使用Python脚本把此表数据导入starrocks时报错如下:
load failed!!! error_msg: type:ETL_RUN_FAIL; msg:No source file in this table(table_name)
问题原因
代码读取文件是路径是 hdfs://mycluster/user/hive/warehouse/fdp/{db}.db/{table}/* ,这样肯定多了一层目录,
问题解决
- 简单粗暴式:需要修改file_path追加 /*
hdfs://mycluster/user/hive/warehouse/fdp/{db}.db/{table}/*/*
- 优雅方式:遍历目录,获取子目录,再加载文件
intermediate_directory = '/path/to/intermediate_directory' command = ['hdfs', 'dfs', '-ls', intermediate_directory] output = subprocess.check_output(command).decode('utf-8') # 解析输出以获取所有子目录 directories = [line.split()[-1] for line in output.split('\n') if line.startswith('d')]
以下配图可看出hdfs文件目录层级关系



浙公网安备 33010602011771号