Skip to content

Commit 23aae7e

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

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
@@ -345,6 +345,23 @@ pub trait Dialect: Debug + Any {
345345
false
346346
}
347347

348+
/// Returns true if the dialect supports `PARTITION BY` appearing after `ORDER BY`
349+
/// in a `CREATE TABLE` statement (in addition to the standard placement before `ORDER BY`).
350+
///
351+
/// ClickHouse DDL uses this ordering:
352+
/// <https://clickhouse.com/docs/en/sql-reference/statements/create/table#partition-by>
353+
fn supports_partition_by_after_order_by(&self) -> bool {
354+
false
355+
}
356+
357+
/// Returns true if the dialect supports ClickHouse-style `ARRAY JOIN` / `LEFT ARRAY JOIN` /
358+
/// `INNER ARRAY JOIN` syntax for unnesting arrays inline.
359+
///
360+
/// <https://clickhouse.com/docs/en/sql-reference/statements/select/array-join>
361+
fn supports_array_join_syntax(&self) -> bool {
362+
false
363+
}
364+
348365
/// Returns true if the dialects supports `group sets, roll up, or cube` expressions.
349366
fn supports_group_by_expr(&self) -> bool {
350367
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()?))
@@ -15749,7 +15749,7 @@ impl<'a> Parser<'a> {
1574915749
constraint: self.parse_join_constraint(false)?,
1575015750
},
1575115751
}
15752-
} else if dialect_of!(self is ClickHouseDialect | GenericDialect)
15752+
} else if self.dialect.supports_array_join_syntax()
1575315753
&& self.parse_keywords(&[Keyword::INNER, Keyword::ARRAY, Keyword::JOIN])
1575415754
{
1575515755
// ClickHouse: INNER ARRAY JOIN
@@ -15758,7 +15758,7 @@ impl<'a> Parser<'a> {
1575815758
global,
1575915759
join_operator: JoinOperator::InnerArrayJoin,
1576015760
}
15761-
} else if dialect_of!(self is ClickHouseDialect | GenericDialect)
15761+
} else if self.dialect.supports_array_join_syntax()
1576215762
&& self.parse_keywords(&[Keyword::LEFT, Keyword::ARRAY, Keyword::JOIN])
1576315763
{
1576415764
// ClickHouse: LEFT ARRAY JOIN
@@ -15767,7 +15767,7 @@ impl<'a> Parser<'a> {
1576715767
global,
1576815768
join_operator: JoinOperator::LeftArrayJoin,
1576915769
}
15770-
} else if dialect_of!(self is ClickHouseDialect | GenericDialect)
15770+
} else if self.dialect.supports_array_join_syntax()
1577115771
&& self.parse_keywords(&[Keyword::ARRAY, Keyword::JOIN])
1577215772
{
1577315773
// ClickHouse: ARRAY JOIN

0 commit comments

Comments
 (0)