@@ -327,6 +327,16 @@ impl<'a> BinaryTypeCoercer<'a> {
327327
328328// TODO Move the rest inside of BinaryTypeCoercer
329329
330+ fn is_decimal ( data_type : & DataType ) -> bool {
331+ matches ! (
332+ data_type,
333+ DataType :: Decimal32 ( ..)
334+ | DataType :: Decimal64 ( ..)
335+ | DataType :: Decimal128 ( ..)
336+ | DataType :: Decimal256 ( ..)
337+ )
338+ }
339+
330340/// Coercion rules for mathematics operators between decimal and non-decimal types.
331341fn math_decimal_coercion (
332342 lhs_type : & DataType ,
@@ -358,7 +368,11 @@ fn math_decimal_coercion(
358368 Some ( ( lhs_type. clone ( ) , rhs_type. clone ( ) ) )
359369 }
360370 // Cross-variant decimal coercion - choose larger variant with appropriate precision/scale
361- ( lhs, rhs) if is_decimal ( lhs) && is_decimal ( rhs) && std:: mem:: discriminant ( lhs) != std:: mem:: discriminant ( rhs) => {
371+ ( lhs, rhs)
372+ if is_decimal ( lhs)
373+ && is_decimal ( rhs)
374+ && std:: mem:: discriminant ( lhs) != std:: mem:: discriminant ( rhs) =>
375+ {
362376 let coerced_type = get_wider_decimal_type_cross_variant ( lhs_type, rhs_type) ?;
363377 Some ( ( coerced_type. clone ( ) , coerced_type) )
364378 }
@@ -1020,6 +1034,11 @@ fn get_wider_decimal_type_cross_variant(
10201034 let range = ( p1 as i8 - s1) . max ( p2 as i8 - s2) ;
10211035 let required_precision = ( range + s) as u8 ;
10221036
1037+ // We currently don't handle cases where the required percision overflows
1038+ if required_precision > DECIMAL256_MAX_PRECISION {
1039+ return None ;
1040+ }
1041+
10231042 // Choose the larger variant between the two input types
10241043 match ( lhs_type, rhs_type) {
10251044 ( Decimal32 ( _, _) , Decimal64 ( _, _) ) | ( Decimal64 ( _, _) , Decimal32 ( _, _) ) => {
0 commit comments