Skip to main content

sqlparser/dialect/
clickhouse.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::dialect::Dialect;
19
20/// A [`Dialect`] for [ClickHouse](https://clickhouse.com/).
21#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct ClickHouseDialect {}
24
25impl Dialect for ClickHouseDialect {
26    fn is_identifier_start(&self, ch: char) -> bool {
27        // See https://clickhouse.com/docs/en/sql-reference/syntax/#syntax-identifiers
28        ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_'
29    }
30
31    fn is_identifier_part(&self, ch: char) -> bool {
32        self.is_identifier_start(ch) || ch.is_ascii_digit()
33    }
34
35    fn supports_string_literal_backslash_escape(&self) -> bool {
36        true
37    }
38
39    fn supports_select_wildcard_except(&self) -> bool {
40        true
41    }
42
43    fn describe_requires_table_keyword(&self) -> bool {
44        true
45    }
46
47    fn require_interval_qualifier(&self) -> bool {
48        true
49    }
50
51    fn supports_limit_comma(&self) -> bool {
52        true
53    }
54
55    fn supports_insert_table_function(&self) -> bool {
56        true
57    }
58
59    fn supports_insert_format(&self) -> bool {
60        true
61    }
62
63    fn supports_numeric_literal_underscores(&self) -> bool {
64        true
65    }
66
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
75    // ClickHouse uses this for some FORMAT expressions in `INSERT` context, e.g. when inserting
76    // with FORMAT JSONEachRow a raw JSON key-value expression is valid and expected.
77    //
78    // [ClickHouse formats](https://clickhouse.com/docs/en/interfaces/formats)
79    fn supports_dictionary_syntax(&self) -> bool {
80        true
81    }
82
83    /// See <https://clickhouse.com/docs/en/sql-reference/functions#higher-order-functions---operator-and-lambdaparams-expr-function>
84    fn supports_lambda_functions(&self) -> bool {
85        true
86    }
87
88    fn supports_from_first_select(&self) -> bool {
89        true
90    }
91
92    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by>
93    fn supports_order_by_all(&self) -> bool {
94        true
95    }
96
97    // See <https://clickhouse.com/docs/en/sql-reference/aggregate-functions/grouping_function#grouping-sets>
98    fn supports_group_by_expr(&self) -> bool {
99        true
100    }
101
102    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/group-by#rollup-modifier>
103    fn supports_group_by_with_modifier(&self) -> bool {
104        true
105    }
106
107    /// Supported since 2020.
108    /// See <https://clickhouse.com/docs/whats-new/changelog/2020#backward-incompatible-change-2>
109    fn supports_nested_comments(&self) -> bool {
110        true
111    }
112
113    /// See <https://clickhouse.com/docs/en/sql-reference/statements/optimize>
114    fn supports_optimize_table(&self) -> bool {
115        true
116    }
117
118    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/prewhere>
119    fn supports_prewhere(&self) -> bool {
120        true
121    }
122
123    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
124    fn supports_with_fill(&self) -> bool {
125        true
126    }
127
128    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/limit-by>
129    fn supports_limit_by(&self) -> bool {
130        true
131    }
132
133    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
134    fn supports_interpolate(&self) -> bool {
135        true
136    }
137
138    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select#settings-in-select-query>
139    fn supports_settings(&self) -> bool {
140        true
141    }
142
143    /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/format>
144    fn supports_select_format(&self) -> bool {
145        true
146    }
147
148    /// See <https://clickhouse.com/docs/sql-reference/statements/select#replace>
149    fn supports_select_wildcard_replace(&self) -> bool {
150        true
151    }
152
153    fn supports_comma_separated_trim(&self) -> bool {
154        true
155    }
156}