Skip to main content

rustfs_s3select_api/query/
parser.rs

1// Copyright 2024 RustFS 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
15use std::collections::VecDeque;
16
17use datafusion::sql::sqlparser::dialect::Dialect;
18
19use super::ast::ExtStatement;
20use crate::QueryResult;
21
22#[derive(Debug, Default)]
23pub struct RustFsDialect;
24
25impl Dialect for RustFsDialect {
26    fn is_identifier_start(&self, ch: char) -> bool {
27        ch.is_alphabetic() || ch == '_' || ch == '#' || ch == '@'
28    }
29
30    fn is_identifier_part(&self, ch: char) -> bool {
31        ch.is_alphabetic() || ch.is_ascii_digit() || ch == '@' || ch == '$' || ch == '#' || ch == '_'
32    }
33
34    fn supports_group_by_expr(&self) -> bool {
35        true
36    }
37
38    fn supports_partiql(&self) -> bool {
39        true
40    }
41}
42
43pub trait Parser {
44    fn parse(&self, sql: &str) -> QueryResult<VecDeque<ExtStatement>>;
45}