在 AWS Glue ETL 作业中从 S3 加载分区 json 文件
Load partitioned json files from S3 in AWS Glue ETL jobs
我正在尝试加载 json 个在 S3 存储中这样分区的文件:
|-json-data
|-x=something
|-y=something
|-data.json
我在我的 ETL 作业中像这样加载它们
datasource0 = glueContext.create_dynamic_frame_from_options('s3',
{
'paths': ['s3://bucket/json-data/'],
'recurse': True,
'groupFiles': 'inPartition',
'partitionKeys':['x', 'y']
},
format='json',
transformation_ctx = 'datasource0')
然而,当我尝试使用 datasource0.printSchema()
读取模式时,我在模式中没有任何分区。我需要在模式中有这些分区来进行转换。经过一些研究后,我不确定这是否是 create_dynamic_frame_from_options
支持的功能。有人知道怎么做吗?
您只能在 write_dynamic_frame.from_options 中传递 partitionKey,而不能在从 s3.For 中读取时加载特定分区或过滤它们,您需要这些分区已经存在于源代码中。
因此,您需要使用 Glue 爬虫进行爬网,或者在 Athena 中使用分区创建 table。一旦 table 在 Glue 元数据中可用,您就可以将 table 的分区加载到 Glue ETL 中,如下所示:
glue_context.create_dynamic_frame.from_catalog(
database = "my_S3_data_set",
table_name = "catalog_data_table",
push_down_predicate = my_partition_predicate)
请参阅下文link了解如何利用谓词下推:
https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-partitions.html
我正在尝试加载 json 个在 S3 存储中这样分区的文件:
|-json-data
|-x=something
|-y=something
|-data.json
我在我的 ETL 作业中像这样加载它们
datasource0 = glueContext.create_dynamic_frame_from_options('s3',
{
'paths': ['s3://bucket/json-data/'],
'recurse': True,
'groupFiles': 'inPartition',
'partitionKeys':['x', 'y']
},
format='json',
transformation_ctx = 'datasource0')
然而,当我尝试使用 datasource0.printSchema()
读取模式时,我在模式中没有任何分区。我需要在模式中有这些分区来进行转换。经过一些研究后,我不确定这是否是 create_dynamic_frame_from_options
支持的功能。有人知道怎么做吗?
您只能在 write_dynamic_frame.from_options 中传递 partitionKey,而不能在从 s3.For 中读取时加载特定分区或过滤它们,您需要这些分区已经存在于源代码中。
因此,您需要使用 Glue 爬虫进行爬网,或者在 Athena 中使用分区创建 table。一旦 table 在 Glue 元数据中可用,您就可以将 table 的分区加载到 Glue ETL 中,如下所示:
glue_context.create_dynamic_frame.from_catalog(
database = "my_S3_data_set",
table_name = "catalog_data_table",
push_down_predicate = my_partition_predicate)
请参阅下文link了解如何利用谓词下推:
https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-partitions.html