【发布时间】:2021-09-09 04:10:21
【问题描述】:
我有多个按 id 分类的 parquet 文件,如下所示:
/user/desktop/id=1x/year=2020/month=8/day=12/file1.parquet
/user/desktop/id=2x/year=2020/month=8/day=15/file2.parquet
/user/desktop/id=3x/year=2020/month=9/day=11/file3.parquet
/user/desktop/id=4x/year=2020/month=8/day=22/file4.parquet
我有一个包含所有 id 值的 python 列表,如下所示:
id_list = ['1x','2x','3x']
我想一次读取 id_list 中存在的 id 的所有文件,并且我想读取对应于 month=8 的文件 所以,对于这个例子,只有 file1 和 file2 应该被读取。
我是这样做的:
sub_path = '/*/*/*/*.parquet'
input_df = sqlContext.read.parquet('/user/desktop/' + 'id={}'.format(*id_list) + sub_path)
这只会选择 id_list 的第一个 id 内的文件,即 id='1x'。谁能帮我这里缺少什么?
【问题讨论】:
-
一次所有文件是什么意思?您要读取指定 id 下的所有文件还是该 id 内特定于某天、某月、某年的文件?
-
@Shrey Jakhmola 我想一次读取 id_list 中存在的 id 的所有文件。对于这个例子,我应该能够读取属于 id=1x,2x 和 3x 的三个文件,因为 id_list 中不存在 4x,但我这样做的方式只是读取一个属于 id-1x 的文件
-
和“一次”-我想说,如果可能的话-想在一行中读取所有匹配的文件。不想先创建空数据框,循环遍历ids,创建个人数据框,联合所有这些事情..
标签: apache-spark pyspark apache-spark-sql