XiDuo You created SPARK-39316:
---------------------------------

             Summary: Merge PromotePrecision and CheckOverflow into decimal 
binary arithmetic
                 Key: SPARK-39316
                 URL: https://issues.apache.org/jira/browse/SPARK-39316
             Project: Spark
          Issue Type: Sub-task
          Components: SQL
    Affects Versions: 3.4.0
            Reporter: XiDuo You


Merge `PromotePrecision` into `dataType`, so every arithmetic should report the 
accurate decimal type.

For example, `Add`:
{code:java}
override def dataType: DataType = (left, right) match {
  case (DecimalType.Expression(p1, s1), DecimalType.Expression(p2, s2)) =>
    val resultScale = max(s1, s2)
    if (allowPrecisionLoss) {
      DecimalType.adjustPrecisionScale(max(p1 - s1, p2 - s2) + resultScale + 1,
        resultScale)
    } else {
      DecimalType.bounded(max(p1 - s1, p2 - s2) + resultScale + 1, resultScale)
    }
  case _ => super.dataType
} {code}
Merge `CheckOverflow` into eval and code-gen code path, so every arithmetic can 
handle the overflow case during runtime. 

For example, `Add`:
{code:java}
dataType match {
  case decimalType: DecimalType =>
    val value = numeric.plus(input1, input2)
    checkOverflow(value.asInstanceOf[Decimal], decimalType)
  ...
} {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

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

Reply via email to