Skip to content

Commit d0c76da

Browse files
committed
migrate tests in eliminate_outer_join.rs to use snapshot assertions
1 parent d1ea368 commit d0c76da

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

datafusion/optimizer/src/eliminate_outer_join.rs

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ fn extract_non_nullable_columns(
304304
#[cfg(test)]
305305
mod tests {
306306
use super::*;
307+
use crate::assert_optimized_plan_eq_snapshot;
307308
use crate::test::*;
308309
use arrow::datatypes::DataType;
309310
use datafusion_expr::{
@@ -313,8 +314,18 @@ mod tests {
313314
Operator::{And, Or},
314315
};
315316

316-
fn assert_optimized_plan_equal(plan: LogicalPlan, expected: &str) -> Result<()> {
317-
assert_optimized_plan_eq(Arc::new(EliminateOuterJoin::new()), plan, expected)
317+
macro_rules! assert_optimized_plan_equal {
318+
(
319+
$plan:expr,
320+
@$expected:literal $(,)?
321+
) => {{
322+
let rule: Arc<dyn crate::OptimizerRule + Send + Sync> = Arc::new(EliminateOuterJoin::new());
323+
assert_optimized_plan_eq_snapshot!(
324+
rule,
325+
$plan,
326+
@ $expected,
327+
)
328+
}};
318329
}
319330

320331
#[test]
@@ -332,12 +343,13 @@ mod tests {
332343
)?
333344
.filter(col("t2.b").is_null())?
334345
.build()?;
335-
let expected = "\
336-
Filter: t2.b IS NULL\
337-
\n Left Join: t1.a = t2.a\
338-
\n TableScan: t1\
339-
\n TableScan: t2";
340-
assert_optimized_plan_equal(plan, expected)
346+
347+
assert_optimized_plan_equal!(plan, @r"
348+
Filter: t2.b IS NULL
349+
Left Join: t1.a = t2.a
350+
TableScan: t1
351+
TableScan: t2
352+
")
341353
}
342354

343355
#[test]
@@ -355,12 +367,13 @@ mod tests {
355367
)?
356368
.filter(col("t2.b").is_not_null())?
357369
.build()?;
358-
let expected = "\
359-
Filter: t2.b IS NOT NULL\
360-
\n Inner Join: t1.a = t2.a\
361-
\n TableScan: t1\
362-
\n TableScan: t2";
363-
assert_optimized_plan_equal(plan, expected)
370+
371+
assert_optimized_plan_equal!(plan, @r"
372+
Filter: t2.b IS NOT NULL
373+
Inner Join: t1.a = t2.a
374+
TableScan: t1
375+
TableScan: t2
376+
")
364377
}
365378

366379
#[test]
@@ -382,12 +395,13 @@ mod tests {
382395
col("t1.c").lt(lit(20u32)),
383396
))?
384397
.build()?;
385-
let expected = "\
386-
Filter: t1.b > UInt32(10) OR t1.c < UInt32(20)\
387-
\n Inner Join: t1.a = t2.a\
388-
\n TableScan: t1\
389-
\n TableScan: t2";
390-
assert_optimized_plan_equal(plan, expected)
398+
399+
assert_optimized_plan_equal!(plan, @r"
400+
Filter: t1.b > UInt32(10) OR t1.c < UInt32(20)
401+
Inner Join: t1.a = t2.a
402+
TableScan: t1
403+
TableScan: t2
404+
")
391405
}
392406

393407
#[test]
@@ -409,12 +423,13 @@ mod tests {
409423
col("t2.c").lt(lit(20u32)),
410424
))?
411425
.build()?;
412-
let expected = "\
413-
Filter: t1.b > UInt32(10) AND t2.c < UInt32(20)\
414-
\n Inner Join: t1.a = t2.a\
415-
\n TableScan: t1\
416-
\n TableScan: t2";
417-
assert_optimized_plan_equal(plan, expected)
426+
427+
assert_optimized_plan_equal!(plan, @r"
428+
Filter: t1.b > UInt32(10) AND t2.c < UInt32(20)
429+
Inner Join: t1.a = t2.a
430+
TableScan: t1
431+
TableScan: t2
432+
")
418433
}
419434

420435
#[test]
@@ -436,11 +451,12 @@ mod tests {
436451
try_cast(col("t2.c"), DataType::Int64).lt(lit(20u32)),
437452
))?
438453
.build()?;
439-
let expected = "\
440-
Filter: CAST(t1.b AS Int64) > UInt32(10) AND TRY_CAST(t2.c AS Int64) < UInt32(20)\
441-
\n Inner Join: t1.a = t2.a\
442-
\n TableScan: t1\
443-
\n TableScan: t2";
444-
assert_optimized_plan_equal(plan, expected)
454+
455+
assert_optimized_plan_equal!(plan, @r"
456+
Filter: CAST(t1.b AS Int64) > UInt32(10) AND TRY_CAST(t2.c AS Int64) < UInt32(20)
457+
Inner Join: t1.a = t2.a
458+
TableScan: t1
459+
TableScan: t2
460+
")
445461
}
446462
}

0 commit comments

Comments
 (0)