Skip to content

Support optional AS keyword in CTE definitions for Databricks#2286

Merged
yoavcloud merged 2 commits intoapache:mainfrom
funcpp:support-cte-without-as-databricks
Apr 9, 2026
Merged

Support optional AS keyword in CTE definitions for Databricks#2286
yoavcloud merged 2 commits intoapache:mainfrom
funcpp:support-cte-without-as-databricks

Conversation

@funcpp
Copy link
Copy Markdown
Contributor

@funcpp funcpp commented Mar 30, 2026

Summary

  • Add Dialect::supports_cte_without_as() to support dialects where the AS keyword is optional in CTE definitions
  • Enable for Databricks and Generic dialects
  • Use maybe_parse to disambiguate name (query) from name (columns), following the same pattern as IN subquery/list disambiguation

Databricks allows omitting the AS keyword:

WITH cte (SELECT 1) SELECT * FROM cte

Test plan

  • Positive tests: CTE without AS, mixed CTEs, column defs without AS
  • Negative test: non-supporting dialects reject the syntax
  • Existing CTE tests unaffected
  • cargo fmt, cargo clippy, full test suite pass

@funcpp funcpp force-pushed the support-cte-without-as-databricks branch 2 times, most recently from 90111a4 to 2051de9 Compare March 30, 2026 02:18
@funcpp
Copy link
Copy Markdown
Contributor Author

funcpp commented Apr 2, 2026

@iffyio Hi! Could you take a look at these Databricks dialect PRs when you have a chance?

Thanks!

}

/// Parse a CTE (`alias [( col1, col2, ... )] AS (subquery)`)
/// Parse a CTE (`alias [( col1, col2, ... )] [AS] (subquery)`)
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.

If there's a way to remove some duplications in this function, it would be great. It's not critical, though IMO.

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.

thanks for the review! I merged the AS and column-defs paths, is it better?

@yoavcloud
Copy link
Copy Markdown
Contributor

@funcpp, please address the conflicts and see if my comment makes sense. Otherwise, looks good.

funcpp added 2 commits April 9, 2026 18:35
Databricks allows omitting the AS keyword in CTE definitions:
`WITH cte (SELECT ...) SELECT * FROM cte`

Add `supports_cte_without_as()` dialect method and enable it for
Databricks and Generic dialects.
@funcpp funcpp force-pushed the support-cte-without-as-databricks branch from 82c2b4f to a37c193 Compare April 9, 2026 09:36
@yoavcloud yoavcloud enabled auto-merge April 9, 2026 09:40
@yoavcloud yoavcloud added this pull request to the merge queue Apr 9, 2026
Merged via the queue into apache:main with commit 72b295a Apr 9, 2026
10 checks passed
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