Skip to content

fix(jdbc-v2): Correctly parse mixed-order CTEs in SqlParser#2611

Closed
AVMusorin wants to merge 1 commit into
ClickHouse:mainfrom
AVMusorin:fix-variables-replacing
Closed

fix(jdbc-v2): Correctly parse mixed-order CTEs in SqlParser#2611
AVMusorin wants to merge 1 commit into
ClickHouse:mainfrom
AVMusorin:fix-variables-replacing

Conversation

@AVMusorin

Copy link
Copy Markdown

Summary

The grammar for CTEs was too restrictive. It required a specific order for different CTE syntax styles.

The grammar expected all CTEs to be defined before all CSEs (Common Scalar Expression).

This commit refactors the ctes grammar rule to be more flexible. It introduces a new, more generic cte rule that can represent either CTE style. The main ctes rule is now defined as a list of these generic cte elements, allowing them to appear in any order.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

@AVMusorin AVMusorin marked this pull request as draft October 9, 2025 14:07

@windsurf-bot windsurf-bot Bot left a comment

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.

💡 To request another review, post a new comment with "/windsurf-review".

Comment thread jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/ClickHouseParser.g4 Outdated
The grammar for CTEs was too restrictive. It required a specific order
for different CTE syntax styles.

The grammar expected all CTEs to be defined before all CSEs (Common
Scalar Expression).

This commit refactors the `ctes` grammar rule to be more flexible.
It introduces a new, more generic `cte` rule that can represent either CTE style.
The main `ctes` rule is now defined as a list of these generic `cte` elements,
allowing them to appear in any order.
@AVMusorin AVMusorin force-pushed the fix-variables-replacing branch from d312221 to accec17 Compare October 9, 2025 14:11
@mshustov mshustov requested a review from chernser October 9, 2025 14:43
@AVMusorin AVMusorin marked this pull request as ready for review October 9, 2025 18:00

@windsurf-bot windsurf-bot Bot left a comment

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.

Looks good to me 🤙

💡 To request another review, post a new comment with "/windsurf-review".

@chernser

chernser commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Good day, @AVMusorin !
Thank you for the contribution!

Actually CTEs were defined incorrectly in the grammar - they were included twice.
We have fixing it in the #2579

@chernser chernser closed this Oct 9, 2025
@AVMusorin AVMusorin mentioned this pull request Oct 10, 2025
4 tasks
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