Skip to content

Fix Redshift parenthesized single-column SORTKEY and DISTKEY - #5915

Open
simen-strand wants to merge 6 commits into
SQLMesh:mainfrom
simen-strand:fix/redshift-single-column-sortkey
Open

simen-strand wants to merge 6 commits into
SQLMesh:mainfrom
simen-strand:fix/redshift-single-column-sortkey

Conversation

@simen-strand

@simen-strand simen-strand commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Redshift: adds support for parenthesized single-column sortkey and distkey.

SQLGlot parses sortkey = (column) and distkey = (column) as an exp.Paren, producing invalid Redshift syntax such as SORTKEY((column)) / DISTKEY((column)).

  • SORTKEY: explicitly normalizes tuple, array, parenthesized, and scalar expressions before constructing the SortKeyProperty.
  • DISTKEY: unwraps parentheses before constructing the DistKeyProperty, matching Redshift's documented DISTKEY ( column_name ) syntax (single column only).

Tests

  • Updated the model-level Redshift physical properties test to cover every sortkey form a user can write.
  • Added a model-level test covering bare, quoted, string, and parenthesized distkey forms.
  • Ran pytest tests/core/engine_adapter/test_redshift.py (47 passed) and make fast-test (190 passed).

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

🤖 Generated with Claude Code

simen-strand and others added 4 commits July 23, 2026 12:13
Signed-off-by: Simen Strand <simen.strand@netcheck.de>
Parametrize the model-definition test over bare, quoted, parenthesized
single-column, tuple, and array sortkey values, restoring coverage for
the bare single-column form.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Simen Strand <simen.strand@netcheck.de>
@simen-strand

Copy link
Copy Markdown
Contributor Author

@StuffbyYuki could you take a look? This small PR makes the Redshift sortkey property accept the documented SORTKEY (column_name [, ...]) form for single columns too

@StuffbyYuki
StuffbyYuki self-requested a review October 2, 2026 07:01

@StuffbyYuki StuffbyYuki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simen-strand A suggestion - DISTKEY has the same bug: distkey = (col) still renders as DISTKEY((col)). Maybe consider unwrapping parentheses there too (e.g. .unnest() before _to_identifier_if_string) and adding a test case, so the two properties behave the same way?

A parenthesized distkey such as `distkey = (col)` rendered as
`DISTKEY((col))`, which doesn't match Redshift's documented
`DISTKEY ( column_name )` syntax. Unwrap the parentheses the same way
the sortkey handling does, and test the bare, quoted, string and
parenthesized forms in model physical_properties.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Simen Strand <simen.strand@netcheck.de>
@simen-strand simen-strand changed the title Fix Redshift parenthesized single-column SORTKEY Fix Redshift parenthesized single-column SORTKEY and DISTKEY Oct 2, 2026
@simen-strand

Copy link
Copy Markdown
Contributor Author

Thanks @StuffbyYuki, you're right about the DISTKEY bug, I added the fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants