【问题标题】:How can I read multiple S3 buckets using Glue?如何使用 Glue 读取多个 S3 存储桶?
【发布时间】:2021-03-12 17:30:51
【问题描述】:

使用 Spark 时,我可以使用前缀中的 * 从多个存储桶中读取数据。比如我的文件夹结构如下:

s3://bucket/folder/computation_date=2020-11-01/
s3://bucket/folder/computation_date=2020-11-02/
s3://bucket/folder/computation_date=2020-11-03/
etc.

使用 PySpark,如果我想读取第 11 个月的所有数据,我可以这样做:

input_bucket = [MY-BUCKET]
input_prefix = [MY-FOLDER/computation_date=2020-11-*]
df_spark = spark.read.parquet("s3://{}/{}/".format(input_bucket, input_prefix))

如何使用 Glue 实现相同的功能?以下似乎不起作用:

input_bucket = [MY-BUCKET]
input_prefix = [MY-FOLDER/computation_date=2020-11-*]
df_glue = glueContext.create_dynamic_frame_from_options(
            connection_type="s3",
            connection_options = {
                "paths": ["s3://{}/{}/".format(input_bucket, input_prefix)]
            },
            format="parquet",
            transformation_ctx="df_spark")

【问题讨论】:

    标签: python amazon-web-services apache-spark pyspark aws-glue


    【解决方案1】:

    我使用 spark 而不是 Glue 读取文件

    glueContext = GlueContext(SparkContext.getOrCreate())
    spark = glueContext.spark_session
    
    input_bucket = [MY-BUCKET]
    input_prefix = [MY-FOLDER/computation_date=2020-11-*]
    df_spark = spark.read.parquet("s3://{}/{}/".format(input_bucket, input_prefix))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2020-01-02
      • 2018-10-25
      • 1970-01-01
      • 2021-09-27
      • 2021-08-14
      相关资源
      最近更新 更多