From 30ba1d171c381db3e4c66d9e1c3befc1ce6b4bc1 Mon Sep 17 00:00:00 2001 From: universalmind303 Date: Sun, 27 Oct 2024 15:51:28 -0500 Subject: [PATCH] fix eliminatecrossjoin tests --- .../rules/eliminate_cross_join.rs | 218 ++++++++---------- 1 file changed, 95 insertions(+), 123 deletions(-) diff --git a/src/daft-plan/src/logical_optimization/rules/eliminate_cross_join.rs b/src/daft-plan/src/logical_optimization/rules/eliminate_cross_join.rs index cc5ea4646f..83c82f5e58 100644 --- a/src/daft-plan/src/logical_optimization/rules/eliminate_cross_join.rs +++ b/src/daft-plan/src/logical_optimization/rules/eliminate_cross_join.rs @@ -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!( @@ -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); @@ -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); @@ -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); @@ -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); @@ -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);