Skip to content

Commit 2bd1669

Browse files
committed
refactor(cubesql): Refactor FilterPushDown tests
1 parent 85c27a9 commit 2bd1669

7 files changed

+70
-69
lines changed

rust/cubesql/cubesql/src/compile/engine/df/optimizers/filter_push_down.rs

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,10 @@ mod tests {
692692
};
693693
use datafusion::logical_plan::{binary_expr, col, count, lit, sum, LogicalPlanBuilder};
694694

695-
fn optimize(plan: &LogicalPlan) -> Result<LogicalPlan> {
695+
fn optimize(plan: &LogicalPlan) -> LogicalPlan {
696696
let rule = FilterPushDown::new();
697697
rule.optimize(plan, &OptimizerConfig::new())
698-
}
699-
700-
fn assert_optimized_plan_eq(plan: LogicalPlan, expected: &str) {
701-
let optimized_plan = optimize(&plan).expect("failed to optimize plan");
702-
let formatted_plan = format!("{:?}", optimized_plan);
703-
assert_eq!(formatted_plan, expected);
698+
.expect("failed to optimize plan")
704699
}
705700

706701
#[test]
@@ -714,14 +709,7 @@ mod tests {
714709
.filter(col("t2.n2").gt(lit(5i32)))?
715710
.build()?;
716711

717-
let expected = "\
718-
Projection: #t1.c1 AS n1, #t1.c3 AS n2, alias=t2\
719-
\n Filter: #t1.c3 > Int32(5)\
720-
\n Projection: #t1.c1, #t1.c3\
721-
\n TableScan: t1 projection=None\
722-
";
723-
724-
assert_optimized_plan_eq(plan, expected);
712+
insta::assert_debug_snapshot!(optimize(&plan));
725713
Ok(())
726714
}
727715

@@ -752,17 +740,7 @@ mod tests {
752740
.project(vec![col("c7"), col("c5"), col("c9")])?
753741
.build()?;
754742

755-
let expected = "\
756-
Projection: #t3.c7, #t3.c5, #c9\
757-
\n Projection: #t3.c7, #t3.c5, #t3.c8 AS c9\
758-
\n Projection: #t2.c4 AS c7, #t2.c5, #t2.c6 AS c8, alias=t3\
759-
\n Projection: #t1.c1 AS c4, #t1.c2 AS c5, #t1.c3 AS c6, alias=t2\
760-
\n Filter: #t1.c2 > Int32(5) AND #t1.c2 <= Int32(10) AND #t1.c3 = Int32(0) AND NOT #t1.c1 < Int32(0)\
761-
\n Projection: #t1.c1, #t1.c2, #t1.c3\
762-
\n TableScan: t1 projection=None\
763-
";
764-
765-
assert_optimized_plan_eq(plan, expected);
743+
insta::assert_debug_snapshot!(optimize(&plan));
766744
Ok(())
767745
}
768746

@@ -782,18 +760,7 @@ mod tests {
782760
.project(vec![col("c1"), col("c2"), col("c3")])?
783761
.build()?;
784762

785-
let expected = "\
786-
Projection: #t1.c1, #c2, #t1.c3\
787-
\n Filter: #t1.c1 > #t1.c3\
788-
\n Projection: #t1.c1, #c2, #t1.c3\
789-
\n Filter: #c2 = Int32(5)\
790-
\n Projection: #t1.c1, #t1.c2 + Int32(5) AS c2, #t1.c3\
791-
\n Filter: #t1.c3 < Int32(5)\
792-
\n Projection: #t1.c1, #t1.c2, #t1.c3\
793-
\n TableScan: t1 projection=None\
794-
";
795-
796-
assert_optimized_plan_eq(plan, expected);
763+
insta::assert_debug_snapshot!(optimize(&plan));
797764
Ok(())
798765
}
799766

@@ -847,16 +814,7 @@ mod tests {
847814
.filter(col("c3").eq(lit(0i32)))?
848815
.build()?;
849816

850-
let expected = "\
851-
Projection: #t1.c1, #SUM(t1.c2) AS c2_sum, #t1.c3\
852-
\n Filter: #SUM(t1.c2) > Int32(10)\
853-
\n Aggregate: groupBy=[[#t1.c1, #t1.c3]], aggr=[[SUM(#t1.c2)]]\
854-
\n Filter: #t1.c3 = Int32(0)\
855-
\n Projection: #t1.c1, #t1.c2, #t1.c3\
856-
\n TableScan: t1 projection=None\
857-
";
858-
859-
assert_optimized_plan_eq(plan, expected);
817+
insta::assert_debug_snapshot!(optimize(&plan));
860818
Ok(())
861819
}
862820

@@ -897,14 +855,7 @@ mod tests {
897855
.filter(col("c3").eq(lit(5i32)))?
898856
.build()?;
899857

900-
let expected = "\
901-
Sort: #t1.c2\
902-
\n Filter: #t1.c3 = Int32(5)\
903-
\n Projection: #t1.c1, #t1.c2, #t1.c3\
904-
\n TableScan: t1 projection=None\
905-
";
906-
907-
assert_optimized_plan_eq(plan, expected);
858+
insta::assert_debug_snapshot!(optimize(&plan));
908859
Ok(())
909860
}
910861

@@ -998,19 +949,7 @@ mod tests {
998949
.filter(col("c2").eq(lit(10i32)))?
999950
.build()?;
1000951

1001-
let expected = "\
1002-
Filter: #j2.c2 = Int32(10)\
1003-
\n CrossJoin:\
1004-
\n Filter: #j1.c1 = Int32(5)\
1005-
\n Projection: #j1.c1\
1006-
\n TableScan: j1 projection=None\
1007-
\n Projection: #COUNT(UInt8(1)) AS c2, alias=j2\
1008-
\n Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]\
1009-
\n Projection: #j2.c2\
1010-
\n TableScan: j2 projection=None\
1011-
";
1012-
1013-
assert_optimized_plan_eq(plan, expected);
952+
insta::assert_debug_snapshot!(optimize(&plan));
1014953
Ok(())
1015954
}
1016955

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
source: cubesql/src/compile/engine/df/optimizers/filter_push_down.rs
3+
expression: optimize(&plan)
4+
---
5+
Filter: #j2.c2 = Int32(10)
6+
CrossJoin:
7+
Filter: #j1.c1 = Int32(5)
8+
Projection: #j1.c1
9+
TableScan: j1 projection=None
10+
Projection: #COUNT(UInt8(1)) AS c2, alias=j2
11+
Aggregate: groupBy=[[]], aggr=[[COUNT(UInt8(1))]]
12+
Projection: #j2.c2
13+
TableScan: j2 projection=None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: cubesql/src/compile/engine/df/optimizers/filter_push_down.rs
3+
expression: optimize(&plan)
4+
---
5+
Projection: #t1.c1 AS n1, #t1.c3 AS n2, alias=t2
6+
Filter: #t1.c3 > Int32(5)
7+
Projection: #t1.c1, #t1.c3
8+
TableScan: t1 projection=None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
source: cubesql/src/compile/engine/df/optimizers/filter_push_down.rs
3+
expression: optimize(&plan)
4+
---
5+
Sort: #t1.c2
6+
Filter: #t1.c3 = Int32(5)
7+
Projection: #t1.c1, #t1.c2, #t1.c3
8+
TableScan: t1 projection=None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: cubesql/src/compile/engine/df/optimizers/filter_push_down.rs
3+
expression: optimize(&plan)
4+
---
5+
Projection: #t1.c1, #SUM(t1.c2) AS c2_sum, #t1.c3
6+
Filter: #SUM(t1.c2) > Int32(10)
7+
Aggregate: groupBy=[[#t1.c1, #t1.c3]], aggr=[[SUM(#t1.c2)]]
8+
Filter: #t1.c3 = Int32(0)
9+
Projection: #t1.c1, #t1.c2, #t1.c3
10+
TableScan: t1 projection=None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: cubesql/src/compile/engine/df/optimizers/filter_push_down.rs
3+
expression: optimize(&plan)
4+
---
5+
Projection: #t3.c7, #t3.c5, #c9
6+
Projection: #t3.c7, #t3.c5, #t3.c8 AS c9
7+
Projection: #t2.c4 AS c7, #t2.c5, #t2.c6 AS c8, alias=t3
8+
Projection: #t1.c1 AS c4, #t1.c2 AS c5, #t1.c3 AS c6, alias=t2
9+
Filter: #t1.c2 > Int32(5) AND #t1.c2 <= Int32(10) AND #t1.c3 = Int32(0) AND NOT #t1.c1 < Int32(0)
10+
Projection: #t1.c1, #t1.c2, #t1.c3
11+
TableScan: t1 projection=None
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: cubesql/src/compile/engine/df/optimizers/filter_push_down.rs
3+
expression: optimize(&plan)
4+
---
5+
Projection: #t1.c1, #c2, #t1.c3
6+
Filter: #t1.c1 > #t1.c3
7+
Projection: #t1.c1, #c2, #t1.c3
8+
Filter: #c2 = Int32(5)
9+
Projection: #t1.c1, #t1.c2 + Int32(5) AS c2, #t1.c3
10+
Filter: #t1.c3 < Int32(5)
11+
Projection: #t1.c1, #t1.c2, #t1.c3
12+
TableScan: t1 projection=None

0 commit comments

Comments
 (0)