【问题标题】:aws glue s3 target - creating partitions of 20 filesaws 胶水 s3 目标 - 创建 20 个文件的分区
【发布时间】:2018-11-15 07:24:04
【问题描述】:

默认情况下,当我从 dynamo DB 源和目标读取两个三个记录时,目标是 s3,即使这样它在目标中创建 20 个分区文件,只有两个有数据,其他是空文件。

我们如何控制这个文件的创建?

或者限制每个文件的记录数?

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-glue


    【解决方案1】:

    您可以通过更改分区数量来控制文件数量。首先,您需要将您的 DynamicFrame 更改为触发 DataFrame,然后更改分区数,最后改回 DynamicFrame:

    dataframe = DynamicFrame.toDF(applymapping3).repartition(2) #where 2 is the number of files/partitions.
    dynamicframe = DynamicFrame.fromDF(dataframe, glueContext, "dynamicframe")
    

    类似的方法,如果你想限制记录的数量,你可以这样做:

    n_partitions = int(math.ceil(dataframe.count() / float(file_size))) #where file_size can be 500 records.
    dataframe1 = DynamicFrame.toDF(dataframe).repartition(n_partitions)
    

    【讨论】:

    • 您还需要在作业脚本的开头添加以下导入以使其正常工作:from awsglue.dynamicframe import DynamicFrame
    猜你喜欢
    • 2021-01-09
    • 2021-05-20
    • 2021-07-19
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多