mingmwang commented on issue #6261:
URL: 
https://github.com/apache/arrow-datafusion/issues/6261#issuecomment-1542367014

   ```rust
   /// Returns the coerced type of applying mathematics operations on decimal 
types.
   /// Two sides of the mathematics operation will be coerced to the same type. 
Note
   /// that we don't coerce the decimal operands in analysis phase, but do it 
in the
   /// execution phase because this is not idempotent.
   pub fn coercion_decimal_mathematics_type(
       mathematics_op: &Operator,
       left_decimal_type: &DataType,
       right_decimal_type: &DataType,
   ) -> Option<DataType> {
       use arrow::datatypes::DataType::*;
       match (left_decimal_type, right_decimal_type) {
           // The promotion rule from spark
           // 
https://github.com/apache/spark/blob/c20af535803a7250fef047c2bf0fe30be242369d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecision.scala#L35
           (Decimal128(_, _), Decimal128(_, _)) => match mathematics_op {
               Operator::Plus | Operator::Minus => decimal_op_mathematics_type(
                   mathematics_op,
                   left_decimal_type,
                   right_decimal_type,
               ),
               Operator::Multiply | Operator::Divide | Operator::Modulo => {
                   get_wider_decimal_type(left_decimal_type, right_decimal_type)
               }
               _ => None,
           },
           _ => None,
       }
   }
   ```


-- 
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]

Reply via email to