@@ -2148,17 +2148,38 @@ fn calculate_union_binary(
21482148 } )
21492149 . collect :: < Vec < _ > > ( ) ;
21502150
2151+ // TEMP HACK WORKAROUND
2152+ // Revert code from https://github.com/apache/datafusion/pull/12562
2153+ // Context: https://github.com/apache/datafusion/issues/13748
2154+ // Context: https://github.com/influxdata/influxdb_iox/issues/13038
2155+
21512156 // Next, calculate valid orderings for the union by searching for prefixes
21522157 // in both sides.
2153- let mut orderings = UnionEquivalentOrderingBuilder :: new ( ) ;
2154- orderings. add_satisfied_orderings ( lhs. normalized_oeq_class ( ) , lhs. constants ( ) , & rhs) ;
2155- orderings. add_satisfied_orderings ( rhs. normalized_oeq_class ( ) , rhs. constants ( ) , & lhs) ;
2156- let orderings = orderings. build ( ) ;
2157-
2158- let mut eq_properties =
2159- EquivalenceProperties :: new ( lhs. schema ) . with_constants ( constants) ;
2160-
2158+ let mut orderings = vec ! [ ] ;
2159+ for mut ordering in lhs. normalized_oeq_class ( ) . into_iter ( ) {
2160+ // Progressively shorten the ordering to search for a satisfied prefix:
2161+ while !rhs. ordering_satisfy ( & ordering) {
2162+ ordering. pop ( ) ;
2163+ }
2164+ // There is a non-trivial satisfied prefix, add it as a valid ordering:
2165+ if !ordering. is_empty ( ) {
2166+ orderings. push ( ordering) ;
2167+ }
2168+ }
2169+ for mut ordering in rhs. normalized_oeq_class ( ) . into_iter ( ) {
2170+ // Progressively shorten the ordering to search for a satisfied prefix:
2171+ while !lhs. ordering_satisfy ( & ordering) {
2172+ ordering. pop ( ) ;
2173+ }
2174+ // There is a non-trivial satisfied prefix, add it as a valid ordering:
2175+ if !ordering. is_empty ( ) {
2176+ orderings. push ( ordering) ;
2177+ }
2178+ }
2179+ let mut eq_properties = EquivalenceProperties :: new ( lhs. schema ) ;
2180+ eq_properties. constants = constants;
21612181 eq_properties. add_new_orderings ( orderings) ;
2182+
21622183 Ok ( eq_properties)
21632184}
21642185
0 commit comments