feat(clickhouse): support PARTITION BY after ORDER BY and ARRAY JOIN#2283
feat(clickhouse): support PARTITION BY after ORDER BY and ARRAY JOIN#2283cristhiank wants to merge 5 commits intoapache:mainfrom
Conversation
ClickHouse DDL allows PARTITION BY to appear after ORDER BY, which differs from standard SQL ordering. This change makes the parser accept both orderings when using the ClickHouseDialect or GenericDialect. Fixes a parse failure for production ClickHouse CREATE TABLE statements like: CREATE TABLE t (...) ENGINE = MergeTree() ORDER BY (...) PARTITION BY expr Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ClickHouse supports ARRAY JOIN clauses for unnesting arrays inline. This adds JoinOperator variants for ARRAY JOIN, LEFT ARRAY JOIN, and INNER ARRAY JOIN. These joins take a table expression (the array to unnest) rather than a standard table reference, and do not use ON/USING constraints. Also adds Spanned impls for the new variants in spans.rs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d27aeca to
097a929
Compare
| // ClickHouse allows PARTITION BY after ORDER BY | ||
| // https://clickhouse.com/docs/en/sql-reference/statements/create/table#partition-by | ||
| let partition_by = if create_table_config.partition_by.is_none() | ||
| && dialect_of!(self is ClickHouseDialect | GenericDialect) |
There was a problem hiding this comment.
Can this condition be converted to a dialect function?
There was a problem hiding this comment.
Thanks for the review, addressed in the latest changes.
| constraint: self.parse_join_constraint(false)?, | ||
| }, | ||
| } | ||
| } else if dialect_of!(self is ClickHouseDialect | GenericDialect) |
There was a problem hiding this comment.
Can this condition be converted to a dialect function?
There was a problem hiding this comment.
Thanks for the review, addressed in the latest changes.
| global, | ||
| join_operator: JoinOperator::InnerArrayJoin, | ||
| } | ||
| } else if dialect_of!(self is ClickHouseDialect | GenericDialect) |
There was a problem hiding this comment.
Can this condition be converted to a dialect function?
There was a problem hiding this comment.
Thanks for the review, addressed in the latest changes.
| global, | ||
| join_operator: JoinOperator::LeftArrayJoin, | ||
| } | ||
| } else if dialect_of!(self is ClickHouseDialect | GenericDialect) |
There was a problem hiding this comment.
Can this condition be converted to a dialect function?
There was a problem hiding this comment.
Thanks for the review, addressed in the latest changes.
…ition-and-array-join
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
clippy 1.95 stable newly flags 8 pre-existing patterns in parser/mod.rs where an `if` inside a match arm body can be expressed as a match guard. Applies clippy's suggested fix verbatim. No behavior change.
|
Fixed a Rust/lint failure introduced by clippy 1.95 — 8 pre-existing collapsible_match patterns in parser/mod.rs, converted to match guards per clippy's suggestions. No behavior change. |
Summary
Two ClickHouse dialect improvements:
PARTITION BY after ORDER BY — ClickHouse CREATE TABLE DDL places PARTITION BY after ORDER BY, which differs from standard SQL. The parser now accepts both orderings when using the ClickHouseDialect or GenericDialect.
ARRAY JOIN support — Adds \JoinOperator\ variants for \ARRAY JOIN, \LEFT ARRAY JOIN, and \INNER ARRAY JOIN. These are ClickHouse-specific constructs for unnesting arrays inline.
Motivation
These patterns appear in production ClickHouse deployments and currently fail to parse with the ClickHouseDialect.
Changes