jayzhan211 commented on code in PR #27347:
URL: https://github.com/apache/datafusion/pull/27347#discussion_r4571935102
##########
datafusion/physical-expr/src/equivalence/properties/union.rs:
##########
@@ -61,7 +61,22 @@ fn calculate_union_binary(
orderings.add_satisfied_orderings(rhs, &lhs)?;
let orderings = orderings.build();
+ // An equality holds at the output only if it holds in both inputs. Keep
+ // it in the result so the next fold step can still use it.
+ let mut eq_group = EquivalenceGroup::default();
+ for class in lhs.eq_group().iter() {
+ for (i, left) in class.iter().enumerate() {
+ for right in class.iter().skip(i + 1) {
+ let rhs_class = rhs.eq_group().get_equivalence_class(left);
+ if rhs_class.is_some_and(|cls| cls.contains(right)) {
Review Comment:
Optional cleanup: the `rhs` class lookup only depends on `left`, so it can
move out of the inner loop (union tests and clippy pass with it):
```suggestion
for (i, left) in class.iter().enumerate() {
let Some(rhs_class) = rhs.eq_group().get_equivalence_class(left)
else {
continue;
};
for right in class.iter().skip(i + 1) {
if rhs_class.contains(right) {
```
--
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]