mikamikasuki commented on code in PR #26059:
URL: https://github.com/apache/datafusion/pull/26059#discussion_r4368686385
##########
datafusion/optimizer/src/eliminate_cross_join.rs:
##########
@@ -170,6 +174,23 @@ impl OptimizerRule for EliminateCrossJoin {
left = rewrite_children(self, left, config)?.data;
+ // Keep any original ON predicates that could not be assigned to one
+ // of the rebuilt joins. In particular, an equijoin key can reference
+ // columns from more than one flattened input on the same side, so it
+ // may only become evaluable after the join graph has been rebuilt.
+ for (left_key, right_key, original_null_equality) in
original_join_keys {
+ if !all_join_keys.contains(&left_key, &right_key) {
+ all_filters.push(binary_expr(
+ left_key.clone(),
+ match original_null_equality {
+ NullEquality::NullEqualsNothing => Operator::Eq,
+ NullEquality::NullEqualsNull =>
Operator::IsNotDistinctFrom,
+ },
+ right_key.clone(),
+ ));
+ }
+ }
Review Comment:
Thanks for checking this. `JoinKeySet::contains` in
`datafusion/optimizer/src/join_key_set.rs` checks both `(left, right)` and
`(right, left)`, so this lookup is already order-insensitive; I left the
production logic unchanged. I also replaced the string-based assertion raised
in the other thread with a structural `Filter` / `IsNotDistinctFrom` assertion
in commit `0bc0b22`.
--
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]