sql/dialect.rs
1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub use sqlparser::dialect::{Dialect, GenericDialect, MySqlDialect, PostgreSqlDialect};
16
17/// GreptimeDb dialect
18#[derive(Debug, Clone)]
19pub struct GreptimeDbDialect {}
20
21impl Dialect for GreptimeDbDialect {
22 fn is_identifier_start(&self, ch: char) -> bool {
23 ch.is_alphabetic() || ch == '_' || ch == '#' || ch == '@'
24 }
25
26 fn is_identifier_part(&self, ch: char) -> bool {
27 ch.is_alphabetic()
28 || ch.is_ascii_digit()
29 || ch == '@'
30 || ch == '$'
31 || ch == '#'
32 || ch == '_'
33 }
34
35 // Accepts both `identifier` and "identifier".
36 fn is_delimited_identifier_start(&self, ch: char) -> bool {
37 ch == '`' || ch == '"'
38 }
39
40 fn supports_filter_during_aggregation(&self) -> bool {
41 true
42 }
43}