-
Notifications
You must be signed in to change notification settings - Fork 594
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
feat: EXCEPT in SELECT #10438
feat: EXCEPT in SELECT #10438
Conversation
Can we add more tests, e.g.:
|
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.
- we can not bind it in the query level, we should treat it as a modifier on the
*
or WildCard.
dev=# select * from t;
a | b | c
---+---+---
2 | 1 | 3
(1 row)
dev=# select *, * from t;
a | b | c | a | b | c
---+---+---+---+---+---
2 | 1 | 3 | 2 | 1 | 3
(1 row)
- we need to support multiple value in the except.
SELECT * EXCEPT (i, j, k);
In conclusion, we might need to add SelectItem::ExceptWithExcept(Vec<Expr>)
even use it to replace the original WildCard
@@ -37,6 +37,8 @@ | |||
formatted_sql: SELECT id, fname, lname FROM customer WHERE salary <> 'Not Provided' AND salary <> '' | |||
- input: SELECT id FROM customer WHERE NOT salary = '' | |||
formatted_sql: SELECT id FROM customer WHERE NOT salary = '' | |||
- input: SELECT * EXCEPT v1 FROM foo | |||
formatted_sql: SELECT EXCEPT v1 FROM foo |
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.
Is this valid?
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.
This is valid in current implementation and there are many things to be fixed and there will be possible change later.
e.g., the TopN pattern BTW, is the syntax decided?
Besides, multiple columns are not tested and things like |
Hi could you add some sqlsmith fuzzing tests? Feel free to ask me if any questions. You may check out the developer docs here: https://github.com/risingwavelabs/risingwave/blob/main/src/tests/sqlsmith/develop.md |
|
Codecov Report
@@ Coverage Diff @@
## main #10438 +/- ##
==========================================
- Coverage 70.38% 70.37% -0.01%
==========================================
Files 1269 1269
Lines 217167 217216 +49
==========================================
+ Hits 152843 152868 +25
- Misses 64324 64348 +24
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -42,6 +42,15 @@ | |||
StreamMaterialize { columns: [v1, t._row_id(hidden)], stream_key: [t._row_id], pk_columns: [t._row_id], pk_conflict: "NoCheck" } | |||
└─StreamFilter { predicate: (t.v1 < 1:Int32) } | |||
└─StreamTableScan { table: t, columns: [t.v1, t._row_id], pk: [t._row_id], dist: UpstreamHashShard(t._row_id) } | |||
- sql: | | |||
create table t (v1 int, v2 int, v3 int); | |||
select * except (v1, v2) from t; |
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.
Can we add more tests which explicitly select except
columns?
Something like:
select v3 from (select * except (v1, v2) from t
Can we also add tests which have selected the excepted row, and re-select already included rows?
select * except (v1, v2), v1 from t; -- v1 excluded from except.
select * except (v1, v2), v3 from t; -- v3 included from except.
src/frontend/src/binder/select.rs
Outdated
if self.context.range_of.is_empty() { | ||
return Err(ErrorCode::BindError( | ||
"SELECT * with no tables specified is not valid".into(), | ||
) | ||
.into()); | ||
} |
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.
extract it out of the match?
src/frontend/src/binder/select.rs
Outdated
let (exprs, names) = self.iter_column_groups(); | ||
select_list.extend(exprs); | ||
aliases.extend(names); | ||
|
||
// Bind columns that are not in groups | ||
let (exprs, names) = Self::iter_bound_columns( | ||
self.context.columns[..].iter().filter(|c| { | ||
!c.is_hidden | ||
&& !self | ||
.context | ||
.column_group_context | ||
.mapping | ||
.contains_key(&c.index) | ||
}), | ||
); |
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.
I think some common logic about the column_groups is lost
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.
LGTM
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.
There aren't any tests for syntax errors 😟
formatted_sql: SELECT * EXCEPT (v1, v2) FROM foo | ||
formatted_ast: 'Query(Query { with: None, body: Select(Select { distinct: All, projection: [WildcardOrWithExcept(Some([Identifier(Ident { value: "v1", quote_style: None }), Identifier(Ident { value: "v2", quote_style: None })]))], from: [TableWithJoins { relation: Table { name: ObjectName([Ident { value: "foo", quote_style: None }]), alias: None, for_system_time_as_of_proctime: false }, joins: [] }], lateral_views: [], selection: None, group_by: [], having: None }), order_by: [], limit: None, offset: None, fetch: None })' | ||
- input: SELECT v3 EXCEPT (v1, v2) FROM foo | ||
error_msg: |- |
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.
I think this is a test for syntax. But it is not sufficient indeed. I will add some.
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Add support to following syntax:
close #9092.
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Click here for Documentation
Types of user-facing changes
Please keep the types that apply to your changes, and remove the others.
Release note