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_filter_during_aggregation(&self) -> bool {
43 true
44 }
45
46 // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html
47 fn supports_group_by_expr(&self) -> bool {
48 true
49 }
50
51 /// <https://docs.databricks.com/gcp/en/delta/history#delta-time-travel-syntax>
52 fn supports_table_versioning(&self) -> bool {
53 true
54 }
55
56 fn supports_lambda_functions(&self) -> bool {
57 true
58 }
59
60 // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html#syntax
61 fn supports_select_wildcard_except(&self) -> bool {
62 true
63 }
64
65 fn require_interval_qualifier(&self) -> bool {
66 true
67 }
68
69 // See https://docs.databricks.com/en/sql/language-manual/functions/struct.html
70 fn supports_struct_literal(&self) -> bool {
71 true
72 }
73
74 /// See <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-comment>
75 fn supports_nested_comments(&self) -> bool {
76 true
77 }
78
79 /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html>
80 fn supports_group_by_with_modifier(&self) -> bool {
81 true
82 }
83
84 /// See <https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-values.html>
85 fn supports_values_as_table_factor(&self) -> bool {
86 true
87 }
88}