SORTKEY / DISTKEY When writing data to redshift using AWS Glue

0

How do I add a sort / dist key to the glue dynamicframe writer into redshift?

已提问 3 个月前159 查看次数
1 回答
0

That is part of the table DDL, not the writing itself.
You could have the table previously created with the sort/dist keys as needed, or if you need to create the table dynamically, you could add a preaction to create the table as needed or a post action to alter the table to do that tweaking

profile pictureAWS
专家
已回答 3 个月前
  • I've tried using a post-action like this:,

    datasink = glueContext.write_dynamic_frame.from_options(
        frame=dyf,
        connection_type="redshift",
        connection_options={
            "redshiftTmpDir": "..",
            "dbtable": "..",
            "connectionName": "..",
            "postactions": "ALTER TABLE <TABLE> ALTER DISTSTYLE KEY DISTKEY <DIST-COLUMN>, ALTER SORTKEY (<SORT-COLUM-A>, <SORT-COLUMN-B>);"
        },
        transformation_ctx="..",
    )
    

    but the problem with specifying them for this problem is that everything works fine the first time the table is created. On subsequent runs, the job fails because you cannot specify THE SAME sort / dist key on the table.

    So is there a way to suppress or ignore errors from the post-actions?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则