You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by cloud-fan <gi...@git.apache.org> on 2017/03/01 00:50:18 UTC

[GitHub] spark pull request #17075: [SPARK-19727][SQL] Fix for round function that mo...

Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17075#discussion_r103588610
  
    --- 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 --
    
    Looks like here we don't need to create a new instance?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org