-
Notifications
You must be signed in to change notification settings - Fork 612
Support DISTINCT
for SetOperator
#689
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
11 commits
Select commit
Hold shift + click to select a range
55b1d2d
Update SetOperation field all to op_option
unvalley e424471
Implement parse_set_operator_option
unvalley 0ac391c
Add test for parsing union distinct
unvalley f6e8305
Rename to SetQualifier and fix fmt space
unvalley ac41a8e
Add None to SetQualifier
unvalley 0337257
Update parse method
unvalley 826dcc5
Rename to SetQuantifier
unvalley 03e4950
Rename parse_set_operator_option parse_set_operator
unvalley e52e567
Fix test to parse union, except, intersect
unvalley ae6fb81
Add some comments to SetQuantifier
unvalley f336342
Fix comment
unvalley 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ pub enum SetExpr { | |
/// UNION/EXCEPT/INTERSECT of two queries | ||
SetOperation { | ||
op: SetOperator, | ||
all: bool, | ||
set_quantifier: SetQuantifier, | ||
left: Box<SetExpr>, | ||
right: Box<SetExpr>, | ||
}, | ||
|
@@ -98,10 +98,17 @@ impl fmt::Display for SetExpr { | |
left, | ||
right, | ||
op, | ||
all, | ||
set_quantifier, | ||
} => { | ||
let all_str = if *all { " ALL" } else { "" }; | ||
write!(f, "{} {}{} {}", left, op, all_str, right) | ||
write!(f, "{} {}", left, op)?; | ||
match set_quantifier { | ||
SetQuantifier::All | SetQuantifier::Distinct => { | ||
write!(f, " {}", set_quantifier)? | ||
} | ||
SetQuantifier::None => write!(f, "{}", set_quantifier)?, | ||
} | ||
write!(f, " {}", right)?; | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
@@ -125,6 +132,26 @@ impl fmt::Display for SetOperator { | |
} | ||
} | ||
|
||
/// A quantifier for [SetOperator]. | ||
// TODO: Restrict parsing specific SetQuantifier in some specific dialects. | ||
// For example, BigQuery does not support `DISTINCT` for `EXCEPT` and `INTERSECT` | ||
Comment on lines
+135
to
+137
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. I added some comments at ae6fb81 , but I wasn't quite sure how to describe this enum🥲 |
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub enum SetQuantifier { | ||
All, | ||
Distinct, | ||
None, | ||
} | ||
|
||
impl fmt::Display for SetQuantifier { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
SetQuantifier::All => write!(f, "ALL"), | ||
SetQuantifier::Distinct => write!(f, "DISTINCT"), | ||
SetQuantifier::None => write!(f, ""), | ||
} | ||
} | ||
} | ||
/// A restricted variant of `SELECT` (without CTEs/`ORDER BY`), which may | ||
/// appear either as the only body item of a `Query`, or as an operand | ||
/// to a set operation like `UNION`. | ||
|
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
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.