mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00

* feat: add DuckDB dialect * formatting * fix conflict * support // in GenericDialect * add DucDbDialect to all_dialects * add comment from suggestion Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * fix: support // in GenericDialect --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
70 lines
2.3 KiB
Rust
70 lines
2.3 KiB
Rust
// Licensed 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.
|
|
|
|
#[macro_use]
|
|
mod test_utils;
|
|
|
|
use test_utils::*;
|
|
|
|
use sqlparser::ast::*;
|
|
use sqlparser::dialect::{DuckDbDialect, GenericDialect};
|
|
|
|
fn duckdb() -> TestedDialects {
|
|
TestedDialects {
|
|
dialects: vec![Box::new(DuckDbDialect {})],
|
|
options: None,
|
|
}
|
|
}
|
|
|
|
fn duckdb_and_generic() -> TestedDialects {
|
|
TestedDialects {
|
|
dialects: vec![Box::new(DuckDbDialect {}), Box::new(GenericDialect {})],
|
|
options: None,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_select_wildcard_with_exclude() {
|
|
let select = duckdb().verified_only_select("SELECT * EXCLUDE (col_a) FROM data");
|
|
let expected = SelectItem::Wildcard(WildcardAdditionalOptions {
|
|
opt_exclude: Some(ExcludeSelectItem::Multiple(vec![Ident::new("col_a")])),
|
|
..Default::default()
|
|
});
|
|
assert_eq!(expected, select.projection[0]);
|
|
|
|
let select =
|
|
duckdb().verified_only_select("SELECT name.* EXCLUDE department_id FROM employee_table");
|
|
let expected = SelectItem::QualifiedWildcard(
|
|
ObjectName(vec![Ident::new("name")]),
|
|
WildcardAdditionalOptions {
|
|
opt_exclude: Some(ExcludeSelectItem::Single(Ident::new("department_id"))),
|
|
..Default::default()
|
|
},
|
|
);
|
|
assert_eq!(expected, select.projection[0]);
|
|
|
|
let select = duckdb()
|
|
.verified_only_select("SELECT * EXCLUDE (department_id, employee_id) FROM employee_table");
|
|
let expected = SelectItem::Wildcard(WildcardAdditionalOptions {
|
|
opt_exclude: Some(ExcludeSelectItem::Multiple(vec![
|
|
Ident::new("department_id"),
|
|
Ident::new("employee_id"),
|
|
])),
|
|
..Default::default()
|
|
});
|
|
assert_eq!(expected, select.projection[0]);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_div_infix() {
|
|
duckdb_and_generic().verified_stmt(r#"SELECT 5 // 2"#);
|
|
}
|