@@ -486,6 +486,7 @@ fn smj_join(
486486/// - Left-side filters are pushed down to the left child
487487/// - Right-side filters are pushed down to the right child
488488/// - Cross-side filters (referencing both sides) remain as FilterExec
489+ ///
489490/// Also tests that non-Inner join types (Left) reject pushdown.
490491#[ test]
491492fn test_static_filter_pushdown_through_sort_merge_join ( ) {
@@ -582,7 +583,7 @@ fn test_static_filter_pushdown_through_sort_merge_join() {
582583 // The two adjacent FilterExec nodes get collapsed into a single combined predicate.
583584 insta:: assert_snapshot!(
584585 OptimizationTest :: new( plan, FilterPushdown :: new( ) , true ) ,
585- @r "
586+ @"
586587 OptimizationTest:
587588 input:
588589 - FilterExec: e@4 = ba
@@ -592,9 +593,9 @@ fn test_static_filter_pushdown_through_sort_merge_join() {
592593 - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[d, e, f], file_type=test, pushdown_supported=true
593594 output:
594595 Ok:
595- - FilterExec: e@4 = ba AND a@0 = aa
596+ - FilterExec: e@4 = ba
596597 - SortMergeJoinExec: join_type=Left, on=[(a@0, d@0)]
597- - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
598+ - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=a@0 = aa
598599 - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[d, e, f], file_type=test, pushdown_supported=true
599600 "
600601 ) ;
@@ -671,11 +672,11 @@ async fn test_dynamic_filter_pushdown_through_sort_merge_join_with_topk() {
671672 // The TopK dynamic filter should pass through the SMJ to the right scan
672673 insta:: assert_snapshot!(
673674 format_plan_for_test( & plan) ,
674- @r "
675+ @"
675676 - SortExec: TopK(fetch=2), expr=[e@4 ASC], preserve_partitioning=[false]
676- - SortMergeJoinExec: join_type=Inner, on=[(a@0, d@0)]
677- - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
678- - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[d, e, f], file_type=test, pushdown_supported=true, predicate=DynamicFilter [ empty ]
677+ - SortMergeJoinExec: join_type=Inner, on=[(a@0, d@0)], left_dynamic_filter=DynamicFilter [ empty ], right_dynamic_filter=DynamicFilter [ empty ]
678+ - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=DynamicFilter [ empty ]
679+ - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[d, e, f], file_type=test, pushdown_supported=true, predicate=DynamicFilter [ empty ] AND DynamicFilter [ empty ]
679680 "
680681 ) ;
681682
@@ -694,19 +695,72 @@ async fn test_dynamic_filter_pushdown_through_sort_merge_join_with_topk() {
694695 // After execution, the dynamic filter should be populated with actual bounds
695696 insta:: assert_snapshot!(
696697 format_plan_for_test( & plan) ,
697- @r "
698+ @"
698699 - SortExec: TopK(fetch=2), expr=[e@4 ASC], preserve_partitioning=[false], filter=[e@4 IS NULL OR e@4 < bb]
699- - SortMergeJoinExec: join_type=Inner, on=[(a@0, d@0)]
700- - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true
701- - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[d, e, f], file_type=test, pushdown_supported=true, predicate=DynamicFilter [ e@1 IS NULL OR e@1 < bb ]
700+ - SortMergeJoinExec: join_type=Inner, on=[(a@0, d@0)], left_dynamic_filter=DynamicFilter [ false ], right_dynamic_filter=DynamicFilter [ false ]
701+ - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[a, b, c], file_type=test, pushdown_supported=true, predicate=DynamicFilter [ false ]
702+ - DataSourceExec: file_groups={1 group: [[test.parquet]]}, projection=[d, e, f], file_type=test, pushdown_supported=true, predicate=DynamicFilter [ false ] AND DynamicFilter [ e@1 IS NULL OR e@1 < bb ]
702703 "
703704 ) ;
704705}
705706
706- /// Tests filter pushdown for all non-Inner join types to ensure they correctly
707- /// reject pushdown (conservative behavior).
707+ /// Tests filter pushdown for Full join to ensure it correctly rejects pushdown.
708708#[ test]
709- fn test_smj_filter_pushdown_non_inner_unsupported ( ) {
709+ fn test_smj_filter_pushdown_unsupported ( ) {
710+ use datafusion_common:: JoinType ;
711+
712+ let left_schema = Arc :: new ( Schema :: new ( vec ! [
713+ Field :: new( "a" , DataType :: Utf8 , false ) ,
714+ Field :: new( "b" , DataType :: Utf8 , false ) ,
715+ ] ) ) ;
716+ let right_schema = Arc :: new ( Schema :: new ( vec ! [
717+ Field :: new( "c" , DataType :: Utf8 , false ) ,
718+ Field :: new( "d" , DataType :: Utf8 , false ) ,
719+ ] ) ) ;
720+
721+ {
722+ let join_type = JoinType :: Full ;
723+ let left_scan = TestScanBuilder :: new ( Arc :: clone ( & left_schema) )
724+ . with_support ( true )
725+ . build ( ) ;
726+ let right_scan = TestScanBuilder :: new ( Arc :: clone ( & right_schema) )
727+ . with_support ( true )
728+ . build ( ) ;
729+ let on = vec ! [ (
730+ col( "a" , & left_schema) . unwrap( ) ,
731+ col( "c" , & right_schema) . unwrap( ) ,
732+ ) ] ;
733+ let join = smj_join ( left_scan, right_scan, on, join_type) ;
734+
735+ let join_schema = join. schema ( ) ;
736+ let filter_pred = col_lit_predicate ( "a" , "x" , & join_schema) ;
737+ let plan = Arc :: new ( FilterExec :: try_new ( filter_pred, join) . unwrap ( ) )
738+ as Arc < dyn ExecutionPlan > ;
739+
740+ let result = OptimizationTest :: new ( plan, FilterPushdown :: new ( ) , true ) ;
741+ let full_output = format ! ( "{result}" ) ;
742+ let output = full_output
743+ . split ( "output:" )
744+ . nth ( 1 )
745+ . expect ( "Expected output section in result" ) ;
746+
747+ // The filter should remain as a FilterExec (not pushed into the scan)
748+ assert ! (
749+ output. contains( "FilterExec" ) ,
750+ "Expected FilterExec to remain for {join_type:?} join, got:\n {full_output}"
751+ ) ;
752+ // The scan should NOT have a predicate
753+ assert ! (
754+ !output. contains( "predicate=" ) ,
755+ "Expected no predicate pushdown for {join_type:?} join, got:\n {full_output}"
756+ ) ;
757+ }
758+ }
759+
760+ /// Tests filter pushdown for other non-Inner join types to ensure they correctly
761+ /// support pushdown for their preserved side.
762+ #[ test]
763+ fn test_smj_filter_pushdown_supported ( ) {
710764 use datafusion_common:: JoinType ;
711765
712766 let left_schema = Arc :: new ( Schema :: new ( vec ! [
@@ -722,7 +776,6 @@ fn test_smj_filter_pushdown_non_inner_unsupported() {
722776 for join_type in [
723777 JoinType :: Left ,
724778 JoinType :: Right ,
725- JoinType :: Full ,
726779 JoinType :: LeftSemi ,
727780 JoinType :: LeftAnti ,
728781 JoinType :: RightSemi ,
@@ -744,24 +797,29 @@ fn test_smj_filter_pushdown_non_inner_unsupported() {
744797 // Pick a column from the join output; for semi/anti joins only
745798 // one side's columns are present
746799 let filter_col = match join_type {
747- JoinType :: RightSemi | JoinType :: RightAnti => "c" ,
800+ JoinType :: RightSemi | JoinType :: RightAnti | JoinType :: Right => "c" ,
748801 _ => "a" ,
749802 } ;
750803 let filter_pred = col_lit_predicate ( filter_col, "x" , & join_schema) ;
751804 let plan = Arc :: new ( FilterExec :: try_new ( filter_pred, join) . unwrap ( ) )
752805 as Arc < dyn ExecutionPlan > ;
753806
754807 let result = OptimizationTest :: new ( plan, FilterPushdown :: new ( ) , true ) ;
755- let output = format ! ( "{result}" ) ;
756- // The filter should remain as a FilterExec (not pushed into the scan)
808+ let full_output = format ! ( "{result}" ) ;
809+ let output = full_output
810+ . split ( "output:" )
811+ . nth ( 1 )
812+ . expect ( "Expected output section in result" ) ;
813+
814+ // The filter should NOT remain as a FilterExec (pushed into the scan)
757815 assert ! (
758- output. contains( "FilterExec" ) ,
759- "Expected FilterExec to remain for {join_type:?} join, got:\n {output }"
816+ ! output. contains( "FilterExec" ) ,
817+ "Expected FilterExec to be pushed for {join_type:?} join, got:\n {full_output }"
760818 ) ;
761- // The scan should NOT have a predicate
819+ // The scan should HAVE a predicate
762820 assert ! (
763- ! output. contains( "predicate=" ) ,
764- "Expected no predicate pushdown for {join_type:?} join, got:\n {output }"
821+ output. contains( "predicate=" ) ,
822+ "Expected predicate pushdown for {join_type:?} join, got:\n {full_output }"
765823 ) ;
766824 }
767825}
0 commit comments