Skip to main content

sqlparser/dialect/
databricks.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;
19use crate::keywords::Keyword;
20use crate::parser::Parser;
21
22/// A [`Dialect`] for [Databricks SQL](https://www.databricks.com/)
23///
24/// See <https://docs.databricks.com/en/sql/language-manual/index.html>.
25#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
26#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
27pub struct DatabricksDialect;
28
29impl Dialect for DatabricksDialect {
30    // see https://docs.databricks.com/en/sql/language-manual/sql-ref-identifiers.html
31
32    fn is_delimited_identifier_start(&self, ch: char) -> bool {
33        matches!(ch, '`')
34    }
35
36    /// Aliases are identifiers, see `column_alias` in
37    /// <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select.html> and
38    /// <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-identifiers.html>
39    fn supports_string_literal_column_alias(&self, _explicit: bool) -> bool {
40        false
41    }
42
43    /// Aliases are identifiers, see
44    /// <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-identifiers.html>
45    fn supports_string_literal_table_alias(&self, _explicit: bool) -> bool {
46        false
47    }
48
49    fn supports_comparison_in_between_low_bound(&self) -> bool {
50        true
51    }
52
53    /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-identifiers.html>
54    fn identifier_quote_style(&self, _identifier: &str) -> Option<char> {
55        Some('`')
56    }
57
58    fn is_identifier_start(&self, ch: char) -> bool {
59        matches!(ch, 'a'..='z' | 'A'..='Z' | '_')
60    }
61
62    fn is_identifier_part(&self, ch: char) -> bool {
63        matches!(ch, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_')
64    }
65
66    /// Databricks permits [keywords](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-reserved-words) as table names.
67    fn is_table_factor(&self, _kw: &Keyword, _parser: &mut Parser) -> bool {
68        true
69    }
70
71    fn supports_numeric_prefix(&self) -> bool {
72        true
73    }
74
75    fn supports_filter_during_aggregation(&self) -> bool {
76        true
77    }
78
79    // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html
80    fn supports_group_by_expr(&self) -> bool {
81        true
82    }
83
84    /// <https://docs.databricks.com/gcp/en/delta/history#delta-time-travel-syntax>
85    fn supports_table_versioning(&self) -> bool {
86        true
87    }
88
89    fn supports_lambda_functions(&self) -> bool {
90        true
91    }
92
93    // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html#syntax
94    fn supports_select_wildcard_except(&self) -> bool {
95        true
96    }
97
98    fn require_interval_qualifier(&self) -> bool {
99        true
100    }
101
102    // See https://docs.databricks.com/en/sql/language-manual/functions/struct.html
103    fn supports_struct_literal(&self) -> bool {
104        true
105    }
106
107    /// See <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-comment>
108    fn supports_nested_comments(&self) -> bool {
109        true
110    }
111
112    /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html>
113    fn supports_group_by_with_modifier(&self) -> bool {
114        true
115    }
116
117    /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-values.html>
118    fn supports_values_as_table_factor(&self) -> bool {
119        true
120    }
121
122    /// See <https://docs.databricks.com/en/sql/language-manual/delta-optimize.html>
123    fn supports_optimize_table(&self) -> bool {
124        true
125    }
126
127    /// See <https://docs.databricks.com/aws/en/sql/language-manual/functions/bangsign>
128    fn supports_bang_not_operator(&self) -> bool {
129        true
130    }
131
132    /// See <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-cte>
133    fn supports_cte_without_as(&self) -> bool {
134        true
135    }
136
137    fn supports_select_item_multi_column_alias(&self) -> bool {
138        true
139    }
140
141    fn supports_map_literal_with_angle_brackets(&self) -> bool {
142        true
143    }
144
145    fn supports_data_type_collation(&self) -> bool {
146        true
147    }
148
149    fn supports_string_literal_backslash_escape(&self) -> bool {
150        true
151    }
152
153    fn supports_select_wildcard_replace(&self) -> bool {
154        true
155    }
156
157    fn supports_from_first_select(&self) -> bool {
158        true
159    }
160
161    fn supports_pipe_operator(&self) -> bool {
162        true
163    }
164}