Github user wojtek-szymanski commented on a diff in the pull request: https://github.com/apache/spark/pull/17075#discussion_r103863388 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala --- @@ -339,36 +339,34 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String } /** - * Change the precision / scale in a given decimal to those set in `decimalType` (if any), - * returning null if it overflows or modifying `value` in-place and returning it if successful. + * Create new `Decimal` with precision and scale given in `decimalType` (if any), + * returning null if it overflows or creating a new `value` and returning it if successful. * - * NOTE: this modifies `value` in-place, so don't call it on external data. */ - private[this] def changePrecision(value: Decimal, decimalType: DecimalType): Decimal = { - if (value.changePrecision(decimalType.precision, decimalType.scale)) value else null - } + private[this] def toPrecision(value: Decimal, decimalType: DecimalType): Decimal = + value.toPrecision(decimalType.precision, decimalType.scale).orNull private[this] def castToDecimal(from: DataType, target: DecimalType): Any => Any = from match { case StringType => buildCast[UTF8String](_, s => try { - changePrecision(Decimal(new JavaBigDecimal(s.toString)), target) + toPrecision(Decimal(new JavaBigDecimal(s.toString)), target) --- End diff -- agree
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org