Skip to content

Support multi-column aliases in SELECT items#2289

Merged
yoavcloud merged 2 commits intoapache:mainfrom
funcpp:support-multi-column-alias
Apr 9, 2026
Merged

Support multi-column aliases in SELECT items#2289
yoavcloud merged 2 commits intoapache:mainfrom
funcpp:support-multi-column-alias

Conversation

@funcpp
Copy link
Copy Markdown
Contributor

@funcpp funcpp commented Mar 31, 2026

Summary

Add support for parenthesized multi-column aliases in SELECT items, as defined in the Spark SQL grammar:

namedExpression
    : expression (AS? (name=errorCapturingIdentifier | identifierList))?
    ;

identifierList
    : LEFT_PAREN identifierSeq RIGHT_PAREN
    ;

This enables syntax like:

SELECT stack(2, 'a', 'b', 'c', 'd') AS (col1, col2)

Changes

  • Add SelectItem::ExprWithAliases variant for multi-column aliases
  • Add Dialect::supports_select_item_multi_column_alias(), enabled for Databricks and Generic dialects
  • Parse AS (ident, ident, ...) when the dialect supports it

Context

While not documented in the Databricks SQL reference, this syntax is part of the Spark SQL grammar that Databricks implements. Verified to execute successfully on Databricks Runtime:

SELECT stack(2, 'a', 'b', 'c', 'd') AS (col1, col2)
-- Returns:
-- col1  col2
-- a     b
-- c     d

Test plan

  • Round-trip test: SELECT stack(...) AS (col1, col2) with and without FROM
  • Negative test: non-supporting dialects reject the syntax
  • Existing tests unaffected
  • cargo fmt, cargo clippy, full test suite pass

);
}

#[test]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can this test move to common?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved it 👍🏻

Copy link
Copy Markdown
Contributor

@yoavcloud yoavcloud left a comment

Choose a reason for hiding this comment

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

Overall looks good, please see my comment inline and we're good to go!

Spark SQL grammar allows parenthesized identifier lists as SELECT
item aliases:

  namedExpression: expression (AS? (identifier | identifierList))?
  identifierList: '(' identifier (',' identifier)* ')'

This enables syntax like:
  SELECT stack(2, 'a', 'b', 'c', 'd') AS (col1, col2)
@funcpp funcpp force-pushed the support-multi-column-alias branch from 156b6ff to 7708a40 Compare April 9, 2026 09:38
@yoavcloud yoavcloud enabled auto-merge April 9, 2026 09:41
@yoavcloud yoavcloud added this pull request to the merge queue Apr 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Apr 9, 2026
Integrate supports_cte_without_as and other upstream changes into
the support-multi-column-alias branch.
@funcpp funcpp force-pushed the support-multi-column-alias branch 2 times, most recently from ff42726 to 325744f Compare April 9, 2026 14:40
@funcpp
Copy link
Copy Markdown
Contributor Author

funcpp commented Apr 9, 2026

@yoavcloud Rebased, Could you check it?

@yoavcloud yoavcloud added this pull request to the merge queue Apr 9, 2026
Merged via the queue into apache:main with commit 531ebdf Apr 9, 2026
10 checks passed
LucaCappelletti94 pushed a commit to LucaCappelletti94/sqlparser-rs that referenced this pull request Apr 9, 2026
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