Apache DataFusion SQL Query Engine
Migrate Optimizer tests to insta, part5 (#15945)
Tommy shu8d79bddeda71
diff --git a/datafusion/optimizer/src/extract_equijoin_predicate.rs b/datafusion/optimizer/src/extract_equijoin_predicate.rsindex 48191ec206..a07b50ade5 100644--- a/datafusion/optimizer/src/extract_equijoin_predicate.rs+++ b/datafusion/optimizer/src/extract_equijoin_predicate.rs@@ -155,6 +155,7 @@ fn split_eq_and_noneq_join_predicate(#[cfg(test)]mod tests {use super::*;+ use crate::assert_optimized_plan_eq_display_indent_snapshot;use crate::test::*;use arrow::datatypes::DataType;use datafusion_expr::{@@ -162,14 +163,18 @@ mod tests {};use std::sync::Arc;- fn assert_plan_eq(plan: LogicalPlan, expected: &str) -> Result<()> {- assert_optimized_plan_eq_display_indent(- Arc::new(ExtractEquijoinPredicate {}),- plan,- expected,- );-- Ok(())+ macro_rules! assert_optimized_plan_equal {+ (+ $plan:expr,+ @ $expected:literal $(,)?+ ) => {{+ let rule: Arc<dyn crate::OptimizerRule + Send + Sync> = Arc::new(ExtractEquijoinPredicate {});+ assert_optimized_plan_eq_display_indent_snapshot!(+ rule,+ $plan,+ @ $expected,+ )+ }};}#[test]@@ -180,11 +185,15 @@ mod tests {let plan = LogicalPlanBuilder::from(t1).join_on(t2, JoinType::Left, Some(col("t1.a").eq(col("t2.a"))))?.build()?;- let expected = "Left Join: t1.a = t2.a [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a = t2.a [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -199,11 +208,15 @@ mod tests {Some((col("t1.a") + lit(10i64)).eq(col("t2.a") * lit(2u32))),)?.build()?;- let expected = "Left Join: t1.a + Int64(10) = t2.a * UInt32(2) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a + Int64(10) = t2.a * UInt32(2) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -222,11 +235,15 @@ mod tests {),)?.build()?;- let expected = "Left Join: Filter: t1.a + Int64(10) >= t2.a * UInt32(2) AND t1.b < Int32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: Filter: t1.a + Int64(10) >= t2.a * UInt32(2) AND t1.b < Int32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -249,11 +266,15 @@ mod tests {),)?.build()?;- let expected = "Left Join: t1.a + UInt32(11) = t2.a * UInt32(2), t1.a + Int64(10) = t2.a * UInt32(2) Filter: t1.b < Int32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a + UInt32(11) = t2.a * UInt32(2), t1.a + Int64(10) = t2.a * UInt32(2) Filter: t1.b < Int32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -275,11 +296,15 @@ mod tests {),)?.build()?;- let expected = "Left Join: t1.a = t2.a, t1.b = t2.b Filter: t1.c = t2.c OR t1.a + t1.b > t2.b + t2.c [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a = t2.a, t1.b = t2.b Filter: t1.c = t2.c OR t1.a + t1.b > t2.b + t2.c [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -310,13 +335,17 @@ mod tests {),)?.build()?;- let expected = "Left Join: t1.a = t2.a Filter: t1.c + t2.c + t3.c < UInt32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n Left Join: t2.a = t3.a Filter: t2.a + t3.b > UInt32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t3 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a = t2.a Filter: t1.c + t2.c + t3.c < UInt32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ Left Join: t2.a = t3.a Filter: t2.a + t3.b > UInt32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t3 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -343,13 +372,17 @@ mod tests {Some(col("t1.a").eq(col("t2.a")).and(col("t2.c").eq(col("t3.c")))),)?.build()?;- let expected = "Left Join: t1.a = t2.a Filter: t2.c = t3.c [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n Left Join: t2.a = t3.a Filter: t2.a + t3.b > UInt32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t3 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a = t2.a Filter: t2.c = t3.c [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ Left Join: t2.a = t3.a Filter: t2.a + t3.b > UInt32(100) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t3 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -369,10 +402,14 @@ mod tests {let plan = LogicalPlanBuilder::from(t1).join_on(t2, JoinType::Left, Some(filter))?.build()?;- let expected = "Left Join: t1.a + CAST(Int64(1) AS UInt32) = t2.a + CAST(Int32(2) AS UInt32) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]\- \n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]\- \n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]";- assert_plan_eq(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Left Join: t1.a + CAST(Int64(1) AS UInt32) = t2.a + CAST(Int32(2) AS UInt32) [a:UInt32, b:UInt32, c:UInt32, a:UInt32;N, b:UInt32;N, c:UInt32;N]+ TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]+ TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]+ "+ )}}diff --git a/datafusion/optimizer/src/scalar_subquery_to_join.rs b/datafusion/optimizer/src/scalar_subquery_to_join.rsindex 5c89bc29a5..897e07cb98 100644--- a/datafusion/optimizer/src/scalar_subquery_to_join.rs+++ b/datafusion/optimizer/src/scalar_subquery_to_join.rs@@ -407,9 +407,24 @@ mod tests {use arrow::datatypes::DataType;use datafusion_expr::test::function_stub::sum;+ use crate::assert_optimized_plan_eq_display_indent_snapshot;use datafusion_expr::{col, lit, out_ref_col, scalar_subquery, Between};use datafusion_functions_aggregate::min_max::{max, min};+ macro_rules! assert_optimized_plan_equal {+ (+ $plan:expr,+ @ $expected:literal $(,)?+ ) => {{+ let rule: Arc<dyn crate::OptimizerRule + Send + Sync> = Arc::new(ScalarSubqueryToJoin::new());+ assert_optimized_plan_eq_display_indent_snapshot!(+ rule,+ $plan,+ @ $expected,+ )+ }};+ }+/// Test multiple correlated subqueries#[test]fn multiple_subqueries() -> Result<()> {@@ -433,25 +448,24 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: Int32(1) < __scalar_sq_1.max(orders.o_custkey) AND Int32(1) < __scalar_sq_2.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: __scalar_sq_2.o_custkey = customer.c_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: __scalar_sq_1.o_custkey = customer.c_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n SubqueryAlias: __scalar_sq_2 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: Int32(1) < __scalar_sq_1.max(orders.o_custkey) AND Int32(1) < __scalar_sq_2.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: __scalar_sq_2.o_custkey = customer.c_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: __scalar_sq_1.o_custkey = customer.c_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ SubqueryAlias: __scalar_sq_2 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test recursive correlated subqueries@@ -488,26 +502,25 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_acctbal < __scalar_sq_1.sum(orders.o_totalprice) [c_custkey:Int64, c_name:Utf8, sum(orders.o_totalprice):Float64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: __scalar_sq_1.o_custkey = customer.c_custkey [c_custkey:Int64, c_name:Utf8, sum(orders.o_totalprice):Float64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [sum(orders.o_totalprice):Float64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: sum(orders.o_totalprice), orders.o_custkey, __always_true [sum(orders.o_totalprice):Float64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[sum(orders.o_totalprice)]] [o_custkey:Int64, __always_true:Boolean, sum(orders.o_totalprice):Float64;N]\- \n Filter: orders.o_totalprice < __scalar_sq_2.sum(lineitem.l_extendedprice) [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N, sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: __scalar_sq_2.l_orderkey = orders.o_orderkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N, sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n SubqueryAlias: __scalar_sq_2 [sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64, __always_true:Boolean]\- \n Projection: sum(lineitem.l_extendedprice), lineitem.l_orderkey, __always_true [sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[lineitem.l_orderkey, Boolean(true) AS __always_true]], aggr=[[sum(lineitem.l_extendedprice)]] [l_orderkey:Int64, __always_true:Boolean, sum(lineitem.l_extendedprice):Float64;N]\- \n TableScan: lineitem [l_orderkey:Int64, l_partkey:Int64, l_suppkey:Int64, l_linenumber:Int32, l_quantity:Float64, l_extendedprice:Float64]";- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_acctbal < __scalar_sq_1.sum(orders.o_totalprice) [c_custkey:Int64, c_name:Utf8, sum(orders.o_totalprice):Float64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: __scalar_sq_1.o_custkey = customer.c_custkey [c_custkey:Int64, c_name:Utf8, sum(orders.o_totalprice):Float64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [sum(orders.o_totalprice):Float64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: sum(orders.o_totalprice), orders.o_custkey, __always_true [sum(orders.o_totalprice):Float64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[sum(orders.o_totalprice)]] [o_custkey:Int64, __always_true:Boolean, sum(orders.o_totalprice):Float64;N]+ Filter: orders.o_totalprice < __scalar_sq_2.sum(lineitem.l_extendedprice) [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N, sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: __scalar_sq_2.l_orderkey = orders.o_orderkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N, sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64;N, __always_true:Boolean;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ SubqueryAlias: __scalar_sq_2 [sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64, __always_true:Boolean]+ Projection: sum(lineitem.l_extendedprice), lineitem.l_orderkey, __always_true [sum(lineitem.l_extendedprice):Float64;N, l_orderkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[lineitem.l_orderkey, Boolean(true) AS __always_true]], aggr=[[sum(lineitem.l_extendedprice)]] [l_orderkey:Int64, __always_true:Boolean, sum(lineitem.l_extendedprice):Float64;N]+ TableScan: lineitem [l_orderkey:Int64, l_partkey:Int64, l_suppkey:Int64, l_linenumber:Int32, l_quantity:Float64, l_extendedprice:Float64]+ "+ )}/// Test for correlated scalar subquery filter with additional subquery filters@@ -530,22 +543,20 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n Filter: orders.o_orderkey = Int32(1) [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ Filter: orders.o_orderkey = Int32(1) [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test for correlated scalar subquery with no columns in schema@@ -568,20 +579,19 @@ mod tests {.build()?;// it will optimize, but fail for the same reason the unoptimized query would- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test for scalar subquery with both columns in schema@@ -600,22 +610,20 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n Filter: orders.o_custkey = orders.o_custkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ Filter: orders.o_custkey = orders.o_custkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test for correlated scalar subquery not equal@@ -638,21 +646,19 @@ mod tests {.build()?;// Unsupported predicate, subquery should not be decorrelated- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = (<subquery>) [c_custkey:Int64, c_name:Utf8]\- \n Subquery: [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n Filter: outer_ref(customer.c_custkey) != orders.o_custkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = (<subquery>) [c_custkey:Int64, c_name:Utf8]+ Subquery: [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ Filter: outer_ref(customer.c_custkey) != orders.o_custkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ "+ )}/// Test for correlated scalar subquery less than@@ -675,21 +681,19 @@ mod tests {.build()?;// Unsupported predicate, subquery should not be decorrelated- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = (<subquery>) [c_custkey:Int64, c_name:Utf8]\- \n Subquery: [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n Filter: outer_ref(customer.c_custkey) < orders.o_custkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = (<subquery>) [c_custkey:Int64, c_name:Utf8]+ Subquery: [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ Filter: outer_ref(customer.c_custkey) < orders.o_custkey [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ "+ )}/// Test for correlated scalar subquery filter with subquery disjunction@@ -713,21 +717,19 @@ mod tests {.build()?;// Unsupported predicate, subquery should not be decorrelated- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = (<subquery>) [c_custkey:Int64, c_name:Utf8]\- \n Subquery: [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n Filter: outer_ref(customer.c_custkey) = orders.o_custkey OR orders.o_orderkey = Int32(1) [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = (<subquery>) [c_custkey:Int64, c_name:Utf8]+ Subquery: [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ Filter: outer_ref(customer.c_custkey) = orders.o_custkey OR orders.o_orderkey = Int32(1) [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ "+ )}/// Test for correlated scalar without projection@@ -768,21 +770,19 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) + Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey) + Int32(1), orders.o_custkey, __always_true [max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) + Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey) + Int32(1), orders.o_custkey, __always_true [max(orders.o_custkey) + Int32(1):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test for correlated scalar subquery with non-strong project@@ -812,20 +812,18 @@ mod tests {.project(vec![col("customer.c_custkey"), scalar_subquery(sq)])?.build()?;- let expected = "Projection: customer.c_custkey, CASE WHEN __scalar_sq_1.__always_true IS NULL THEN CASE WHEN CAST(NULL AS Boolean) THEN Utf8(\"a\") ELSE Utf8(\"b\") END ELSE __scalar_sq_1.CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END END AS CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END [c_custkey:Int64, CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END:Utf8;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END:Utf8;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END:Utf8, o_custkey:Int64, __always_true:Boolean]\- \n Projection: CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END, orders.o_custkey, __always_true [CASE WHEN max(orders.o_totalprice) THEN Utf8(\"a\") ELSE Utf8(\"b\") END:Utf8, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_totalprice)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_totalprice):Float64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r#"+ Projection: customer.c_custkey, CASE WHEN __scalar_sq_1.__always_true IS NULL THEN CASE WHEN CAST(NULL AS Boolean) THEN Utf8("a") ELSE Utf8("b") END ELSE __scalar_sq_1.CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END END AS CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END [c_custkey:Int64, CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END:Utf8;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END:Utf8;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END:Utf8, o_custkey:Int64, __always_true:Boolean]+ Projection: CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END, orders.o_custkey, __always_true [CASE WHEN max(orders.o_totalprice) THEN Utf8("a") ELSE Utf8("b") END:Utf8, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_totalprice)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_totalprice):Float64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "#+ )}/// Test for correlated scalar subquery multiple projected columns@@ -875,21 +873,19 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey >= __scalar_sq_1.max(orders.o_custkey) AND customer.c_custkey = Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey >= __scalar_sq_1.max(orders.o_custkey) AND customer.c_custkey = Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}#[test]@@ -914,21 +910,19 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) AND customer.c_custkey = Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) AND customer.c_custkey = Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test for correlated scalar subquery filter with disjunctions@@ -954,21 +948,19 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) OR customer.c_custkey = Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) OR customer.c_custkey = Int32(1) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}/// Test for correlated scalar subquery filter@@ -987,21 +979,19 @@ mod tests {.project(vec![col("test.c")])?.build()?;- let expected = "Projection: test.c [c:UInt32]\- \n Filter: test.c < __scalar_sq_1.min(sq.c) [a:UInt32, b:UInt32, c:UInt32, min(sq.c):UInt32;N, a:UInt32;N, __always_true:Boolean;N]\- \n Left Join: Filter: test.a = __scalar_sq_1.a [a:UInt32, b:UInt32, c:UInt32, min(sq.c):UInt32;N, a:UInt32;N, __always_true:Boolean;N]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]\- \n SubqueryAlias: __scalar_sq_1 [min(sq.c):UInt32;N, a:UInt32, __always_true:Boolean]\- \n Projection: min(sq.c), sq.a, __always_true [min(sq.c):UInt32;N, a:UInt32, __always_true:Boolean]\- \n Aggregate: groupBy=[[sq.a, Boolean(true) AS __always_true]], aggr=[[min(sq.c)]] [a:UInt32, __always_true:Boolean, min(sq.c):UInt32;N]\- \n TableScan: sq [a:UInt32, b:UInt32, c:UInt32]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: test.c [c:UInt32]+ Filter: test.c < __scalar_sq_1.min(sq.c) [a:UInt32, b:UInt32, c:UInt32, min(sq.c):UInt32;N, a:UInt32;N, __always_true:Boolean;N]+ Left Join: Filter: test.a = __scalar_sq_1.a [a:UInt32, b:UInt32, c:UInt32, min(sq.c):UInt32;N, a:UInt32;N, __always_true:Boolean;N]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ SubqueryAlias: __scalar_sq_1 [min(sq.c):UInt32;N, a:UInt32, __always_true:Boolean]+ Projection: min(sq.c), sq.a, __always_true [min(sq.c):UInt32;N, a:UInt32, __always_true:Boolean]+ Aggregate: groupBy=[[sq.a, Boolean(true) AS __always_true]], aggr=[[min(sq.c)]] [a:UInt32, __always_true:Boolean, min(sq.c):UInt32;N]+ TableScan: sq [a:UInt32, b:UInt32, c:UInt32]+ "+ )}/// Test for non-correlated scalar subquery with no filters@@ -1019,21 +1009,19 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey < __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey < __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}#[test]@@ -1050,21 +1038,19 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey = __scalar_sq_1.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, max(orders.o_custkey):Int64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}#[test]@@ -1102,26 +1088,24 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey BETWEEN __scalar_sq_1.min(orders.o_custkey) AND __scalar_sq_2.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_2.o_custkey [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [min(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: min(orders.o_custkey), orders.o_custkey, __always_true [min(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[min(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, min(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n SubqueryAlias: __scalar_sq_2 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]\- \n Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey BETWEEN __scalar_sq_1.min(orders.o_custkey) AND __scalar_sq_2.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_2.o_custkey [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N, max(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ Left Join: Filter: customer.c_custkey = __scalar_sq_1.o_custkey [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, o_custkey:Int64;N, __always_true:Boolean;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [min(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: min(orders.o_custkey), orders.o_custkey, __always_true [min(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[min(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, min(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ SubqueryAlias: __scalar_sq_2 [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Projection: max(orders.o_custkey), orders.o_custkey, __always_true [max(orders.o_custkey):Int64;N, o_custkey:Int64, __always_true:Boolean]+ Aggregate: groupBy=[[orders.o_custkey, Boolean(true) AS __always_true]], aggr=[[max(orders.o_custkey)]] [o_custkey:Int64, __always_true:Boolean, max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}#[test]@@ -1151,25 +1135,23 @@ mod tests {.project(vec![col("customer.c_custkey")])?.build()?;- let expected = "Projection: customer.c_custkey [c_custkey:Int64]\- \n Filter: customer.c_custkey BETWEEN __scalar_sq_1.min(orders.o_custkey) AND __scalar_sq_2.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, max(orders.o_custkey):Int64;N]\- \n Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, max(orders.o_custkey):Int64;N]\- \n Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N]\- \n TableScan: customer [c_custkey:Int64, c_name:Utf8]\- \n SubqueryAlias: __scalar_sq_1 [min(orders.o_custkey):Int64;N]\- \n Projection: min(orders.o_custkey) [min(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[min(orders.o_custkey)]] [min(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]\- \n SubqueryAlias: __scalar_sq_2 [max(orders.o_custkey):Int64;N]\- \n Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]\- \n Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]\- \n TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]";-- assert_multi_rules_optimized_plan_eq_display_indent(- vec![Arc::new(ScalarSubqueryToJoin::new())],+ assert_optimized_plan_equal!(plan,- expected,- );- Ok(())+ @r"+ Projection: customer.c_custkey [c_custkey:Int64]+ Filter: customer.c_custkey BETWEEN __scalar_sq_1.min(orders.o_custkey) AND __scalar_sq_2.max(orders.o_custkey) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, max(orders.o_custkey):Int64;N]+ Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N, max(orders.o_custkey):Int64;N]+ Left Join: Filter: Boolean(true) [c_custkey:Int64, c_name:Utf8, min(orders.o_custkey):Int64;N]+ TableScan: customer [c_custkey:Int64, c_name:Utf8]+ SubqueryAlias: __scalar_sq_1 [min(orders.o_custkey):Int64;N]+ Projection: min(orders.o_custkey) [min(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[min(orders.o_custkey)]] [min(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ SubqueryAlias: __scalar_sq_2 [max(orders.o_custkey):Int64;N]+ Projection: max(orders.o_custkey) [max(orders.o_custkey):Int64;N]+ Aggregate: groupBy=[[]], aggr=[[max(orders.o_custkey)]] [max(orders.o_custkey):Int64;N]+ TableScan: orders [o_orderkey:Int64, o_custkey:Int64, o_orderstatus:Utf8, o_totalprice:Float64;N]+ "+ )}}diff --git a/datafusion/optimizer/src/single_distinct_to_groupby.rs b/datafusion/optimizer/src/single_distinct_to_groupby.rsindex 7337d2ffce..acafc7d922 100644--- a/datafusion/optimizer/src/single_distinct_to_groupby.rs+++ b/datafusion/optimizer/src/single_distinct_to_groupby.rs@@ -280,6 +280,7 @@ impl OptimizerRule for SingleDistinctToGroupBy {#[cfg(test)]mod tests {use super::*;+ use crate::assert_optimized_plan_eq_display_indent_snapshot;use crate::test::*;use datafusion_expr::expr::GroupingSet;use datafusion_expr::ExprFunctionExt;@@ -300,13 +301,18 @@ mod tests {))}- fn assert_optimized_plan_equal(plan: LogicalPlan, expected: &str) -> Result<()> {- assert_optimized_plan_eq_display_indent(- Arc::new(SingleDistinctToGroupBy::new()),- plan,- expected,- );- Ok(())+ macro_rules! assert_optimized_plan_equal {+ (+ $plan:expr,+ @ $expected:literal $(,)?+ ) => {{+ let rule: Arc<dyn crate::OptimizerRule + Send + Sync> = Arc::new(SingleDistinctToGroupBy::new());+ assert_optimized_plan_eq_display_indent_snapshot!(+ rule,+ $plan,+ @ $expected,+ )+ }};}#[test]@@ -318,11 +324,13 @@ mod tests {.build()?;// Do nothing- let expected =- "Aggregate: groupBy=[[]], aggr=[[max(test.b)]] [max(test.b):UInt32;N]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[]], aggr=[[max(test.b)]] [max(test.b):UInt32;N]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -334,12 +342,15 @@ mod tests {.build()?;// Should work- let expected = "Projection: count(alias1) AS count(DISTINCT test.b) [count(DISTINCT test.b):Int64]\- \n Aggregate: groupBy=[[]], aggr=[[count(alias1)]] [count(alias1):Int64]\- \n Aggregate: groupBy=[[test.b AS alias1]], aggr=[[]] [alias1:UInt32]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: count(alias1) AS count(DISTINCT test.b) [count(DISTINCT test.b):Int64]+ Aggregate: groupBy=[[]], aggr=[[count(alias1)]] [count(alias1):Int64]+ Aggregate: groupBy=[[test.b AS alias1]], aggr=[[]] [alias1:UInt32]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}// Currently this optimization is disabled for CUBE/ROLLUP/GROUPING SET@@ -357,10 +368,13 @@ mod tests {.build()?;// Should not be optimized- let expected = "Aggregate: groupBy=[[GROUPING SETS ((test.a), (test.b))]], aggr=[[count(DISTINCT test.c)]] [a:UInt32;N, b:UInt32;N, __grouping_id:UInt8, count(DISTINCT test.c):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[GROUPING SETS ((test.a), (test.b))]], aggr=[[count(DISTINCT test.c)]] [a:UInt32;N, b:UInt32;N, __grouping_id:UInt8, count(DISTINCT test.c):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}// Currently this optimization is disabled for CUBE/ROLLUP/GROUPING SET@@ -375,10 +389,13 @@ mod tests {.build()?;// Should not be optimized- let expected = "Aggregate: groupBy=[[CUBE (test.a, test.b)]], aggr=[[count(DISTINCT test.c)]] [a:UInt32;N, b:UInt32;N, __grouping_id:UInt8, count(DISTINCT test.c):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[CUBE (test.a, test.b)]], aggr=[[count(DISTINCT test.c)]] [a:UInt32;N, b:UInt32;N, __grouping_id:UInt8, count(DISTINCT test.c):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}// Currently this optimization is disabled for CUBE/ROLLUP/GROUPING SET@@ -394,10 +411,13 @@ mod tests {.build()?;// Should not be optimized- let expected = "Aggregate: groupBy=[[ROLLUP (test.a, test.b)]], aggr=[[count(DISTINCT test.c)]] [a:UInt32;N, b:UInt32;N, __grouping_id:UInt8, count(DISTINCT test.c):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[ROLLUP (test.a, test.b)]], aggr=[[count(DISTINCT test.c)]] [a:UInt32;N, b:UInt32;N, __grouping_id:UInt8, count(DISTINCT test.c):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -408,12 +428,15 @@ mod tests {.aggregate(Vec::<Expr>::new(), vec![count_distinct(lit(2) * col("b"))])?.build()?;- let expected = "Projection: count(alias1) AS count(DISTINCT Int32(2) * test.b) [count(DISTINCT Int32(2) * test.b):Int64]\- \n Aggregate: groupBy=[[]], aggr=[[count(alias1)]] [count(alias1):Int64]\- \n Aggregate: groupBy=[[Int32(2) * test.b AS alias1]], aggr=[[]] [alias1:Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: count(alias1) AS count(DISTINCT Int32(2) * test.b) [count(DISTINCT Int32(2) * test.b):Int64]+ Aggregate: groupBy=[[]], aggr=[[count(alias1)]] [count(alias1):Int64]+ Aggregate: groupBy=[[Int32(2) * test.b AS alias1]], aggr=[[]] [alias1:Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -425,12 +448,15 @@ mod tests {.build()?;// Should work- let expected = "Projection: test.a, count(alias1) AS count(DISTINCT test.b) [a:UInt32, count(DISTINCT test.b):Int64]\- \n Aggregate: groupBy=[[test.a]], aggr=[[count(alias1)]] [a:UInt32, count(alias1):Int64]\- \n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[]] [a:UInt32, alias1:UInt32]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: test.a, count(alias1) AS count(DISTINCT test.b) [a:UInt32, count(DISTINCT test.b):Int64]+ Aggregate: groupBy=[[test.a]], aggr=[[count(alias1)]] [a:UInt32, count(alias1):Int64]+ Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[]] [a:UInt32, alias1:UInt32]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -445,10 +471,13 @@ mod tests {.build()?;// Do nothing- let expected = "Aggregate: groupBy=[[test.a]], aggr=[[count(DISTINCT test.b), count(DISTINCT test.c)]] [a:UInt32, count(DISTINCT test.b):Int64, count(DISTINCT test.c):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.a]], aggr=[[count(DISTINCT test.b), count(DISTINCT test.c)]] [a:UInt32, count(DISTINCT test.b):Int64, count(DISTINCT test.c):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -461,13 +490,17 @@ mod tests {vec![count_distinct(col("b")), max_distinct(col("b"))],)?.build()?;- // Should work- let expected = "Projection: test.a, count(alias1) AS count(DISTINCT test.b), max(alias1) AS max(DISTINCT test.b) [a:UInt32, count(DISTINCT test.b):Int64, max(DISTINCT test.b):UInt32;N]\- \n Aggregate: groupBy=[[test.a]], aggr=[[count(alias1), max(alias1)]] [a:UInt32, count(alias1):Int64, max(alias1):UInt32;N]\- \n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[]] [a:UInt32, alias1:UInt32]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Should work+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: test.a, count(alias1) AS count(DISTINCT test.b), max(alias1) AS max(DISTINCT test.b) [a:UInt32, count(DISTINCT test.b):Int64, max(DISTINCT test.b):UInt32;N]+ Aggregate: groupBy=[[test.a]], aggr=[[count(alias1), max(alias1)]] [a:UInt32, count(alias1):Int64, max(alias1):UInt32;N]+ Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[]] [a:UInt32, alias1:UInt32]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -482,10 +515,13 @@ mod tests {.build()?;// Do nothing- let expected = "Aggregate: groupBy=[[test.a]], aggr=[[count(DISTINCT test.b), count(test.c)]] [a:UInt32, count(DISTINCT test.b):Int64, count(test.c):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.a]], aggr=[[count(DISTINCT test.b), count(test.c)]] [a:UInt32, count(DISTINCT test.b):Int64, count(test.c):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -497,12 +533,15 @@ mod tests {.build()?;// Should work- let expected = "Projection: group_alias_0 AS test.a + Int32(1), count(alias1) AS count(DISTINCT test.c) [test.a + Int32(1):Int64, count(DISTINCT test.c):Int64]\- \n Aggregate: groupBy=[[group_alias_0]], aggr=[[count(alias1)]] [group_alias_0:Int64, count(alias1):Int64]\- \n Aggregate: groupBy=[[test.a + Int32(1) AS group_alias_0, test.c AS alias1]], aggr=[[]] [group_alias_0:Int64, alias1:UInt32]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";-- assert_optimized_plan_equal(plan, expected)+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: group_alias_0 AS test.a + Int32(1), count(alias1) AS count(DISTINCT test.c) [test.a + Int32(1):Int64, count(DISTINCT test.c):Int64]+ Aggregate: groupBy=[[group_alias_0]], aggr=[[count(alias1)]] [group_alias_0:Int64, count(alias1):Int64]+ Aggregate: groupBy=[[test.a + Int32(1) AS group_alias_0, test.c AS alias1]], aggr=[[]] [group_alias_0:Int64, alias1:UInt32]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -519,13 +558,17 @@ mod tests {],)?.build()?;- // Should work- let expected = "Projection: test.a, sum(alias2) AS sum(test.c), count(alias1) AS count(DISTINCT test.b), max(alias1) AS max(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, count(DISTINCT test.b):Int64, max(DISTINCT test.b):UInt32;N]\- \n Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), count(alias1), max(alias1)]] [a:UInt32, sum(alias2):UInt64;N, count(alias1):Int64, max(alias1):UInt32;N]\- \n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2]] [a:UInt32, alias1:UInt32, alias2:UInt64;N]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Should work+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: test.a, sum(alias2) AS sum(test.c), count(alias1) AS count(DISTINCT test.b), max(alias1) AS max(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, count(DISTINCT test.b):Int64, max(DISTINCT test.b):UInt32;N]+ Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), count(alias1), max(alias1)]] [a:UInt32, sum(alias2):UInt64;N, count(alias1):Int64, max(alias1):UInt32;N]+ Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2]] [a:UInt32, alias1:UInt32, alias2:UInt64;N]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -538,13 +581,17 @@ mod tests {vec![sum(col("c")), max(col("c")), count_distinct(col("b"))],)?.build()?;- // Should work- let expected = "Projection: test.a, sum(alias2) AS sum(test.c), max(alias3) AS max(test.c), count(alias1) AS count(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, max(test.c):UInt32;N, count(DISTINCT test.b):Int64]\- \n Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), max(alias3), count(alias1)]] [a:UInt32, sum(alias2):UInt64;N, max(alias3):UInt32;N, count(alias1):Int64]\- \n Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2, max(test.c) AS alias3]] [a:UInt32, alias1:UInt32, alias2:UInt64;N, alias3:UInt32;N]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Should work+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: test.a, sum(alias2) AS sum(test.c), max(alias3) AS max(test.c), count(alias1) AS count(DISTINCT test.b) [a:UInt32, sum(test.c):UInt64;N, max(test.c):UInt32;N, count(DISTINCT test.b):Int64]+ Aggregate: groupBy=[[test.a]], aggr=[[sum(alias2), max(alias3), count(alias1)]] [a:UInt32, sum(alias2):UInt64;N, max(alias3):UInt32;N, count(alias1):Int64]+ Aggregate: groupBy=[[test.a, test.b AS alias1]], aggr=[[sum(test.c) AS alias2, max(test.c) AS alias3]] [a:UInt32, alias1:UInt32, alias2:UInt64;N, alias3:UInt32;N]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -557,13 +604,17 @@ mod tests {vec![min(col("a")), count_distinct(col("b"))],)?.build()?;- // Should work- let expected = "Projection: test.c, min(alias2) AS min(test.a), count(alias1) AS count(DISTINCT test.b) [c:UInt32, min(test.a):UInt32;N, count(DISTINCT test.b):Int64]\- \n Aggregate: groupBy=[[test.c]], aggr=[[min(alias2), count(alias1)]] [c:UInt32, min(alias2):UInt32;N, count(alias1):Int64]\- \n Aggregate: groupBy=[[test.c, test.b AS alias1]], aggr=[[min(test.a) AS alias2]] [c:UInt32, alias1:UInt32, alias2:UInt32;N]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Should work+ assert_optimized_plan_equal!(+ plan,+ @r"+ Projection: test.c, min(alias2) AS min(test.a), count(alias1) AS count(DISTINCT test.b) [c:UInt32, min(test.a):UInt32;N, count(DISTINCT test.b):Int64]+ Aggregate: groupBy=[[test.c]], aggr=[[min(alias2), count(alias1)]] [c:UInt32, min(alias2):UInt32;N, count(alias1):Int64]+ Aggregate: groupBy=[[test.c, test.b AS alias1]], aggr=[[min(test.a) AS alias2]] [c:UInt32, alias1:UInt32, alias2:UInt32;N]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -582,11 +633,15 @@ mod tests {let plan = LogicalPlanBuilder::from(table_scan).aggregate(vec![col("c")], vec![expr, count_distinct(col("b"))])?.build()?;- // Do nothing- let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a) FILTER (WHERE test.a > Int32(5)), count(DISTINCT test.b)]] [c:UInt32, sum(test.a) FILTER (WHERE test.a > Int32(5)):UInt64;N, count(DISTINCT test.b):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Do nothing+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a) FILTER (WHERE test.a > Int32(5)), count(DISTINCT test.b)]] [c:UInt32, sum(test.a) FILTER (WHERE test.a > Int32(5)):UInt64;N, count(DISTINCT test.b):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -602,11 +657,15 @@ mod tests {let plan = LogicalPlanBuilder::from(table_scan).aggregate(vec![col("c")], vec![sum(col("a")), expr])?.build()?;- // Do nothing- let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a), count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5))]] [c:UInt32, sum(test.a):UInt64;N, count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5)):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Do nothing+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a), count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5))]] [c:UInt32, sum(test.a):UInt64;N, count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5)):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -625,11 +684,15 @@ mod tests {let plan = LogicalPlanBuilder::from(table_scan).aggregate(vec![col("c")], vec![expr, count_distinct(col("b"))])?.build()?;- // Do nothing- let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a) ORDER BY [test.a ASC NULLS LAST], count(DISTINCT test.b)]] [c:UInt32, sum(test.a) ORDER BY [test.a ASC NULLS LAST]:UInt64;N, count(DISTINCT test.b):Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Do nothing+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a) ORDER BY [test.a ASC NULLS LAST], count(DISTINCT test.b)]] [c:UInt32, sum(test.a) ORDER BY [test.a ASC NULLS LAST]:UInt64;N, count(DISTINCT test.b):Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -645,11 +708,15 @@ mod tests {let plan = LogicalPlanBuilder::from(table_scan).aggregate(vec![col("c")], vec![sum(col("a")), expr])?.build()?;- // Do nothing- let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a), count(DISTINCT test.a) ORDER BY [test.a ASC NULLS LAST]]] [c:UInt32, sum(test.a):UInt64;N, count(DISTINCT test.a) ORDER BY [test.a ASC NULLS LAST]:Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Do nothing+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a), count(DISTINCT test.a) ORDER BY [test.a ASC NULLS LAST]]] [c:UInt32, sum(test.a):UInt64;N, count(DISTINCT test.a) ORDER BY [test.a ASC NULLS LAST]:Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}#[test]@@ -666,10 +733,14 @@ mod tests {let plan = LogicalPlanBuilder::from(table_scan).aggregate(vec![col("c")], vec![sum(col("a")), expr])?.build()?;- // Do nothing- let expected = "Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a), count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5)) ORDER BY [test.a ASC NULLS LAST]]] [c:UInt32, sum(test.a):UInt64;N, count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5)) ORDER BY [test.a ASC NULLS LAST]:Int64]\- \n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";- assert_optimized_plan_equal(plan, expected)+ // Do nothing+ assert_optimized_plan_equal!(+ plan,+ @r"+ Aggregate: groupBy=[[test.c]], aggr=[[sum(test.a), count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5)) ORDER BY [test.a ASC NULLS LAST]]] [c:UInt32, sum(test.a):UInt64;N, count(DISTINCT test.a) FILTER (WHERE test.a > Int32(5)) ORDER BY [test.a ASC NULLS LAST]:Int64]+ TableScan: test [a:UInt32, b:UInt32, c:UInt32]+ "+ )}}diff --git a/datafusion/optimizer/src/test/mod.rs b/datafusion/optimizer/src/test/mod.rsindex 4d89a35fc1..5193746021 100644--- a/datafusion/optimizer/src/test/mod.rs+++ b/datafusion/optimizer/src/test/mod.rs@@ -21,7 +21,7 @@ use crate::{OptimizerContext, OptimizerRule};use arrow::datatypes::{DataType, Field, Schema};use datafusion_common::config::ConfigOptions;use datafusion_common::{assert_contains, Result};-use datafusion_expr::{col, logical_plan::table_scan, LogicalPlan, LogicalPlanBuilder};+use datafusion_expr::{logical_plan::table_scan, LogicalPlan, LogicalPlanBuilder};use std::sync::Arc;pub mod user_defined;@@ -64,15 +64,6 @@ pub fn assert_fields_eq(plan: &LogicalPlan, expected: Vec<&str>) {assert_eq!(actual, expected);}-pub fn test_subquery_with_name(name: &str) -> Result<Arc<LogicalPlan>> {- let table_scan = test_table_scan_with_name(name)?;- Ok(Arc::new(- LogicalPlanBuilder::from(table_scan)- .project(vec![col("c")])?- .build()?,- ))-}-pub fn scan_tpch_table(table: &str) -> LogicalPlan {let schema = Arc::new(get_tpch_table_schema(table));table_scan(Some(table), &schema, None)@@ -133,20 +124,6 @@ pub fn assert_analyzed_plan_with_config_eq(Ok(())}-pub fn assert_analyzed_plan_eq_display_indent(- rule: Arc<dyn AnalyzerRule + Send + Sync>,- plan: LogicalPlan,- expected: &str,-) -> Result<()> {- let options = ConfigOptions::default();- let analyzed_plan =- Analyzer::with_rules(vec![rule]).execute_and_check(plan, &options, |_, _| {})?;- let formatted_plan = analyzed_plan.display_indent_schema().to_string();- assert_eq!(formatted_plan, expected);-- Ok(())-}-pub fn assert_analyzer_check_err(rules: Vec<Arc<dyn AnalyzerRule + Send + Sync>>,plan: LogicalPlan,@@ -187,7 +164,6 @@ fn generate_optimized_plan_with_rules(rules: Vec<Arc<dyn OptimizerRule + Send + Sync>>,plan: LogicalPlan,) -> LogicalPlan {- fn observe(_plan: &LogicalPlan, _rule: &dyn OptimizerRule) {}let config = &mut OptimizerContext::new().with_max_passes(1).with_skip_failing_rules(false);@@ -213,19 +189,6 @@ pub fn assert_optimized_plan_with_rules(Ok(())}-pub fn assert_optimized_plan_eq_display_indent(- rule: Arc<dyn OptimizerRule + Send + Sync>,- plan: LogicalPlan,- expected: &str,-) {- let optimizer = Optimizer::with_rules(vec![rule]);- let optimized_plan = optimizer- .optimize(plan, &OptimizerContext::new(), observe)- .expect("failed to optimize plan");- let formatted_plan = optimized_plan.display_indent_schema().to_string();- assert_eq!(formatted_plan, expected);-}-#[macro_export]macro_rules! assert_optimized_plan_eq_display_indent_snapshot {(@@ -243,48 +206,3 @@ macro_rules! assert_optimized_plan_eq_display_indent_snapshot {Ok::<(), datafusion_common::DataFusionError>(())}};}--pub fn assert_multi_rules_optimized_plan_eq_display_indent(- rules: Vec<Arc<dyn OptimizerRule + Send + Sync>>,- plan: LogicalPlan,- expected: &str,-) {- let optimizer = Optimizer::with_rules(rules);- let optimized_plan = optimizer- .optimize(plan, &OptimizerContext::new(), observe)- .expect("failed to optimize plan");- let formatted_plan = optimized_plan.display_indent_schema().to_string();- assert_eq!(formatted_plan, expected);-}--pub fn assert_optimizer_err(- rule: Arc<dyn OptimizerRule + Send + Sync>,- plan: LogicalPlan,- expected: &str,-) {- let optimizer = Optimizer::with_rules(vec![rule]);- let res = optimizer.optimize(plan, &OptimizerContext::new(), observe);- match res {- Ok(plan) => assert_eq!(format!("{}", plan.display_indent()), "An error"),- Err(ref e) => {- let actual = format!("{e}");- if expected.is_empty() || !actual.contains(expected) {- assert_eq!(actual, expected)- }- }- }-}--pub fn assert_optimization_skipped(- rule: Arc<dyn OptimizerRule + Send + Sync>,- plan: LogicalPlan,-) -> Result<()> {- let optimizer = Optimizer::with_rules(vec![rule]);- let new_plan = optimizer.optimize(plan.clone(), &OptimizerContext::new(), observe)?;-- assert_eq!(- format!("{}", plan.display_indent()),- format!("{}", new_plan.display_indent())- );- Ok(())-}