@@ -131,7 +131,7 @@ pub struct EquivalenceProperties {
131
131
/// Expressions whose values are constant
132
132
///
133
133
/// TODO: We do not need to track constants separately, they can be tracked
134
- /// inside `eq_groups ` as `Literal` expressions.
134
+ /// inside `eq_group ` as `Literal` expressions.
135
135
constants : Vec < ConstExpr > ,
136
136
/// Schema associated with this object.
137
137
schema : SchemaRef ,
@@ -168,6 +168,11 @@ impl EquivalenceProperties {
168
168
& self . oeq_class
169
169
}
170
170
171
+ /// Return the inner OrderingEquivalenceClass, consuming self
172
+ pub fn into_oeq_class ( self ) -> OrderingEquivalenceClass {
173
+ self . oeq_class
174
+ }
175
+
171
176
/// Returns a reference to the equivalence group within.
172
177
pub fn eq_group ( & self ) -> & EquivalenceGroup {
173
178
& self . eq_group
@@ -430,8 +435,8 @@ impl EquivalenceProperties {
430
435
let mut new_orderings = vec ! [ filtered_exprs. clone( ) ] ;
431
436
432
437
// Preserve valid suffixes from existing orderings
433
- let orderings = mem:: take ( & mut self . oeq_class . orderings ) ;
434
- for existing in orderings {
438
+ let oeq_class = mem:: take ( & mut self . oeq_class ) ;
439
+ for existing in oeq_class {
435
440
if self . is_prefix_of ( & filtered_exprs, & existing) {
436
441
let mut extended = filtered_exprs. clone ( ) ;
437
442
extended. extend ( existing. into_iter ( ) . skip ( filtered_exprs. len ( ) ) ) ;
@@ -710,8 +715,8 @@ impl EquivalenceProperties {
710
715
/// Since it would cause bug in dependency constructions, we should substitute the input order in order to get correct
711
716
/// dependency map, happen in issue 8838: <https://github.com/apache/datafusion/issues/8838>
712
717
pub fn substitute_oeq_class ( & mut self , mapping : & ProjectionMapping ) -> Result < ( ) > {
713
- let orderings = & self . oeq_class . orderings ;
714
- let new_order = orderings
718
+ let new_order = self
719
+ . oeq_class
715
720
. iter ( )
716
721
. map ( |order| self . substitute_ordering_component ( mapping, order) )
717
722
. collect :: < Result < Vec < _ > > > ( ) ?;
@@ -1219,7 +1224,7 @@ impl EquivalenceProperties {
1219
1224
1220
1225
// Rewrite orderings according to new schema:
1221
1226
let mut new_orderings = vec ! [ ] ;
1222
- for ordering in self . oeq_class . orderings {
1227
+ for ordering in self . oeq_class {
1223
1228
let new_ordering = ordering
1224
1229
. inner
1225
1230
. into_iter ( )
@@ -2008,16 +2013,8 @@ fn calculate_union_binary(
2008
2013
// Next, calculate valid orderings for the union by searching for prefixes
2009
2014
// in both sides.
2010
2015
let mut orderings = UnionEquivalentOrderingBuilder :: new ( ) ;
2011
- orderings. add_satisfied_orderings (
2012
- lhs. normalized_oeq_class ( ) . orderings ,
2013
- lhs. constants ( ) ,
2014
- & rhs,
2015
- ) ;
2016
- orderings. add_satisfied_orderings (
2017
- rhs. normalized_oeq_class ( ) . orderings ,
2018
- rhs. constants ( ) ,
2019
- & lhs,
2020
- ) ;
2016
+ orderings. add_satisfied_orderings ( lhs. normalized_oeq_class ( ) , lhs. constants ( ) , & rhs) ;
2017
+ orderings. add_satisfied_orderings ( rhs. normalized_oeq_class ( ) , rhs. constants ( ) , & lhs) ;
2021
2018
let orderings = orderings. build ( ) ;
2022
2019
2023
2020
let mut eq_properties =
@@ -2156,7 +2153,7 @@ impl UnionEquivalentOrderingBuilder {
2156
2153
2157
2154
// for each equivalent ordering in properties, try and augment
2158
2155
// `ordering` it with the constants to match
2159
- for existing_ordering in & properties. oeq_class . orderings {
2156
+ for existing_ordering in properties. oeq_class . iter ( ) {
2160
2157
if let Some ( augmented_ordering) = self . augment_ordering (
2161
2158
ordering,
2162
2159
constants,
@@ -2437,17 +2434,12 @@ mod tests {
2437
2434
Some ( JoinSide :: Left ) ,
2438
2435
& [ ] ,
2439
2436
) ;
2440
- let orderings = & join_eq. oeq_class . orderings ;
2441
- let err_msg = format ! ( "expected: {:?}, actual:{:?}" , expected, orderings) ;
2442
- assert_eq ! (
2443
- join_eq. oeq_class. orderings. len( ) ,
2444
- expected. len( ) ,
2445
- "{}" ,
2446
- err_msg
2447
- ) ;
2448
- for ordering in orderings {
2437
+ let err_msg =
2438
+ format ! ( "expected: {:?}, actual:{:?}" , expected, & join_eq. oeq_class) ;
2439
+ assert_eq ! ( join_eq. oeq_class. len( ) , expected. len( ) , "{}" , err_msg) ;
2440
+ for ordering in join_eq. oeq_class {
2449
2441
assert ! (
2450
- expected. contains( ordering) ,
2442
+ expected. contains( & ordering) ,
2451
2443
"{}, ordering: {:?}" ,
2452
2444
err_msg,
2453
2445
ordering
@@ -3766,8 +3758,8 @@ mod tests {
3766
3758
3767
3759
// Check whether orderings are same.
3768
3760
let lhs_orderings = lhs. oeq_class ( ) ;
3769
- let rhs_orderings = & rhs. oeq_class . orderings ;
3770
- for rhs_ordering in rhs_orderings {
3761
+ let rhs_orderings = rhs. oeq_class ( ) ;
3762
+ for rhs_ordering in rhs_orderings. iter ( ) {
3771
3763
assert ! (
3772
3764
lhs_orderings. contains( rhs_ordering) ,
3773
3765
"{err_msg}\n lhs: {lhs}\n rhs: {rhs}"
@@ -3843,7 +3835,7 @@ mod tests {
3843
3835
// Add equality condition c = concat(a, b)
3844
3836
eq_properties. add_equal_conditions ( & col_c, & a_concat_b) ?;
3845
3837
3846
- let orderings = eq_properties. oeq_class ( ) . orderings . clone ( ) ;
3838
+ let orderings = eq_properties. oeq_class ( ) ;
3847
3839
3848
3840
let expected_ordering1 =
3849
3841
LexOrdering :: from ( vec ! [
@@ -3894,7 +3886,7 @@ mod tests {
3894
3886
// Add equality condition c = a * b
3895
3887
eq_properties. add_equal_conditions ( & col_c, & a_times_b) ?;
3896
3888
3897
- let orderings = eq_properties. oeq_class ( ) . orderings . clone ( ) ;
3889
+ let orderings = eq_properties. oeq_class ( ) ;
3898
3890
3899
3891
// The ordering should remain unchanged since multiplication is not lex-monotonic
3900
3892
assert_eq ! ( orderings. len( ) , 1 ) ;
@@ -3934,7 +3926,7 @@ mod tests {
3934
3926
// Add equality condition c = concat(a, b)
3935
3927
eq_properties. add_equal_conditions ( & col_c, & a_concat_b) ?;
3936
3928
3937
- let orderings = eq_properties. oeq_class ( ) . orderings . clone ( ) ;
3929
+ let orderings = eq_properties. oeq_class ( ) ;
3938
3930
3939
3931
let expected_ordering1 = LexOrdering :: from ( vec ! [ PhysicalSortExpr :: new_default(
3940
3932
Arc :: clone( & a_concat_b) ,
@@ -3978,8 +3970,9 @@ mod tests {
3978
3970
3979
3971
// Should only contain b since a is constant
3980
3972
assert_eq ! ( result. oeq_class( ) . len( ) , 1 ) ;
3981
- assert_eq ! ( result. oeq_class( ) . orderings[ 0 ] . len( ) , 1 ) ;
3982
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 0 ] . expr. eq( & col_b) ) ;
3973
+ let ordering = result. oeq_class ( ) . iter ( ) . next ( ) . unwrap ( ) ;
3974
+ assert_eq ! ( ordering. len( ) , 1 ) ;
3975
+ assert ! ( ordering[ 0 ] . expr. eq( & col_b) ) ;
3983
3976
3984
3977
Ok ( ( ) )
3985
3978
}
@@ -4025,13 +4018,14 @@ mod tests {
4025
4018
4026
4019
// Should only contain [a ASC, b DESC, c ASC]
4027
4020
assert_eq ! ( result. oeq_class( ) . len( ) , 1 ) ;
4028
- assert_eq ! ( result. oeq_class( ) . orderings[ 0 ] . len( ) , 3 ) ;
4029
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 0 ] . expr. eq( & col_a) ) ;
4030
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 0 ] . options. eq( & asc) ) ;
4031
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 1 ] . expr. eq( & col_b) ) ;
4032
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 1 ] . options. eq( & desc) ) ;
4033
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 2 ] . expr. eq( & col_c) ) ;
4034
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 2 ] . options. eq( & asc) ) ;
4021
+ let ordering = result. oeq_class ( ) . iter ( ) . next ( ) . unwrap ( ) ;
4022
+ assert_eq ! ( ordering. len( ) , 3 ) ;
4023
+ assert ! ( ordering[ 0 ] . expr. eq( & col_a) ) ;
4024
+ assert ! ( ordering[ 0 ] . options. eq( & asc) ) ;
4025
+ assert ! ( ordering[ 1 ] . expr. eq( & col_b) ) ;
4026
+ assert ! ( ordering[ 1 ] . options. eq( & desc) ) ;
4027
+ assert ! ( ordering[ 2 ] . expr. eq( & col_c) ) ;
4028
+ assert ! ( ordering[ 2 ] . options. eq( & asc) ) ;
4035
4029
4036
4030
Ok ( ( ) )
4037
4031
}
@@ -4074,11 +4068,12 @@ mod tests {
4074
4068
assert_eq ! ( result. oeq_class( ) . len( ) , 1 ) ;
4075
4069
4076
4070
// Verify orderings
4077
- assert_eq ! ( result. oeq_class( ) . orderings[ 0 ] . len( ) , 2 ) ;
4078
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 0 ] . expr. eq( & col_b) ) ;
4079
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 0 ] . options. eq( & asc) ) ;
4080
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 1 ] . expr. eq( & col_c) ) ;
4081
- assert ! ( result. oeq_class( ) . orderings[ 0 ] [ 1 ] . options. eq( & asc) ) ;
4071
+ let ordering = result. oeq_class ( ) . iter ( ) . next ( ) . unwrap ( ) ;
4072
+ assert_eq ! ( ordering. len( ) , 2 ) ;
4073
+ assert ! ( ordering[ 0 ] . expr. eq( & col_b) ) ;
4074
+ assert ! ( ordering[ 0 ] . options. eq( & asc) ) ;
4075
+ assert ! ( ordering[ 1 ] . expr. eq( & col_c) ) ;
4076
+ assert ! ( ordering[ 1 ] . options. eq( & asc) ) ;
4082
4077
4083
4078
Ok ( ( ) )
4084
4079
}
@@ -4119,7 +4114,8 @@ mod tests {
4119
4114
4120
4115
// Should only contain the new ordering since options don't match
4121
4116
assert_eq ! ( result. oeq_class( ) . len( ) , 1 ) ;
4122
- assert_eq ! ( result. oeq_class( ) . orderings[ 0 ] , new_order) ;
4117
+ let ordering = result. oeq_class ( ) . iter ( ) . next ( ) . unwrap ( ) ;
4118
+ assert_eq ! ( ordering, & new_order) ;
4123
4119
4124
4120
Ok ( ( ) )
4125
4121
}
@@ -4177,7 +4173,7 @@ mod tests {
4177
4173
4178
4174
// Should preserve the original [d ASC, a ASC] ordering
4179
4175
assert_eq ! ( result. oeq_class( ) . len( ) , 1 ) ;
4180
- let ordering = & result. oeq_class ( ) . orderings [ 0 ] ;
4176
+ let ordering = result. oeq_class ( ) . iter ( ) . next ( ) . unwrap ( ) ;
4181
4177
assert_eq ! ( ordering. len( ) , 2 ) ;
4182
4178
4183
4179
// First expression should be either b or d (they're equivalent)
0 commit comments