我在S3目录中有很多实木复合地板文件。目录结构可能因vid而异。像这样的东西:
bucketname/vid=123/year=2020/month=9/date=12/hf1hfw2he.parquet
bucketname/vid=456/year=2020/month=8/date=13/34jbj.parquet
bucketname/vid=876/year=2020/month=9/date=15/ghg76.parquet
我有一个包含所有vid的列表
vid_list = ['123','456','876']
在没有有效性能问题的情况下,我如何一次读取month = 9的所有文件?
current_month=9
temp_df = sqlContext.read.option("mergeSchema", "false").parquet('s3a://bucketname' + 'vid={}/year=2020/month={}/*/*.parquet'.format(*vid_list,current_month))
这给我错误Path does not exist: file:/Users/home/desktop/test1/vid=123/year=2020/month=456/*/*.parquet;
。有什么办法可以有效地实现这一目标吗?
答案 0 :(得分:0)
尝试以下代码:
vid_list = '(' + '|'.join(['123','456','876']) + ')'
current_month=9
temp_df = sqlContext.read.option("mergeSchema", "false").parquet('s3://bucketname/' + 'vid={}/year=2020/month={}/*/*.parquet'.format(vid_list,current_month))
// URL should look like: s3://bucketname/vid=(123|456|876)/year=2020/month=9/*/*.parquet
您的代码中有错误:月值为 456 ,应为 9
file:/Users/home/desktop/test1/vid=123/year=2020/month=456/*/*.parquet;