jayzhan211 commented on code in PR #25255:
URL: https://github.com/apache/datafusion/pull/25255#discussion_r4005719350


##########
datafusion/core/tests/physical_optimizer/filter_pushdown.rs:
##########
@@ -1754,6 +1754,293 @@ fn 
test_hashjoin_parent_filter_pushdown_semi_anti_join() {
     assert_parent_filter_remains(plan);
 }
 
+/// A parent filter over one side's join keys is transferred to the other side,
+/// rewritten over that side's key expressions, even when the key names differ.
+/// Filters over non-key columns stay on their own side.
+#[test]
+fn test_hashjoin_parent_filter_transferred_across_join_keys() {
+    let build_side_schema = Arc::new(Schema::new(vec![
+        Field::new("id", DataType::Utf8, false),
+        Field::new("build_val", DataType::Utf8, false),
+    ]));
+    let build_scan = TestScanBuilder::new(Arc::clone(&build_side_schema))
+        .with_support(true)
+        .build();
+
+    let probe_side_schema = Arc::new(Schema::new(vec![
+        Field::new("pid", DataType::Utf8, false),
+        Field::new("probe_val", DataType::Utf8, false),
+    ]));
+    let probe_scan = TestScanBuilder::new(Arc::clone(&probe_side_schema))
+        .with_support(true)
+        .build();
+
+    let on = vec![(
+        col("id", &build_side_schema).unwrap(),
+        col("pid", &probe_side_schema).unwrap(),
+    )];
+    let join = Arc::new(
+        HashJoinExec::try_new(
+            build_scan,
+            probe_scan,
+            on,
+            None,
+            &JoinType::Inner,
+            None,
+            PartitionMode::Partitioned,
+            datafusion_common::NullEquality::NullEqualsNothing,
+            false,
+        )
+        .unwrap(),
+    );
+
+    let join_schema = join.schema();
+
+    let build_key_filter = col_lit_predicate("id", "aa", &join_schema);
+    let probe_key_filter = col_lit_predicate("pid", "ab", &join_schema);
+    let build_val_filter = col_lit_predicate("build_val", "x", &join_schema);
+
+    let filter =
+        Arc::new(FilterExec::try_new(build_key_filter, Arc::clone(&join) as 
_).unwrap());
+    let filter = Arc::new(FilterExec::try_new(probe_key_filter, 
filter).unwrap());
+    let plan = Arc::new(FilterExec::try_new(build_val_filter, filter).unwrap())
+        as Arc<dyn ExecutionPlan>;
+
+    insta::assert_snapshot!(
+        OptimizationTest::new(Arc::clone(&plan), FilterPushdown::new(), true),
+        @r"
+    OptimizationTest:
+      input:
+        - FilterExec: build_val@1 = x
+        -   FilterExec: pid@2 = ab
+        -     FilterExec: id@0 = aa
+        -       HashJoinExec: mode=Partitioned, join_type=Inner, on=[(id@0, 
pid@0)]
+        -         DataSourceExec: file_groups={1 group: [[test.parquet]]}, 
projection=[id, build_val], file_type=test, pushdown_supported=true
+        -         DataSourceExec: file_groups={1 group: [[test.parquet]]}, 
projection=[pid, probe_val], file_type=test, pushdown_supported=true
+      output:
+        Ok:
+          - HashJoinExec: mode=Partitioned, join_type=Inner, on=[(id@0, pid@0)]
+          -   DataSourceExec: file_groups={1 group: [[test.parquet]]}, 
projection=[id, build_val], file_type=test, pushdown_supported=true, 
predicate=id@0 = aa AND id@0 = ab AND build_val@1 = x
+          -   DataSourceExec: file_groups={1 group: [[test.parquet]]}, 
projection=[pid, probe_val], file_type=test, pushdown_supported=true, 
predicate=pid@0 = aa AND pid@0 = ab
+    "
+    );
+}
+
+/// The non-output side of a semi join receives key filters through the same
+/// transfer, so differently named keys work too.
+#[test]
+fn test_hashjoin_parent_filter_transfer_semi_join_different_key_names() {

Review Comment:
   test_hashjoin_parent_filter_transfer_semi_join_key_name_shadowed_by_non_key 
added



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to