Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20350#discussion_r182820983
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/decimalExpressions.scala
 ---
    @@ -80,30 +80,44 @@ case class PromotePrecision(child: Expression) extends 
UnaryExpression {
     
     /**
      * Rounds the decimal to given scale and check whether the decimal can fit 
in provided precision
    - * or not, returns null if not.
    + * or not. If not, if `nullOnOverflow` is `true`, it returns `null`; 
otherwise an
    + * `ArithmeticException` is thrown.
      */
    -case class CheckOverflow(child: Expression, dataType: DecimalType) extends 
UnaryExpression {
    +case class CheckOverflow(
    +    child: Expression,
    +    dataType: DecimalType,
    +    nullOnOverflow: Boolean) extends UnaryExpression {
     
       override def nullable: Boolean = true
     
       override def nullSafeEval(input: Any): Any =
    -    input.asInstanceOf[Decimal].toPrecision(dataType.precision, 
dataType.scale)
    +    input.asInstanceOf[Decimal].toPrecision(
    +      dataType.precision,
    +      dataType.scale,
    +      Decimal.ROUND_HALF_UP,
    +      nullOnOverflow)
     
       override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): 
ExprCode = {
         nullSafeCodeGen(ctx, ev, eval => {
           val tmp = ctx.freshName("tmp")
    +      val onOverflow = if (nullOnOverflow) {
    --- End diff --
    
    Why are you not just calling `Decimal.toPrecision`  here? There seems to be 
very little value in code generating this (no specialization).


---

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

Reply via email to