Skip to content

Commit e7e43d0

Browse files
crilopezCopilot
authored andcommitted
refactor(clickhouse): move dialect_of! checks to Dialect trait methods
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1679f37 commit e7e43d0

4 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/dialect/clickhouse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ impl Dialect for ClickHouseDialect {
6464
true
6565
}
6666

67+
fn supports_partition_by_after_order_by(&self) -> bool {
68+
true
69+
}
70+
71+
fn supports_array_join_syntax(&self) -> bool {
72+
true
73+
}
74+
6775
// ClickHouse uses this for some FORMAT expressions in `INSERT` context, e.g. when inserting
6876
// with FORMAT JSONEachRow a raw JSON key-value expression is valid and expected.
6977
//

src/dialect/generic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ impl Dialect for GenericDialect {
4545
true
4646
}
4747

48+
fn supports_partition_by_after_order_by(&self) -> bool {
49+
true
50+
}
51+
52+
fn supports_array_join_syntax(&self) -> bool {
53+
true
54+
}
55+
4856
fn supports_group_by_expr(&self) -> bool {
4957
true
5058
}

src/dialect/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,23 @@ pub trait Dialect: Debug + Any {
349349
false
350350
}
351351

352+
/// Returns true if the dialect supports `PARTITION BY` appearing after `ORDER BY`
353+
/// in a `CREATE TABLE` statement (in addition to the standard placement before `ORDER BY`).
354+
///
355+
/// ClickHouse DDL uses this ordering:
356+
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/table#partition-by>
357+
fn supports_partition_by_after_order_by(&self) -> bool {
358+
false
359+
}
360+
361+
/// Returns true if the dialect supports ClickHouse-style `ARRAY JOIN` / `LEFT ARRAY JOIN` /
362+
/// `INNER ARRAY JOIN` syntax for unnesting arrays inline.
363+
///
364+
/// <https://clickhouse.com/docs/en/sql-reference/statements/select/array-join>
365+
fn supports_array_join_syntax(&self) -> bool {
366+
false
367+
}
368+
352369
/// Returns true if the dialects supports `group sets, roll up, or cube` expressions.
353370
fn supports_group_by_expr(&self) -> bool {
354371
false

src/parser/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8567,7 +8567,7 @@ impl<'a> Parser<'a> {
85678567
// ClickHouse allows PARTITION BY after ORDER BY
85688568
// https://clickhouse.com/docs/en/sql-reference/statements/create/table#partition-by
85698569
let partition_by = if create_table_config.partition_by.is_none()
8570-
&& dialect_of!(self is ClickHouseDialect | GenericDialect)
8570+
&& self.dialect.supports_partition_by_after_order_by()
85718571
&& self.parse_keywords(&[Keyword::PARTITION, Keyword::BY])
85728572
{
85738573
Some(Box::new(self.parse_expr()?))
@@ -15779,7 +15779,7 @@ impl<'a> Parser<'a> {
1577915779
constraint: self.parse_join_constraint(false)?,
1578015780
},
1578115781
}
15782-
} else if dialect_of!(self is ClickHouseDialect | GenericDialect)
15782+
} else if self.dialect.supports_array_join_syntax()
1578315783
&& self.parse_keywords(&[Keyword::INNER, Keyword::ARRAY, Keyword::JOIN])
1578415784
{
1578515785
// ClickHouse: INNER ARRAY JOIN
@@ -15788,7 +15788,7 @@ impl<'a> Parser<'a> {
1578815788
global,
1578915789
join_operator: JoinOperator::InnerArrayJoin,
1579015790
}
15791-
} else if dialect_of!(self is ClickHouseDialect | GenericDialect)
15791+
} else if self.dialect.supports_array_join_syntax()
1579215792
&& self.parse_keywords(&[Keyword::LEFT, Keyword::ARRAY, Keyword::JOIN])
1579315793
{
1579415794
// ClickHouse: LEFT ARRAY JOIN
@@ -15797,7 +15797,7 @@ impl<'a> Parser<'a> {
1579715797
global,
1579815798
join_operator: JoinOperator::LeftArrayJoin,
1579915799
}
15800-
} else if dialect_of!(self is ClickHouseDialect | GenericDialect)
15800+
} else if self.dialect.supports_array_join_syntax()
1580115801
&& self.parse_keywords(&[Keyword::ARRAY, Keyword::JOIN])
1580215802
{
1580315803
// ClickHouse: ARRAY JOIN

0 commit comments

Comments
 (0)