diff --git a/Cargo.lock b/Cargo.lock index 03f1b281a4c98..03cf75c3e6b2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6784,9 +6784,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "symbolic-common" -version = "10.1.2" +version = "10.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "492875918a6bcbae753a5fc6f39bc87566fc3c25182e76d7f128ef1c8a2375c6" +checksum = "56de97fb15cc5db0100c22aed51cee31b013234bc43e00e4035cad048a4c7cd8" dependencies = [ "debugid", "memmap2", @@ -6796,9 +6796,9 @@ dependencies = [ [[package]] name = "symbolic-demangle" -version = "10.1.2" +version = "10.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "214d3a420108471222e55268ef502ba0fc89cfd4de876ff26105c560729127af" +checksum = "0fe238e66ada3122c2efe810ba17459df9f7573b45dd523a8057e4c0f515e860" dependencies = [ "cpp_demangle", "rustc-demangle", @@ -7059,9 +7059,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.2" +version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" dependencies = [ "autocfg", "bytes", diff --git a/src/tests/sqlsmith/src/expr.rs b/src/tests/sqlsmith/src/expr.rs index a5b439d3ac4af..6b3263a781deb 100644 --- a/src/tests/sqlsmith/src/expr.rs +++ b/src/tests/sqlsmith/src/expr.rs @@ -84,7 +84,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, inside_agg), 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. @@ -242,6 +243,22 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { .unwrap_or_else(|| self.gen_simple_scalar(ret)) } + fn gen_exists(&mut self, ret: DataTypeName, inside_agg: bool) -> Expr { + // TODO: Streaming nested loop join is not implemented yet. + // Tracked by: . + + // Generation of subquery inside aggregation is now workaround. + // Tracked by: . + if self.is_mview || ret != DataTypeName::Boolean || inside_agg { + return self.gen_simple_scalar(ret); + }; + // TODO: Feature is not yet implemented: correlated subquery in HAVING or SELECT with agg + // let (subquery, _) = self.gen_correlated_query(); + // Tracked by: + let (subquery, _) = self.gen_local_query(); + Expr::Exists(Box::new(subquery)) + } + fn gen_agg(&mut self, ret: DataTypeName) -> Expr { // TODO: workaround for if ret == DataTypeName::Interval { diff --git a/src/tests/sqlsmith/src/lib.rs b/src/tests/sqlsmith/src/lib.rs index 856c85b913651..b522e61106636 100644 --- a/src/tests/sqlsmith/src/lib.rs +++ b/src/tests/sqlsmith/src/lib.rs @@ -210,7 +210,7 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { } /// Generates a query with local context. - /// Used by `WITH`, subquery + /// Used by `WITH`, `Table Subquery` in Relation fn gen_local_query(&mut self) -> (Query, Vec) { let old_ctxt = self.new_local_context(); let t = self.gen_query(); @@ -218,6 +218,16 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { t } + /// Generates a query with correlated context to ensure proper recursion. + /// Used by Exists `Subquery` + /// TODO: + fn _gen_correlated_query(&mut self) -> (Query, Vec) { + let old_ctxt = self._clone_local_context(); + let t = self.gen_query(); + self.restore_context(old_ctxt); + t + } + fn gen_with(&mut self) -> (Option, Vec) { match self.flip_coin() { true => (None, vec![]), diff --git a/src/tests/sqlsmith/src/utils.rs b/src/tests/sqlsmith/src/utils.rs index 88c9084566331..fbdbc1832f68a 100644 --- a/src/tests/sqlsmith/src/utils.rs +++ b/src/tests/sqlsmith/src/utils.rs @@ -36,6 +36,13 @@ impl<'a, R: Rng> SqlGenerator<'a, R> { self.bound_relations = old_rels; self.bound_columns = old_cols; } + + // TODO: + pub(crate) fn _clone_local_context(&mut self) -> Context { + let current_bound_relations = self.bound_relations.clone(); + let current_bound_columns = self.bound_columns.clone(); + (current_bound_columns, current_bound_relations) + } } /// Gen utils