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

    https://github.com/apache/spark/pull/8018#discussion_r36581818
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala ---
    @@ -261,60 +178,52 @@ final class Decimal extends Ordered[Decimal] with 
Serializable {
     
       override def hashCode(): Int = toBigDecimal.hashCode()
     
    -  def isZero: Boolean = if (decimalVal.ne(null)) decimalVal == 
BIG_DEC_ZERO else longVal == 0
    +  def isZero: Boolean = {
    +    decimalVal.compareTo(BIG_DEC_ZERO) == 0
    +  }
     
       def + (that: Decimal): Decimal = {
    -    if (decimalVal.eq(null) && that.decimalVal.eq(null) && scale == 
that.scale) {
    -      Decimal(longVal + that.longVal, Math.max(precision, that.precision), 
scale)
    -    } else {
    -      Decimal(toBigDecimal + that.toBigDecimal, precision, scale)
    -    }
    +    Decimal(toJavaBigDecimal.add(that.toJavaBigDecimal, MATH_CONTEXT), 
precision, scale)
       }
     
       def - (that: Decimal): Decimal = {
    -    if (decimalVal.eq(null) && that.decimalVal.eq(null) && scale == 
that.scale) {
    -      Decimal(longVal - that.longVal, Math.max(precision, that.precision), 
scale)
    -    } else {
    -      Decimal(toBigDecimal - that.toBigDecimal, precision, scale)
    -    }
    +    Decimal(toJavaBigDecimal.subtract(that.toJavaBigDecimal, 
MATH_CONTEXT), precision, scale)
       }
     
       // HiveTypeCoercion will take care of the precision, scale of result
    -  def * (that: Decimal): Decimal = Decimal(toBigDecimal * 
that.toBigDecimal)
    +  def * (that: Decimal): Decimal = {
    +    Decimal(toJavaBigDecimal.multiply(that.toJavaBigDecimal, MATH_CONTEXT))
    +  }
     
    -  def / (that: Decimal): Decimal =
    -    if (that.isZero) null else Decimal(toBigDecimal / that.toBigDecimal)
    +  def / (that: Decimal): Decimal = {
    +    if (that.isZero) null
    +    else Decimal(toJavaBigDecimal.divide(that.toJavaBigDecimal, 
MATH_CONTEXT))
    +  }
     
    -  def % (that: Decimal): Decimal =
    -    if (that.isZero) null else Decimal(toBigDecimal % that.toBigDecimal)
    +  def % (that: Decimal): Decimal = {
    +    if (that.isZero) null else 
Decimal(toJavaBigDecimal.remainder(that.toJavaBigDecimal))
    +  }
     
       def remainder(that: Decimal): Decimal = this % that
     
       def unary_- : Decimal = {
    -    if (decimalVal.ne(null)) {
    -      Decimal(-decimalVal, precision, scale)
    -    } else {
    -      Decimal(-longVal, precision, scale)
    -    }
    +    Decimal(decimalVal.negate(), precision, scale)
       }
     
       def abs: Decimal = if (this.compare(Decimal.ZERO) < 0) this.unary_- else 
this
     }
     
     object Decimal {
    -  private val ROUNDING_MODE = BigDecimal.RoundingMode.HALF_UP
    -
       /** Maximum number of decimal digits a Long can represent */
       val MAX_LONG_DIGITS = 18
    --- End diff --
    
    It looks like this is now unused if you remove `POW_10`?


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to