@@ -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
@@ -2204,6 +2225,7 @@ struct UnionEquivalentOrderingBuilder {
22042225 orderings : Vec < LexOrdering > ,
22052226}
22062227
2228+ #[ expect( unused) ]
22072229impl UnionEquivalentOrderingBuilder {
22082230 fn new ( ) -> Self {
22092231 Self { orderings : vec ! [ ] }
@@ -3552,134 +3574,6 @@ mod tests {
35523574 . run ( )
35533575 }
35543576
3555- #[ test]
3556- fn test_union_equivalence_properties_constants_fill_gaps ( ) {
3557- let schema = create_test_schema ( ) . unwrap ( ) ;
3558- UnionEquivalenceTest :: new ( & schema)
3559- . with_child_sort_and_const_exprs (
3560- // First child orderings: [a ASC, c ASC], const [b]
3561- vec ! [ vec![ "a" , "c" ] ] ,
3562- vec ! [ "b" ] ,
3563- & schema,
3564- )
3565- . with_child_sort_and_const_exprs (
3566- // Second child orderings: [b ASC, c ASC], const [a]
3567- vec ! [ vec![ "b" , "c" ] ] ,
3568- vec ! [ "a" ] ,
3569- & schema,
3570- )
3571- . with_expected_sort_and_const_exprs (
3572- // Union orderings: [
3573- // [a ASC, b ASC, c ASC],
3574- // [b ASC, a ASC, c ASC]
3575- // ], const []
3576- vec ! [ vec![ "a" , "b" , "c" ] , vec![ "b" , "a" , "c" ] ] ,
3577- vec ! [ ] ,
3578- )
3579- . run ( )
3580- }
3581-
3582- #[ test]
3583- fn test_union_equivalence_properties_constants_no_fill_gaps ( ) {
3584- let schema = create_test_schema ( ) . unwrap ( ) ;
3585- UnionEquivalenceTest :: new ( & schema)
3586- . with_child_sort_and_const_exprs (
3587- // First child orderings: [a ASC, c ASC], const [d] // some other constant
3588- vec ! [ vec![ "a" , "c" ] ] ,
3589- vec ! [ "d" ] ,
3590- & schema,
3591- )
3592- . with_child_sort_and_const_exprs (
3593- // Second child orderings: [b ASC, c ASC], const [a]
3594- vec ! [ vec![ "b" , "c" ] ] ,
3595- vec ! [ "a" ] ,
3596- & schema,
3597- )
3598- . with_expected_sort_and_const_exprs (
3599- // Union orderings: [[a]] (only a is constant)
3600- vec ! [ vec![ "a" ] ] ,
3601- vec ! [ ] ,
3602- )
3603- . run ( )
3604- }
3605-
3606- #[ test]
3607- fn test_union_equivalence_properties_constants_fill_some_gaps ( ) {
3608- let schema = create_test_schema ( ) . unwrap ( ) ;
3609- UnionEquivalenceTest :: new ( & schema)
3610- . with_child_sort_and_const_exprs (
3611- // First child orderings: [c ASC], const [a, b] // some other constant
3612- vec ! [ vec![ "c" ] ] ,
3613- vec ! [ "a" , "b" ] ,
3614- & schema,
3615- )
3616- . with_child_sort_and_const_exprs (
3617- // Second child orderings: [a DESC, b], const []
3618- vec ! [ vec![ "a DESC" , "b" ] ] ,
3619- vec ! [ ] ,
3620- & schema,
3621- )
3622- . with_expected_sort_and_const_exprs (
3623- // Union orderings: [[a, b]] (can fill in the a/b with constants)
3624- vec ! [ vec![ "a DESC" , "b" ] ] ,
3625- vec ! [ ] ,
3626- )
3627- . run ( )
3628- }
3629-
3630- #[ test]
3631- fn test_union_equivalence_properties_constants_fill_gaps_non_symmetric ( ) {
3632- let schema = create_test_schema ( ) . unwrap ( ) ;
3633- UnionEquivalenceTest :: new ( & schema)
3634- . with_child_sort_and_const_exprs (
3635- // First child orderings: [a ASC, c ASC], const [b]
3636- vec ! [ vec![ "a" , "c" ] ] ,
3637- vec ! [ "b" ] ,
3638- & schema,
3639- )
3640- . with_child_sort_and_const_exprs (
3641- // Second child orderings: [b ASC, c ASC], const [a]
3642- vec ! [ vec![ "b DESC" , "c" ] ] ,
3643- vec ! [ "a" ] ,
3644- & schema,
3645- )
3646- . with_expected_sort_and_const_exprs (
3647- // Union orderings: [
3648- // [a ASC, b ASC, c ASC],
3649- // [b ASC, a ASC, c ASC]
3650- // ], const []
3651- vec ! [ vec![ "a" , "b DESC" , "c" ] , vec![ "b DESC" , "a" , "c" ] ] ,
3652- vec ! [ ] ,
3653- )
3654- . run ( )
3655- }
3656-
3657- #[ test]
3658- fn test_union_equivalence_properties_constants_gap_fill_symmetric ( ) {
3659- let schema = create_test_schema ( ) . unwrap ( ) ;
3660- UnionEquivalenceTest :: new ( & schema)
3661- . with_child_sort_and_const_exprs (
3662- // First child: [a ASC, b ASC, d ASC], const [c]
3663- vec ! [ vec![ "a" , "b" , "d" ] ] ,
3664- vec ! [ "c" ] ,
3665- & schema,
3666- )
3667- . with_child_sort_and_const_exprs (
3668- // Second child: [a ASC, c ASC, d ASC], const [b]
3669- vec ! [ vec![ "a" , "c" , "d" ] ] ,
3670- vec ! [ "b" ] ,
3671- & schema,
3672- )
3673- . with_expected_sort_and_const_exprs (
3674- // Union orderings:
3675- // [a, b, c, d]
3676- // [a, c, b, d]
3677- vec ! [ vec![ "a" , "c" , "b" , "d" ] , vec![ "a" , "b" , "c" , "d" ] ] ,
3678- vec ! [ ] ,
3679- )
3680- . run ( )
3681- }
3682-
36833577 #[ test]
36843578 fn test_union_equivalence_properties_constants_gap_fill_and_common ( ) {
36853579 let schema = create_test_schema ( ) . unwrap ( ) ;
@@ -3705,34 +3599,6 @@ mod tests {
37053599 . run ( )
37063600 }
37073601
3708- #[ test]
3709- fn test_union_equivalence_properties_constants_middle_desc ( ) {
3710- let schema = create_test_schema ( ) . unwrap ( ) ;
3711- UnionEquivalenceTest :: new ( & schema)
3712- . with_child_sort_and_const_exprs (
3713- // NB `b DESC` in the first child
3714- //
3715- // First child: [a ASC, b DESC, d ASC], const [c]
3716- vec ! [ vec![ "a" , "b DESC" , "d" ] ] ,
3717- vec ! [ "c" ] ,
3718- & schema,
3719- )
3720- . with_child_sort_and_const_exprs (
3721- // Second child: [a ASC, c ASC, d ASC], const [b]
3722- vec ! [ vec![ "a" , "c" , "d" ] ] ,
3723- vec ! [ "b" ] ,
3724- & schema,
3725- )
3726- . with_expected_sort_and_const_exprs (
3727- // Union orderings:
3728- // [a, b, d] (c constant)
3729- // [a, c, d] (b constant)
3730- vec ! [ vec![ "a" , "c" , "b DESC" , "d" ] , vec![ "a" , "b DESC" , "c" , "d" ] ] ,
3731- vec ! [ ] ,
3732- )
3733- . run ( )
3734- }
3735-
37363602 // TODO tests with multiple constants
37373603
37383604 #[ derive( Debug ) ]
0 commit comments