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
Support DISTINCT
for SetOperator
#689
Changes from 9 commits
55b1d2d
e424471
0ac391c
f6e8305
ac41a8e
0337257
826dcc5
03e4950
e52e567
ae6fb81
f336342
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 |
---|---|---|
|
@@ -64,6 +64,25 @@ impl fmt::Display for Query { | |
} | ||
} | ||
|
||
/// Options for SetOperator | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub enum SetQuantifier { | ||
All, | ||
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. In general it should be possible to round trip structures in sqlparser -- so it should be possible to distinguish between 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'll add the 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 fixed this at ac41a8e |
||
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 node in a tree, representing a "query body" expression, roughly: | ||
/// `SELECT ... [ {UNION|EXCEPT|INTERSECT} SELECT ...]` | ||
#[allow(clippy::large_enum_variant)] | ||
|
@@ -78,7 +97,7 @@ pub enum SetExpr { | |
/// UNION/EXCEPT/INTERSECT of two queries | ||
SetOperation { | ||
op: SetOperator, | ||
all: bool, | ||
set_quantifier: SetQuantifier, | ||
alamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
left: Box<SetExpr>, | ||
right: Box<SetExpr>, | ||
}, | ||
|
@@ -98,10 +117,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(()) | ||
} | ||
} | ||
} | ||
|
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.
Would be nice having more description about the structure. Maybe a reference of which big dialects use it...