Skip to content

Commit

Permalink
fix eliminatecrossjoin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
universalmind303 committed Oct 27, 2024
1 parent e9e009f commit 30ba1d1
Showing 1 changed file with 95 additions and 123 deletions.
218 changes: 95 additions & 123 deletions src/daft-plan/src/logical_optimization/rules/eliminate_cross_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ mod tests {
let transformed_plan = rule.try_optimize(plan).unwrap();
assert!(transformed_plan.transformed, "failed to optimize plan");
let optimized_plan = transformed_plan.data;
let formatted = optimized_plan.repr_ascii(false);
let formatted = optimized_plan.repr_indent();

let actual: Vec<&str> = formatted.trim().lines().collect();
assert_eq!(
Expand All @@ -511,23 +511,20 @@ mod tests {
.build();

let expected = vec![
"* Join: Type = Inner",
"| Strategy = Auto",
"| Left on = col(a), col(b)",
"| Right on = col(right.a), col(right.b)",
"| Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
"|\\",
"| * Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
"| |",
"| * PlaceHolder:",
"| | Source ID = 0",
"| | Num partitions = 0",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32",
"|",
"* PlaceHolder:",
"| Source ID = 0",
"| Num partitions = 0",
"| Output schema = a#UInt32, b#UInt32, c#UInt32",
"Join: Type = Inner",
"Strategy = Auto",
"Left on = col(a), col(b)",
"Right on = col(right.a), col(right.b)",
"Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
];

assert_optimized_plan_eq(plan, expected);
Expand All @@ -545,23 +542,19 @@ mod tests {
.build();

let expected = vec![
"* Filter: [col(a) == col(right.a)] | [col(right.b) == col(a)]",
"|",
"* Join: Type = Inner",
"| Strategy = Auto",
"| Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
"|\\",
"| * Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
"| |",
"| * PlaceHolder:",
"| | Source ID = 0",
"| | Num partitions = 0",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32",
"|",
"* PlaceHolder:",
"| Source ID = 0",
"| Num partitions = 0",
"| Output schema = a#UInt32, b#UInt32, c#UInt32",
"Filter: [col(a) == col(right.a)] | [col(right.b) == col(a)]",
" Join: Type = Inner",
"Strategy = Auto",
"Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
];

assert_optimized_plan_eq(plan, expected);
Expand All @@ -582,25 +575,21 @@ mod tests {
.build();

let expected = vec![
"* Filter: [col(right.c) < lit(20)] & [col(right.c) == lit(10)]",
"|",
"* Join: Type = Inner",
"| Strategy = Auto",
"| Left on = col(a)",
"| Right on = col(right.a)",
"| Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
"|\\",
"| * Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
"| |",
"| * PlaceHolder:",
"| | Source ID = 0",
"| | Num partitions = 0",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32",
"|",
"* PlaceHolder:",
"| Source ID = 0",
"| Num partitions = 0",
"| Output schema = a#UInt32, b#UInt32, c#UInt32",
"Filter: [col(right.c) < lit(20)] & [col(right.c) == lit(10)]",
" Join: Type = Inner",
"Strategy = Auto",
"Left on = col(a)",
"Right on = col(right.a)",
"Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
];

assert_optimized_plan_eq(plan, expected);
Expand All @@ -621,25 +610,21 @@ mod tests {
.build();

let expected = vec![
"* Filter: [col(right.c) < lit(15)] | [col(right.c) == lit(688)]",
"|",
"* Join: Type = Inner",
"| Strategy = Auto",
"| Left on = col(a)",
"| Right on = col(right.a)",
"| Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
"|\\",
"| * Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
"| |",
"| * PlaceHolder:",
"| | Source ID = 0",
"| | Num partitions = 0",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32",
"|",
"* PlaceHolder:",
"| Source ID = 0",
"| Num partitions = 0",
"| Output schema = a#UInt32, b#UInt32, c#UInt32",
"Filter: [col(right.c) < lit(15)] | [col(right.c) == lit(688)]",
" Join: Type = Inner",
"Strategy = Auto",
"Left on = col(a)",
"Right on = col(right.a)",
"Output schema = a#UInt32, b#UInt32, c#UInt32, right.a#UInt32, right.b#UInt32, right.c#UInt32",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as right.a, col(b) as right.b, col(c) as right.c",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
];
assert_optimized_plan_eq(plan, expected);

Expand Down Expand Up @@ -686,56 +671,43 @@ mod tests {
.build();

let expected = vec![
"* Filter: [col(t4.c) < lit(15)] | [col(t4.c) == lit(688)]",
"|",
"* Join: Type = Inner",
"| Strategy = Auto",
"| Left on = col(a)",
"| Right on = col(t3.a)",
"| Output schema = a#UInt32, b#UInt32, c#UInt32, t2.a#UInt32, t2.b#UInt32, t2.c#UInt32, t3.a#UInt32, t3.b#UInt32, t3.c#UInt32, t4.a#UInt32, t4.b#UInt32,",
"| t4.c#UInt32",
"|\\",
"| * Project: col(a) as t3.a, col(b) as t3.b, col(c) as t3.c, col(t4.a), col(t4.b), col(t4.c)",
"| |",
"| * Filter: [[col(t4.c) < lit(15)] | [col(c) == lit(688)]] | [col(b) == col(t4.b)]",
"| |",
"| * Join: Type = Inner",
"| | Strategy = Auto",
"| | Left on = col(a)",
"| | Right on = col(t4.a)",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32, t4.a#UInt32, t4.b#UInt32, t4.c#UInt32",
"| |\\",
"| | * Project: col(a) as t4.a, col(b) as t4.b, col(c) as t4.c",
"| | |",
"| | * PlaceHolder:",
"| | | Source ID = 0",
"| | | Num partitions = 0",
"| | | Output schema = a#UInt32, b#UInt32, c#UInt32",
"| |",
"| * PlaceHolder:",
"| | Source ID = 0",
"| | Num partitions = 0",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32",
"|",
"* Filter: [col(t2.c) < lit(15)] | [col(t2.c) == lit(688)]",
"|",
"* Join: Type = Inner",
"| Strategy = Auto",
"| Left on = col(a)",
"| Right on = col(t2.a)",
"| Output schema = a#UInt32, b#UInt32, c#UInt32, t2.a#UInt32, t2.b#UInt32, t2.c#UInt32",
"|\\",
"| * Project: col(a) as t2.a, col(b) as t2.b, col(c) as t2.c",
"| |",
"| * PlaceHolder:",
"| | Source ID = 0",
"| | Num partitions = 0",
"| | Output schema = a#UInt32, b#UInt32, c#UInt32",
"|",
"* PlaceHolder:",
"| Source ID = 0",
"| Num partitions = 0",
"| Output schema = a#UInt32, b#UInt32, c#UInt32",
"Filter: [col(t4.c) < lit(15)] | [col(t4.c) == lit(688)]",
" Join: Type = Inner",
"Strategy = Auto",
"Left on = col(a)",
"Right on = col(t3.a)",
"Output schema = a#UInt32, b#UInt32, c#UInt32, t2.a#UInt32, t2.b#UInt32, t2.c#UInt32, t3.a#UInt32, t3.b#UInt32, t3.c#UInt32, t4.a#UInt32, t4.b#UInt32, t4.c#UInt32",
" Filter: [col(t2.c) < lit(15)] | [col(t2.c) == lit(688)]",
" Join: Type = Inner",
"Strategy = Auto",
"Left on = col(a)",
"Right on = col(t2.a)",
"Output schema = a#UInt32, b#UInt32, c#UInt32, t2.a#UInt32, t2.b#UInt32, t2.c#UInt32",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as t2.a, col(b) as t2.b, col(c) as t2.c",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as t3.a, col(b) as t3.b, col(c) as t3.c, col(t4.a), col(t4.b), col(t4.c)",
" Filter: [[col(t4.c) < lit(15)] | [col(c) == lit(688)]] | [col(b) == col(t4.b)]",
" Join: Type = Inner",
"Strategy = Auto",
"Left on = col(a)",
"Right on = col(t4.a)",
"Output schema = a#UInt32, b#UInt32, c#UInt32, t4.a#UInt32, t4.b#UInt32, t4.c#UInt32",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
" Project: col(a) as t4.a, col(b) as t4.b, col(c) as t4.c",
" PlaceHolder:",
"Source ID = 0",
"Num partitions = 0",
"Output schema = a#UInt32, b#UInt32, c#UInt32",
];

assert_optimized_plan_eq(plan, expected);
Expand Down

0 comments on commit 30ba1d1

Please sign in to comment.