Support DISTINCT for SetOperator (#689)

* Update SetOperation field all to op_option

* Implement parse_set_operator_option

cargo fmt

Fix parse_set_operator_option after next_token

* Add test for parsing union distinct

* Rename to SetQualifier and fix fmt space

* Add None to SetQualifier

* Update parse method

* Rename to SetQuantifier

* Rename parse_set_operator_option parse_set_operator

* Fix test to parse union, except, intersect

* Add some comments to SetQuantifier

* Fix comment
This commit is contained in:
unvalley 2022-11-07 21:05:59 +09:00 committed by GitHub
parent 0f7e144890
commit f7817bc7c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 9 deletions

View file

@ -4072,14 +4072,17 @@ fn parse_derived_tables() {
}
#[test]
fn parse_union() {
fn parse_union_except_intersect() {
// TODO: add assertions
verified_stmt("SELECT 1 UNION SELECT 2");
verified_stmt("SELECT 1 UNION ALL SELECT 2");
verified_stmt("SELECT 1 UNION DISTINCT SELECT 1");
verified_stmt("SELECT 1 EXCEPT SELECT 2");
verified_stmt("SELECT 1 EXCEPT ALL SELECT 2");
verified_stmt("SELECT 1 EXCEPT DISTINCT SELECT 1");
verified_stmt("SELECT 1 INTERSECT SELECT 2");
verified_stmt("SELECT 1 INTERSECT ALL SELECT 2");
verified_stmt("SELECT 1 INTERSECT DISTINCT SELECT 1");
verified_stmt("SELECT 1 UNION SELECT 2 UNION SELECT 3");
verified_stmt("SELECT 1 EXCEPT SELECT 2 UNION SELECT 3"); // Union[Except[1,2], 3]
verified_stmt("SELECT 1 INTERSECT (SELECT 2 EXCEPT SELECT 3)");
@ -4088,6 +4091,7 @@ fn parse_union() {
verified_stmt("SELECT 1 UNION SELECT 2 INTERSECT SELECT 3"); // Union[1, Intersect[2,3]]
verified_stmt("SELECT foo FROM tab UNION SELECT bar FROM TAB");
verified_stmt("(SELECT * FROM new EXCEPT SELECT * FROM old) UNION ALL (SELECT * FROM old EXCEPT SELECT * FROM new) ORDER BY 1");
verified_stmt("(SELECT * FROM new EXCEPT DISTINCT SELECT * FROM old) UNION DISTINCT (SELECT * FROM old EXCEPT DISTINCT SELECT * FROM new) ORDER BY 1");
}
#[test]