Skip to content

feat(clickhouse): support PARTITION BY after ORDER BY and ARRAY JOIN#2283

Open
cristhiank wants to merge 2 commits intoapache:mainfrom
cristhiank:fix/clickhouse-partition-and-array-join
Open

feat(clickhouse): support PARTITION BY after ORDER BY and ARRAY JOIN#2283
cristhiank wants to merge 2 commits intoapache:mainfrom
cristhiank:fix/clickhouse-partition-and-array-join

Conversation

@cristhiank
Copy link

Summary

Two ClickHouse dialect improvements:

  1. 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.

  2. 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

  • \src/parser/mod.rs: Accept PARTITION BY after ORDER BY in CREATE TABLE (ClickHouse + Generic dialect)
  • \src/ast/query.rs: New \JoinOperator\ variants: \ArrayJoin, \LeftArrayJoin, \InnerArrayJoin\ with Display impl
  • \src/ast/spans.rs: \Spanned\ impl for new \JoinOperator\ variants
  • \src/parser/mod.rs: Recognize \ARRAY JOIN, \LEFT ARRAY JOIN, \INNER ARRAY JOIN\ in \parse_joins()\
  • \ ests/sqlparser_clickhouse.rs: Added test cases for both features

Cristhian Lopez Vidal and others added 2 commits March 23, 2026 16:23
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 <[email protected]>
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 <[email protected]>
@cristhiank cristhiank force-pushed the fix/clickhouse-partition-and-array-join branch from d27aeca to 097a929 Compare March 23, 2026 23:57
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.

1 participant