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

    https://github.com/apache/spark/pull/15154#discussion_r79918976
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala ---
    @@ -242,10 +242,30 @@ final class Decimal extends Ordered[Decimal] with 
Serializable {
           if (scale < _scale) {
             // Easier case: we just need to divide our scale down
             val diff = _scale - scale
    -        val droppedDigits = longVal % POW_10(diff)
    -        longVal /= POW_10(diff)
    -        if (math.abs(droppedDigits) * 2 >= POW_10(diff)) {
    -          longVal += (if (longVal < 0) -1L else 1L)
    +        val pow10diff = POW_10(diff)
    +        // % and / always round to 0
    +        val droppedDigits = longVal % pow10diff
    +        longVal /= pow10diff
    +        roundMode match {
    +          case ROUND_FLOOR =>
    +            if (droppedDigits < 0) {
    +              longVal += -1L
    +            }
    +          case ROUND_CEILING =>
    +            if (droppedDigits > 0) {
    +              longVal += 1L
    +            }
    +          case ROUND_HALF_UP =>
    +            if (math.abs(droppedDigits) * 2 >= pow10diff) {
    +              longVal += (if (longVal < 0) -1L else 1L)
    --- End diff --
    
    Good catch, we should use droppedDigits here.


---
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

Reply via email to