1717
1818use core:: panic;
1919use std:: collections:: HashSet ;
20- use std:: ops:: Not ;
2120use std:: vec;
2221
2322use 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