You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "mingmwang (via GitHub)" <gi...@apache.org> on 2023/05/11 06:15:03 UTC

[GitHub] [arrow-datafusion] mingmwang commented on pull request #6331: refine decimal multiply, avoid cast to wider type

mingmwang commented on PR #6331:
URL: https://github.com/apache/arrow-datafusion/pull/6331#issuecomment-1543398311

   
   ```spark  
   override def resultDecimalType(p1: Int, s1: Int, p2: Int, s2: Int): DecimalType = {
       val resultScale = s1 + s2
       val resultPrecision = p1 + p2 + 1
       if (allowPrecisionLoss) {
         DecimalType.adjustPrecisionScale(resultPrecision, resultScale)
       } else {
         DecimalType.bounded(resultPrecision, resultScale)
       }
     }
   
     private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)
   
     protected override def nullSafeEval(input1: Any, input2: Any): Any = dataType match {
       case DecimalType.Fixed(precision, scale) =>
         checkDecimalOverflow(numeric.times(input1, input2).asInstanceOf[Decimal], precision, scale)
       case _: IntegerType if failOnError =>
         MathUtils.multiplyExact(
           input1.asInstanceOf[Int],
           input2.asInstanceOf[Int],
           getContextOrNull())
       case _: LongType if failOnError =>
         MathUtils.multiplyExact(
           input1.asInstanceOf[Long],
           input2.asInstanceOf[Long],
           getContextOrNull())
       case _ => numeric.times(input1, input2)
     }
   ```


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org