Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit dede91b

Browse files
committed
unit test for the join-split-filter rule
Signed-off-by: Yuchen Liang <[email protected]>
1 parent 5cd56d7 commit dede91b

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

optd-datafusion-repr/src/rules/filter_pushdown.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
use core::panic;
1919
use std::collections::HashSet;
20-
use std::ops::Not;
2120
use std::vec;
2221

2322
use optd_core::nodes::PlanNodeOrGroup;
@@ -550,12 +549,14 @@ mod tests {
550549
)
551550
.into_pred_node(),
552551
BinOpPred::new(
553-
// This one stay in join condition
552+
// This one stays in the join condition.
554553
ColumnRefPred::new(2).into_pred_node(),
555554
ColumnRefPred::new(8).into_pred_node(),
556555
BinOpType::Eq,
557556
)
558557
.into_pred_node(),
558+
// This one stays in the join condition.
559+
ConstantPred::bool(true).into_pred_node(),
559560
],
560561
);
561562

@@ -567,7 +568,50 @@ mod tests {
567568
);
568569

569570
let plan = test_optimizer.optimize(join.into_plan_node()).unwrap();
570-
println!("{}", plan.explain_to_string(None));
571+
let join = LogicalJoin::from_plan_node(plan.clone()).unwrap();
572+
573+
assert_eq!(join.join_type(), &JoinType::LeftOuter);
574+
575+
{
576+
// Examine join conditions.
577+
let join_conds = LogOpPred::from_pred_node(join.cond()).unwrap();
578+
assert!(matches!(join_conds.op_type(), LogOpType::And));
579+
assert_eq!(join_conds.children().len(), 2);
580+
let bin_op_with_both_ref =
581+
BinOpPred::from_pred_node(join_conds.children()[0].clone()).unwrap();
582+
assert!(matches!(bin_op_with_both_ref.op_type(), BinOpType::Eq));
583+
let col_2 = ColumnRefPred::from_pred_node(bin_op_with_both_ref.left_child()).unwrap();
584+
let col_8 = ColumnRefPred::from_pred_node(bin_op_with_both_ref.right_child()).unwrap();
585+
assert_eq!(col_2.index(), 2);
586+
assert_eq!(col_8.index(), 8);
587+
let constant_true =
588+
ConstantPred::from_pred_node(join_conds.children()[1].clone()).unwrap();
589+
assert_eq!(constant_true.value().as_bool(), true);
590+
}
591+
592+
{
593+
// Examine left child filter + condition
594+
let filter_left =
595+
LogicalFilter::from_plan_node(join.left().unwrap_plan_node()).unwrap();
596+
let bin_op = BinOpPred::from_pred_node(filter_left.cond()).unwrap();
597+
assert!(matches!(bin_op.op_type(), BinOpType::Eq));
598+
let col = ColumnRefPred::from_pred_node(bin_op.left_child()).unwrap();
599+
let constant = ConstantPred::from_pred_node(bin_op.right_child()).unwrap();
600+
assert_eq!(col.index(), 0);
601+
assert_eq!(constant.value().as_i32(), 5);
602+
}
603+
604+
{
605+
// Examine right child filter + condition
606+
let filter_right =
607+
LogicalFilter::from_plan_node(join.right().unwrap_plan_node()).unwrap();
608+
let bin_op = BinOpPred::from_pred_node(filter_right.cond()).unwrap();
609+
assert!(matches!(bin_op.op_type(), BinOpType::Eq));
610+
let col = ColumnRefPred::from_pred_node(bin_op.left_child()).unwrap();
611+
let constant = ConstantPred::from_pred_node(bin_op.right_child()).unwrap();
612+
assert_eq!(col.index(), 3);
613+
assert_eq!(constant.value().as_i32(), 6);
614+
}
571615
}
572616

573617
#[test]

0 commit comments

Comments
 (0)