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 // ClickHouse uses this for some FORMAT expressions in `INSERT` context, e.g. when inserting
68 // with FORMAT JSONEachRow a raw JSON key-value expression is valid and expected.
69 //
70 // [ClickHouse formats](https://clickhouse.com/docs/en/interfaces/formats)
71 fn supports_dictionary_syntax(&self) -> bool {
72 true
73 }
74
75 /// See <https://clickhouse.com/docs/en/sql-reference/functions#higher-order-functions---operator-and-lambdaparams-expr-function>
76 fn supports_lambda_functions(&self) -> bool {
77 true
78 }
79
80 fn supports_from_first_select(&self) -> bool {
81 true
82 }
83
84 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by>
85 fn supports_order_by_all(&self) -> bool {
86 true
87 }
88
89 // See <https://clickhouse.com/docs/en/sql-reference/aggregate-functions/grouping_function#grouping-sets>
90 fn supports_group_by_expr(&self) -> bool {
91 true
92 }
93
94 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/group-by#rollup-modifier>
95 fn supports_group_by_with_modifier(&self) -> bool {
96 true
97 }
98
99 /// Supported since 2020.
100 /// See <https://clickhouse.com/docs/whats-new/changelog/2020#backward-incompatible-change-2>
101 fn supports_nested_comments(&self) -> bool {
102 true
103 }
104
105 /// See <https://clickhouse.com/docs/en/sql-reference/statements/optimize>
106 fn supports_optimize_table(&self) -> bool {
107 true
108 }
109
110 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/prewhere>
111 fn supports_prewhere(&self) -> bool {
112 true
113 }
114
115 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
116 fn supports_with_fill(&self) -> bool {
117 true
118 }
119
120 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/limit-by>
121 fn supports_limit_by(&self) -> bool {
122 true
123 }
124
125 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/order-by#order-by-expr-with-fill-modifier>
126 fn supports_interpolate(&self) -> bool {
127 true
128 }
129
130 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select#settings-in-select-query>
131 fn supports_settings(&self) -> bool {
132 true
133 }
134
135 /// See <https://clickhouse.com/docs/en/sql-reference/statements/select/format>
136 fn supports_select_format(&self) -> bool {
137 true
138 }
139
140 /// See <https://clickhouse.com/docs/sql-reference/statements/select#replace>
141 fn supports_select_wildcard_replace(&self) -> bool {
142 true
143 }
144
145 fn supports_comma_separated_trim(&self) -> bool {
146 true
147 }
148}