@@ -29,9 +29,7 @@ use arrow::datatypes::{
2929 DECIMAL128_MAX_SCALE , DECIMAL256_MAX_PRECISION , DECIMAL256_MAX_SCALE ,
3030} ;
3131use datafusion_common:: types:: NativeType ;
32- use datafusion_common:: {
33- exec_datafusion_err, exec_err, internal_err, plan_datafusion_err, plan_err, Result ,
34- } ;
32+ use datafusion_common:: { exec_err, internal_err, plan_datafusion_err, plan_err, Result } ;
3533use itertools:: Itertools ;
3634
3735/// The type signature of an instantiation of binary operator expression such as
@@ -869,54 +867,6 @@ fn get_wider_decimal_type(
869867 }
870868}
871869
872- /// Returns the wider type among arguments `lhs` and `rhs`.
873- /// The wider type is the type that can safely represent values from both types
874- /// without information loss. Returns an Error if types are incompatible.
875- pub fn get_wider_type ( lhs : & DataType , rhs : & DataType ) -> Result < DataType > {
876- use arrow:: datatypes:: DataType :: * ;
877- Ok ( match ( lhs, rhs) {
878- ( lhs, rhs) if lhs == rhs => lhs. clone ( ) ,
879- // Right UInt is larger than left UInt.
880- ( UInt8 , UInt16 | UInt32 | UInt64 ) | ( UInt16 , UInt32 | UInt64 ) | ( UInt32 , UInt64 ) |
881- // Right Int is larger than left Int.
882- ( Int8 , Int16 | Int32 | Int64 ) | ( Int16 , Int32 | Int64 ) | ( Int32 , Int64 ) |
883- // Right Float is larger than left Float.
884- ( Float16 , Float32 | Float64 ) | ( Float32 , Float64 ) |
885- // Right String is larger than left String.
886- ( Utf8 , LargeUtf8 ) |
887- // Any right type is wider than a left hand side Null.
888- ( Null , _) => rhs. clone ( ) ,
889- // Left UInt is larger than right UInt.
890- ( UInt16 | UInt32 | UInt64 , UInt8 ) | ( UInt32 | UInt64 , UInt16 ) | ( UInt64 , UInt32 ) |
891- // Left Int is larger than right Int.
892- ( Int16 | Int32 | Int64 , Int8 ) | ( Int32 | Int64 , Int16 ) | ( Int64 , Int32 ) |
893- // Left Float is larger than right Float.
894- ( Float32 | Float64 , Float16 ) | ( Float64 , Float32 ) |
895- // Left String is larger than right String.
896- ( LargeUtf8 , Utf8 ) |
897- // Any left type is wider than a right hand side Null.
898- ( _, Null ) => lhs. clone ( ) ,
899- ( List ( lhs_field) , List ( rhs_field) ) => {
900- let field_type =
901- get_wider_type ( lhs_field. data_type ( ) , rhs_field. data_type ( ) ) ?;
902- if lhs_field. name ( ) != rhs_field. name ( ) {
903- return Err ( exec_datafusion_err ! (
904- "There is no wider type that can represent both {lhs} and {rhs}."
905- ) ) ;
906- }
907- assert_eq ! ( lhs_field. name( ) , rhs_field. name( ) ) ;
908- let field_name = lhs_field. name ( ) ;
909- let nullable = lhs_field. is_nullable ( ) | rhs_field. is_nullable ( ) ;
910- List ( Arc :: new ( Field :: new ( field_name, field_type, nullable) ) )
911- }
912- ( _, _) => {
913- return Err ( exec_datafusion_err ! (
914- "There is no wider type that can represent both {lhs} and {rhs}."
915- ) ) ;
916- }
917- } )
918- }
919-
920870/// Convert the numeric data type to the decimal data type.
921871/// We support signed and unsigned integer types and floating-point type.
922872fn coerce_numeric_type_to_decimal ( numeric_type : & DataType ) -> Option < DataType > {
0 commit comments