-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(redshift): Cannot add distkey to existing table #26733
Labels
@aws-cdk/aws-redshift
Related to Amazon Redshift
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p1
Comments
ghost
added
bug
This issue is a bug.
needs-triage
This issue or PR still needs to be triaged.
labels
Aug 11, 2023
pahud
added
p1
effort/small
Small work item – less than a day of effort
and removed
needs-triage
This issue or PR still needs to be triaged.
labels
Aug 14, 2023
Yes we should address this use case. |
mergify bot
pushed a commit
that referenced
this issue
Aug 17, 2023
…26789) The current implementation executes a `CREATE TABLE` if the table has no `distKey` specified and one is added, or if a `distKey` is present and is removed. The resulting table is created with the same name, causing the update operation to fail. This fixes the problem by using [`ALTER TABLE`](https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_TABLE.html) when adding/removing `distKey` on a table update. Closes #26733. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
@aws-cdk/aws-redshift
Related to Amazon Redshift
bug
This issue is a bug.
effort/small
Small work item – less than a day of effort
p1
Describe the bug
Adding
distKey=true
to a column where the table previously had no distribution key fails to deploy because it tries to create the table.The diff:
The error:
Expected Behavior
CDK should add a distribution key to the table.
Current Behavior
CDK tries to create the table from scratch.
Reproduction Steps
It's unfortunately difficult for me to create a runnable snippet due to the amount of proprietary code used to generate it, but I've been able to reproduce the error with various tables in our system. The basic steps are:
.distKey(true)
for any single columnAs best as I can figure it, our code does something like this:
Possible Solution
The current code issues a
CREATE TABLE
statement if the table either has no distkey and we're adding one, or had a distkey and we're removing it:The problem here is that the resulting query tries to create a new table with the same name, which Redshift will reject because the table already exists.
Redshift supports adding and removing distribution keys on existing tables (see docs here) so we should take advantage of that. I believe the following will work:
Additional Information/Context
No response
CDK CLI Version
2.88.0
Framework Version
2.17.184
Node.js Version
20.5.1
OS
MacOS 13.5
Language
Java
Language Version
JDK 17
Other information
No response
The text was updated successfully, but these errors were encountered: