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;
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    fn is_identifier_start(&self, ch: char) -> bool {
35        matches!(ch, 'a'..='z' | 'A'..='Z' | '_')
36    }
37
38    fn is_identifier_part(&self, ch: char) -> bool {
39        matches!(ch, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_')
40    }
41
42    fn supports_numeric_prefix(&self) -> bool {
43        true
44    }
45
46    fn supports_filter_during_aggregation(&self) -> bool {
47        true
48    }
49
50    // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html
51    fn supports_group_by_expr(&self) -> bool {
52        true
53    }
54
55    /// <https://docs.databricks.com/gcp/en/delta/history#delta-time-travel-syntax>
56    fn supports_table_versioning(&self) -> bool {
57        true
58    }
59
60    fn supports_lambda_functions(&self) -> bool {
61        true
62    }
63
64    // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html#syntax
65    fn supports_select_wildcard_except(&self) -> bool {
66        true
67    }
68
69    fn require_interval_qualifier(&self) -> bool {
70        true
71    }
72
73    // See https://docs.databricks.com/en/sql/language-manual/functions/struct.html
74    fn supports_struct_literal(&self) -> bool {
75        true
76    }
77
78    /// See <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-comment>
79    fn supports_nested_comments(&self) -> bool {
80        true
81    }
82
83    /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html>
84    fn supports_group_by_with_modifier(&self) -> bool {
85        true
86    }
87
88    /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-values.html>
89    fn supports_values_as_table_factor(&self) -> bool {
90        true
91    }
92
93    /// See <https://docs.databricks.com/en/sql/language-manual/delta-optimize.html>
94    fn supports_optimize_table(&self) -> bool {
95        true
96    }
97
98    /// See <https://docs.databricks.com/aws/en/sql/language-manual/functions/bangsign>
99    fn supports_bang_not_operator(&self) -> bool {
100        true
101    }
102
103    /// See <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-cte>
104    fn supports_cte_without_as(&self) -> bool {
105        true
106    }
107
108    fn supports_select_item_multi_column_alias(&self) -> bool {
109        true
110    }
111}