jayzhan211 commented on code in PR #27066:
URL: https://github.com/apache/datafusion/pull/27066#discussion_r4504475556
##########
datafusion/optimizer/src/eliminate_cross_join.rs:
##########
@@ -177,29 +174,30 @@ impl OptimizerRule for EliminateCrossJoin {
));
}
- if !all_filters.is_empty() {
- // Add any filters on top - PushDownFilter can push filters down
to applicable join
- let first = all_filters.swap_remove(0);
- let predicate = all_filters.into_iter().fold(first, and);
- left = LogicalPlan::Filter(Filter::try_new(predicate,
Arc::new(left))?);
+ if let Some(predicate) = parent_predicate {
+ all_filters.push(predicate);
}
- let Some(predicate) = parent_predicate else {
- return Ok(Transformed::yes(left));
- };
-
- // If there are no join keys then do nothing:
- if all_join_keys.is_empty() {
- Filter::try_new(predicate, Arc::new(left))
- .map(|filter| Transformed::yes(LogicalPlan::Filter(filter)))
- } else {
- // Remove join expressions from filter:
- match remove_join_expressions(predicate, &all_join_keys) {
- Some(filter_expr) => Filter::try_new(filter_expr,
Arc::new(left))
- .map(|filter|
Transformed::yes(LogicalPlan::Filter(filter))),
- _ => Ok(Transformed::yes(left)),
- }
+ // Only remove predicates enforced by rebuilt joins with the same NULL
+ // semantics. Keys spanning several inputs may need to remain as
filters.
+ let predicate = all_filters
+ .into_iter()
+ .filter_map(|expr| {
+ if all_join_keys.is_empty() &&
all_null_equal_join_keys.is_empty() {
+ Some(expr)
+ } else {
+ remove_join_expressions(
+ expr,
+ &all_join_keys,
+ &all_null_equal_join_keys,
+ )
+ }
+ })
Review Comment:
Optional cleanup: the empty-key-set branch isn't needed.
`remove_join_expressions` with empty key sets returns its input unchanged, and
the unit tests plus `joins.slt` still pass without the branch.
```suggestion
.filter_map(|expr| {
remove_join_expressions(expr, &all_join_keys,
&all_null_equal_join_keys)
})
```
--
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]