-
Notifications
You must be signed in to change notification settings - Fork 616
feat: add DuckDB dialect #878
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
58efd2f
feat: add DuckDB dialect
eitsupi 46c9394
Merge remote-tracking branch 'upstream/main' into duckdb-int-div
eitsupi c08b40f
formatting
eitsupi fdf904b
fix conflict
eitsupi 6c903a9
support // in GenericDialect
eitsupi 4622d62
add DucDbDialect to all_dialects
eitsupi f2909fa
add comment from suggestion
eitsupi c71b13e
fix: support // in GenericDialect
eitsupi 0e1073b
Merge branch 'duckdb-int-div' of github.com:eitsupi/sqlparser-rs into…
eitsupi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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. | ||
|
||
use crate::dialect::Dialect; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct DuckDbDialect; | ||
|
||
// In most cases the redshift dialect is identical to [`PostgresSqlDialect`]. | ||
impl Dialect for DuckDbDialect { | ||
fn is_identifier_start(&self, ch: char) -> bool { | ||
ch.is_alphabetic() || ch == '_' | ||
} | ||
|
||
fn is_identifier_part(&self, ch: char) -> bool { | ||
ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_' | ||
} | ||
|
||
fn supports_filter_during_aggregation(&self) -> bool { | ||
true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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"#); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.