cool9850311 commented on code in PR #27474:
URL: https://github.com/apache/datafusion/pull/27474#discussion_r4658163543


##########
datafusion/expr-common/src/type_coercion/binary.rs:
##########
@@ -1269,25 +1227,39 @@ fn get_common_decimal_type(
     other_type: &DataType,
 ) -> Option<DataType> {
     use arrow::datatypes::DataType::*;
-    match decimal_type {
-        Decimal32(_, _) => {
-            let other_decimal_type = 
coerce_numeric_type_to_decimal32(other_type)?;
-            get_wider_decimal_type(decimal_type, &other_decimal_type)
-        }
-        Decimal64(_, _) => {
-            let other_decimal_type = 
coerce_numeric_type_to_decimal64(other_type)?;
-            get_wider_decimal_type(decimal_type, &other_decimal_type)
-        }
-        Decimal128(_, _) => {
-            let other_decimal_type = 
coerce_numeric_type_to_decimal128(other_type)?;
-            get_wider_decimal_type(decimal_type, &other_decimal_type)
-        }
-        Decimal256(_, _) => {
-            let other_decimal_type = 
coerce_numeric_type_to_decimal256(other_type)?;
-            get_wider_decimal_type(decimal_type, &other_decimal_type)
-        }
-        _ => None,
+
+    // How many digits an integer needs is known exactly, so a common type with
+    // no room for them is one no such value casts into.
+    if let Some((integer_precision, integer_scale)) =
+        integer_decimal_precision(other_type)
+    {
+        let (precision, scale) = decimal_precision_and_scale(decimal_type)?;
+        let common_precision = required_decimal_precision(
+            precision,
+            scale,
+            integer_precision,
+            integer_scale,
+        );
+        let common_scale = scale.max(integer_scale);
+        if let Some(variant) = narrowest_decimal_variant(decimal_type, 
common_precision) {

Review Comment:
   Thanks for catching, done fix.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to