@@ -708,6 +708,31 @@ pub fn try_type_union_resolution_with_struct(
708708/// strings. For example when comparing `'2' > 1`, the arguments will be
709709/// coerced to `Utf8` for comparison
710710pub fn comparison_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
711+ if lhs_type == rhs_type {
712+ // same type => equality is possible
713+ return Some ( lhs_type. clone ( ) ) ;
714+ }
715+ binary_numeric_coercion ( lhs_type, rhs_type)
716+ . or_else ( || number_boolean_coercion ( lhs_type, rhs_type) )
717+ . or_else ( || dictionary_comparison_coercion ( lhs_type, rhs_type, true ) )
718+ . or_else ( || temporal_coercion_nonstrict_timezone ( lhs_type, rhs_type) )
719+ . or_else ( || string_coercion ( lhs_type, rhs_type) )
720+ . or_else ( || list_coercion ( lhs_type, rhs_type) )
721+ . or_else ( || null_coercion ( lhs_type, rhs_type) )
722+ // TODO upgrade DF: Look at non-comparison coercions and figure out desirable behavior
723+ . or_else ( || string_numeric_coercion_as_numeric ( lhs_type, rhs_type) )
724+ . or_else ( || string_boolean_coercion ( lhs_type, rhs_type) )
725+ . or_else ( || string_temporal_coercion ( lhs_type, rhs_type) )
726+ . or_else ( || binary_coercion ( lhs_type, rhs_type) )
727+ . or_else ( || struct_coercion ( lhs_type, rhs_type) )
728+ }
729+
730+ /// Cube: DF 46 had case expressions use comparison_coercion to find the common type for the value
731+ /// expression. We changed comparison_coercion but for case value expressions we want
732+ /// string_numeric_coercion to be used.
733+ //
734+ // TODO upgrade DF: What behavior do we want for numeric_boolean and string_boolean coercion here? Probably boolean->string
735+ pub fn case_value_comparison_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
711736 if lhs_type == rhs_type {
712737 // same type => equality is possible
713738 return Some ( lhs_type. clone ( ) ) ;
@@ -726,6 +751,10 @@ pub fn comparison_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<D
726751 . or_else ( || struct_coercion ( lhs_type, rhs_type) )
727752}
728753
754+ pub fn union_value_comparison_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Option < DataType > {
755+ case_value_comparison_coercion ( lhs_type, rhs_type)
756+ }
757+
729758/// Similar to [`comparison_coercion`] but prefers numeric if compares with
730759/// numeric and string
731760///
@@ -1630,7 +1659,9 @@ mod tests {
16301659 let rhs_type = Dictionary ( Box :: new ( Int8 ) , Box :: new ( Int16 ) ) ;
16311660 assert_eq ! (
16321661 dictionary_comparison_coercion( & lhs_type, & rhs_type, true ) ,
1633- Some ( Utf8 )
1662+ // Cube: We switched the direction of int/numeric comparison coercion
1663+ Some ( Int16 )
1664+ // Some(Utf8)
16341665 ) ;
16351666
16361667 // Since we can coerce values of Utf8 to Binary can support this
0 commit comments