Skip to content

fix(cubesql): preserve literal ORDER BY aliases - #11496

Open
jwils wants to merge 1 commit into
cube-js:masterfrom
jwils:joshuaw/fix-literal-order-by
Open

fix(cubesql): preserve literal ORDER BY aliases#11496
jwils wants to merge 1 commit into
cube-js:masterfrom
jwils:joshuaw/fix-literal-order-by

Conversation

@jwils

@jwils jwils commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Description of Changes Made

CubeSQL sort pushdown can replace an aliased grouped integer literal with the literal itself. Databases that interpret integers in ORDER BY as positional ordinals can then reject the generated SQL when the ordinal exceeds the select-list width.

  • Restore the generated group alias when an ORDER BY expression exactly matches a grouped literal
  • Preserve sort direction, null ordering, ordinary column sorts, and existing window-expression alias handling
  • Add a regression test with two literal sort keys that fails against master with a raw ORDER BY 19

Risk Assessment

Low. The rewrite is limited to ORDER BY expressions that exactly match literal expressions in the same grouped select; all other sort expressions retain their existing behavior.

Validation

  • cargo test -p cubesql --lib: 776 passed, 6 ignored
  • cargo clippy -p cubesql --lib --tests
  • cargo fmt --all -- --check

Sort pushdown can replace a grouped literal alias with the literal itself. Integer literals are then interpreted as positional ordinals by downstream databases such as Databricks. Reuse the generated group alias to keep wrapped SQL unambiguous.
@jwils
jwils marked this pull request as ready for review August 6, 2026 18:10
@jwils
jwils requested a review from a team as a code owner August 6, 2026 18:10
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.

1 participant