@@ -34,7 +34,7 @@ use crate::{
34
34
35
35
use arrow_schema:: { SchemaRef , SortOptions } ;
36
36
use datafusion_common:: tree_node:: { Transformed , TransformedResult , TreeNode } ;
37
- use datafusion_common:: { plan_err, JoinSide , JoinType , Result } ;
37
+ use datafusion_common:: { internal_err , plan_err, JoinSide , JoinType , Result } ;
38
38
use datafusion_expr:: interval_arithmetic:: Interval ;
39
39
use datafusion_expr:: sort_properties:: { ExprProperties , SortProperties } ;
40
40
use datafusion_physical_expr_common:: utils:: ExprPropertiesNode ;
@@ -1677,14 +1677,22 @@ pub fn calculate_union(
1677
1677
) -> Result < EquivalenceProperties > {
1678
1678
// TODO: In some cases, we should be able to preserve some equivalence
1679
1679
// classes. Add support for such cases.
1680
- let mut init = eqps[ 0 ] . clone ( ) ;
1680
+ let mut iter = eqps. into_iter ( ) ;
1681
+ let Some ( mut acc) = iter. next ( ) else {
1682
+ return internal_err ! (
1683
+ "Cannot calculate EquivalenceProperties for a union with no inputs"
1684
+ ) ;
1685
+ } ;
1686
+
1681
1687
// Harmonize the schema of the init with the schema of the union:
1682
- if !init. schema . eq ( & schema) {
1683
- init = init. with_new_schema ( schema) ?;
1688
+ if !acc. schema . eq ( & schema) {
1689
+ acc = acc. with_new_schema ( schema) ?;
1690
+ }
1691
+ // Fold in the rest of the EquivalenceProperties:
1692
+ for props in iter {
1693
+ acc = calculate_union_binary ( acc, props) ?;
1684
1694
}
1685
- eqps. into_iter ( )
1686
- . skip ( 1 )
1687
- . try_fold ( init, calculate_union_binary)
1695
+ Ok ( acc)
1688
1696
}
1689
1697
1690
1698
#[ cfg( test) ]
0 commit comments