【问题标题】:AWS Glue ETL Doesn't Output All RecordsAWS Glue ETL 不输出所有记录
【发布时间】:2020-02-07 02:38:16
【问题描述】:

我有一个 ETL 脚本,旨在使用 Relationalize 扁平化一组 400 万个 JSON 文件。该脚本在包含 300 个文件的测试集上运行良好,但是当在具有 400 万个文件的 S3 存储桶上运行时,它仅生成 1500~ 个输出文件,每个输出文件包含单个记录的数据。

我尝试了该脚本的几种不同配置,但它们都产生了相同的结果:

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.dynamicframe import DynamicFrame
from awsglue.job import Job

## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)

# Begin variables to customize with your information
glue_source_database = "mydatabase"
glue_source_table = "mytable"
glue_temp_storage = "s3://my-data/glue_temp"
glue_relationalize_output_s3_path = "s3://my-data/glue_output/mytable_flat/"
dfc_root_table_name = "root" #default value is "roottable"
# End variables to customize with your information


datasource0 = glueContext.create_dynamic_frame.from_catalog(database = glue_source_database, table_name = glue_source_table, transformation_ctx = "datasource0")
dfc = Relationalize.apply(frame = datasource0, staging_path = glue_temp_storage, name = dfc_root_table_name, transformation_ctx = "dfc")
origdata = dfc.select(dfc_root_table_name)

origdataoutput = glueContext.write_dynamic_frame.from_options(frame = origdata, connection_type = "s3", connection_options = {"path": glue_relationalize_output_s3_path}, format = "json", transformation_ctx = "origdataoutput")

【问题讨论】:

    标签: aws-glue


    【解决方案1】:

    看起来您只是将根表传递给 glueContext.create_dynamic_frame.from_catalog 。当您执行关系化时,它将返回一个 DynamicFrameCollection。要查看此集合中的动态帧列表,请尝试使用 dfc.keys() 打印它们。

    请参阅thisthis 中的第 6 步,了解关系化的工作原理。

    【讨论】:

    • 进一步研究后,看起来 Relationalize 实际上删除了记录,原因尚不清楚。如果我计算源动态帧中的记录数然后运行 ​​Relationalize 并计算根表,该数量低于源中的对象总数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 2023-02-19
    相关资源
    最近更新 更多