Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaido91 committed Apr 20, 2018
1 parent bd8b645 commit d6bc7e9
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,10 @@ case class CheckOverflow(

override protected def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
nullSafeCodeGen(ctx, ev, eval => {
val tmp = ctx.freshName("tmp")
val onOverflow = if (nullOnOverflow) {
s"${ev.isNull} = true"
} else {
s"""throw new ArithmeticException($tmp.toDebugString() + " cannot be represented as " +
| "Decimal(${dataType.precision}, ${dataType.scale}).")""".stripMargin
}
s"""
| Decimal $tmp = $eval.clone();
| if ($tmp.changePrecision(${dataType.precision}, ${dataType.scale})) {
| ${ev.value} = $tmp;
| } else {
| $onOverflow;
| }
|${ev.value} = $eval.toPrecision(
| ${dataType.precision}, ${dataType.scale}, Decimal.ROUND_HALF_UP, $nullOnOverflow);
|${ev.isNull} = ${ev.value} == null;
""".stripMargin
})
}
Expand Down

0 comments on commit d6bc7e9

Please sign in to comment.