Skip to content
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(SqlSmith): gen Table Subquery EXISTS #4431

Merged
merged 14 commits into from
Nov 26, 2022
13 changes: 12 additions & 1 deletion src/tests/sqlsmith/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ impl<'a, R: Rng> SqlGenerator<'a, R> {
let range = if can_agg & !inside_agg { 99 } else { 90 };

match self.rng.gen_range(0..=range) {
0..=80 => self.gen_func(typ, can_agg, inside_agg),
0..=70 => self.gen_func(typ, can_agg, inside_agg),
71..=80 => self.gen_exists(typ),
81..=90 => self.gen_cast(typ, can_agg, inside_agg),
91..=99 => self.gen_agg(typ),
// TODO: There are more that are not in the functions table, e.g. CAST.
Expand Down Expand Up @@ -181,6 +182,16 @@ impl<'a, R: Rng> SqlGenerator<'a, R> {
.unwrap_or_else(|| self.gen_simple_scalar(ret))
}

fn gen_exists(&mut self, ret: DataTypeName) -> Expr {
// TODO: Streaming nested loop join is not implemented yet.
// Tracked by: <https://github.com/singularity-data/risingwave/issues/2655>.
if self.is_mview || ret != DataTypeName::Boolean {
return self.gen_simple_scalar(ret);
};
let (subquery, _) = self.gen_local_query();
Expr::Exists(Box::new(subquery))
}

fn gen_agg(&mut self, ret: DataTypeName) -> Expr {
let funcs = match AGG_FUNC_TABLE.get(&ret) {
None => return self.gen_simple_scalar(ret),
Expand Down