LucaCappelletti94 commented on code in PR #2380: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2380#discussion_r3719113401
########## src/dialect/doris.rs: ########## @@ -0,0 +1,53 @@ +// 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::dialect::Dialect; + +/// 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 { Review Comment: I believe you are still currently missing: * `supports_limit_comma` * `parse_infix` (the `DIV`) * `supports_group_by_with_modifier` I am not familiar enough with Doris to say anything about the other methods, but I suggest you audit them against the engine. ########## tests/sqlparser_doris.rs: ########## @@ -0,0 +1,55 @@ +// 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::{Dialect, DorisDialect, GenericDialect}; +use test_utils::*; + +fn doris() -> TestedDialects { + TestedDialects::new(vec![Box::new(DorisDialect {})]) +} + +fn doris_and_generic() -> TestedDialects { + TestedDialects::new(vec![Box::new(DorisDialect {}), Box::new(GenericDialect {})]) +} + +#[test] +fn doris_identifier_and_string_literal_gates() { + let dialect = DorisDialect {}; + assert_eq!(dialect.identifier_quote_style("identifier"), Some('`')); + assert!(dialect.is_delimited_identifier_start('`')); + assert!(dialect.supports_string_literal_backslash_escape()); + assert!(dialect.ignores_wildcard_escapes()); + assert!(dialect.supports_numeric_prefix()); +} + +#[test] +fn parse_doris_strings_and_identifiers() { + doris().verified_stmt( + r#"SELECT "double quoted string", 'single quoted string', `select` FROM `db`.`table`"#, + ); +} + +#[test] +fn doris_and_generic_parse_common_sql_identically() { + doris_and_generic().verified_stmt("SELECT 1 AS properties FROM t"); Review Comment: I imagine this will be more relevant in a later PR in this series where you add the keyword `PROPERTIES`? ########## src/dialect/doris.rs: ########## @@ -0,0 +1,53 @@ +// 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::dialect::Dialect; + +/// 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 { + fn is_delimited_identifier_start(&self, ch: char) -> bool { + ch == '`' + } + + fn identifier_quote_style(&self, _identifier: &str) -> Option<char> { + Some('`') + } + + fn is_identifier_start(&self, ch: char) -> bool { + ch.is_ascii_alphabetic() || ch == '_' || !ch.is_ascii() Review Comment: Since these methods at this time are extensively identical and meant to be identical to the `MySqlDialect`, I suggest they are kept aligned by using the same approach used with redshift and postgres and dispatch the method call to `MySqlDialect`. When they are strictly distinct, a comment with a documentation link may be desirable. ########## tests/sqlparser_doris.rs: ########## @@ -0,0 +1,55 @@ +// 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::{Dialect, DorisDialect, GenericDialect}; +use test_utils::*; + +fn doris() -> TestedDialects { + TestedDialects::new(vec![Box::new(DorisDialect {})]) +} + +fn doris_and_generic() -> TestedDialects { + TestedDialects::new(vec![Box::new(DorisDialect {}), Box::new(GenericDialect {})]) +} + +#[test] +fn doris_identifier_and_string_literal_gates() { + let dialect = DorisDialect {}; + assert_eq!(dialect.identifier_quote_style("identifier"), Some('`')); + assert!(dialect.is_delimited_identifier_start('`')); + assert!(dialect.supports_string_literal_backslash_escape()); + assert!(dialect.ignores_wildcard_escapes()); + assert!(dialect.supports_numeric_prefix()); +} + +#[test] +fn parse_doris_strings_and_identifiers() { + doris().verified_stmt( Review Comment: I believe here you may want to use `verified_only_select` ########## tests/sqlparser_doris.rs: ########## @@ -0,0 +1,55 @@ +// 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::{Dialect, DorisDialect, GenericDialect}; +use test_utils::*; + +fn doris() -> TestedDialects { + TestedDialects::new(vec![Box::new(DorisDialect {})]) +} + +fn doris_and_generic() -> TestedDialects { + TestedDialects::new(vec![Box::new(DorisDialect {}), Box::new(GenericDialect {})]) +} + +#[test] +fn doris_identifier_and_string_literal_gates() { Review Comment: I am unsure such a test is necessary -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
