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