-
Notifications
You must be signed in to change notification settings - Fork 779
Doris SQL: add Doris Dialect #2380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7ff24be
78c8b9c
d29d027
3390f3f
cc99298
282819b
ca70ec2
e559954
d728af4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use crate::{ | ||
| ast::Expr, | ||
| dialect::{Dialect, MySqlDialect}, | ||
| parser::{Parser, ParserError}, | ||
| }; | ||
|
|
||
| /// A [`Dialect`] for [Apache Doris](https://doris.apache.org/). | ||
| #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
| #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
| pub struct DorisDialect {} | ||
|
|
||
| impl Dialect for DorisDialect { | ||
|
finchxxia marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also add
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add a |
||
| fn supports_nested_comments(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn is_delimited_identifier_start(&self, ch: char) -> bool { | ||
| MySqlDialect {}.is_delimited_identifier_start(ch) | ||
| } | ||
|
|
||
| fn identifier_quote_style(&self, identifier: &str) -> Option<char> { | ||
| MySqlDialect {}.identifier_quote_style(identifier) | ||
| } | ||
|
|
||
| fn is_identifier_start(&self, ch: char) -> bool { | ||
| MySqlDialect {}.is_identifier_start(ch) | ||
| } | ||
|
|
||
| fn is_identifier_part(&self, ch: char) -> bool { | ||
| MySqlDialect {}.is_identifier_part(ch) | ||
| } | ||
|
|
||
| fn supports_string_literal_backslash_escape(&self) -> bool { | ||
| MySqlDialect {}.supports_string_literal_backslash_escape() | ||
| } | ||
|
|
||
| fn ignores_wildcard_escapes(&self) -> bool { | ||
| MySqlDialect {}.ignores_wildcard_escapes() | ||
| } | ||
|
|
||
| fn supports_numeric_prefix(&self) -> bool { | ||
| MySqlDialect {}.supports_numeric_prefix() | ||
| } | ||
|
|
||
| fn supports_limit_comma(&self) -> bool { | ||
| MySqlDialect {}.supports_limit_comma() | ||
| } | ||
|
|
||
| fn parse_infix( | ||
| &self, | ||
| parser: &mut Parser, | ||
| expr: &Expr, | ||
| precedence: u8, | ||
| ) -> Option<Result<Expr, ParserError>> { | ||
| MySqlDialect {}.parse_infix(parser, expr, precedence) | ||
| } | ||
|
|
||
| fn supports_group_by_with_modifier(&self) -> bool { | ||
| MySqlDialect {}.supports_group_by_with_modifier() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #![warn(clippy::all)] | ||
| //! Test SQL syntax specific to Apache Doris. | ||
|
|
||
| #[macro_use] | ||
| mod test_utils; | ||
|
|
||
| use sqlparser::dialect::DorisDialect; | ||
| use test_utils::*; | ||
|
|
||
| fn doris() -> TestedDialects { | ||
| TestedDialects::new(vec![Box::new(DorisDialect {})]) | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_doris_strings_and_identifiers() { | ||
| doris().verified_only_select( | ||
| r#"SELECT "double quoted string", 'single quoted string', `select` FROM `db`.`table`"#, | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_doris_limit_comma() { | ||
| doris().verified_only_select("SELECT * FROM t LIMIT 5, 10"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_doris_div_infix() { | ||
| doris().verified_only_select("SELECT 5 DIV 2"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_doris_group_by_with_rollup() { | ||
| doris().verified_only_select("SELECT * FROM t GROUP BY col1, col2 WITH ROLLUP"); | ||
| } | ||
|
finchxxia marked this conversation as resolved.
|
||
|
|
||
| #[test] | ||
| fn parse_doris_nested_comments() { | ||
| doris().one_statement_parses_to("SELECT 1 /* a /* b */ c */, 2", "SELECT 1, 2"); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you are still currently missing:
supports_limit_commaparse_infix(theDIV)supports_group_by_with_modifierI am not familiar enough with Doris to say anything about the other methods, but I suggest you audit them against the engine.