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?

asked 2 months ago140 views
1 Answer
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
EXPERT
answered 2 months ago
  • 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?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions