【问题标题】:pyspark in AWS Glue skip bad fileAWS Glue 中的 pyspark 跳过错误文件
【发布时间】:2020-03-23 02:58:55
【问题描述】:

我在 AWS Glue 中使用 pyspark 来读取 ETL 100K S3 文件,但是,我没有读取数十个文件的权限。

我使用了以下代码:

datasource0 = glueContext.create_dynamic_frame_from_options("s3",
    {'paths': ["s3://mykkkk-test"],
    'recurse':True,
    'groupFiles': 'inPartition',
    'groupSize': '10485760'}, 
    format="json",
    transformation_ctx = "datasource0")
## @type: toDF
## @args: []
## @return: df
## @inputs: [frame = datasource0]
df = datasource0.toDF()

它说

An error occurred while calling o70.toDF. java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
...
Caused by: java.io.FileNotFoundException: No such file or directory
s3://mykkkk-test/1111/2222/3333.json

我没有读取 3333.json 的权限,然后整个作业停止了。

有没有办法捕获异常并跳过文件,让脚本继续处理其他文件?

【问题讨论】:

    标签: pyspark aws-glue


    【解决方案1】:

    不,您不能...这是因为 spark 假定我可以访问您提到的作为源的文件夹中的所有数据文件。您最好的选择是事先确定您有权访问的文件列表,将它们移动到不同的文件夹,然后从那里读取数据。

    或者尝试获取您可以访问的文件列表,然后在循环中单独准备每个文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2019-07-23
      • 1970-01-01
      • 2018-08-31
      • 2021-09-13
      相关资源
      最近更新 更多