Skip to content

Clickhouse: Clickhouse assume table constraint - #2467

Open
pelovett wants to merge 7 commits into
apache:mainfrom
pelovett:clickhouse-assume-table-constraint
Open

pelovett wants to merge 7 commits into
apache:mainfrom
pelovett:clickhouse-assume-table-constraint

Conversation

@pelovett

Copy link
Copy Markdown

Resolves: #2466

First time contributing so please let me know if I missed anything!

Comment thread tests/sqlparser_clickhouse.rs
Comment thread src/ast/table_constraints.rs Outdated
@pelovett

Copy link
Copy Markdown
Author

@LucaCappelletti94 if you have some time, could you take another look? I tried to address the issues you identified.

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Sure, currently I am trying to ultimate the fuzzing CI, once that is done reviews might get more swift given it should provide a stronger claim of consistency

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.18182% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.96%. Comparing base (9ae00e7) to head (f292e1a).

Files with missing lines Patch % Lines
src/ast/table_constraints.rs 71.42% 4 Missing ⚠️
src/parser/mod.rs 85.71% 0 Missing and 4 partials ⚠️
src/dialect/mod.rs 50.00% 3 Missing ⚠️
src/ast/spans.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2467   +/-   ##
=======================================
  Coverage   80.96%   80.96%           
=======================================
  Files          42       42           
  Lines       33359    33412   +53     
  Branches    33359    33412   +53     
=======================================
+ Hits        27009    27053   +44     
- Misses       2790     2798    +8     
- Partials     3560     3561    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/parser/mod.rs
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
}
Token::Word(w) if w.keyword == Keyword::CHECK => {
self.expect_token(&Token::LParen)?;
let has_paren = if self.dialect.supports_unparenthesized_check_constraint() {

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.

The unparenthesized CHECK path has the same defect. CONSTRAINT c CHECK (a + 1) > 0 fails here but ClickHouse accepts it. Add an appropriate test for it, and correct this parser.

Comment thread src/ast/table_constraints.rs Outdated
Comment thread src/ast/table_constraints.rs
Comment thread tests/sqlparser_clickhouse.rs
Comment thread tests/sqlparser_clickhouse.rs
@LucaCappelletti94 LucaCappelletti94 added the waiting on contributor The review needs further refinements by its author label Sep 24, 2026
pelovett and others added 2 commits October 21, 2026 13:03
Add suggestions from review

Co-authored-by: Luca Cappelletti <cappelletti.luca94@gmail.com>
@pelovett

Copy link
Copy Markdown
Author

Hey @LucaCappelletti94 , sorry for the delay in responding to your comments after requesting them. I've updated the code with your suggestions and added a fix for check constraints without parentheses. My solution adds a field to the constraint structs tracking if they were created with parentheses. This would be a breaking change for these structs.

The other option I could think of was storing the parenthesis state by wrapping the expressions in Expr::Nested but this could break code that creates structs manually rather than with the parser.

Not sure the best option here but would appreciate your opinion.

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

Labels

ClickHouse waiting on contributor The review needs further refinements by its author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Clickhouse ASSUME table constraints (and remove required parenthetical)

3 participants