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 2015/12/10 10:20:43 UTC

[GitHub] spark pull request: [SPARK-10215] [SQL] Fix precision of division ...

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

    https://github.com/apache/spark/pull/8415#discussion_r47203695
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala ---
    @@ -400,8 +400,15 @@ object HiveTypeCoercion {
                 resultType)
     
             case Divide(e1 @ DecimalType.Expression(p1, s1), e2 @ DecimalType.Expression(p2, s2)) =>
    -          val resultType = DecimalType.bounded(p1 - s1 + s2 + max(6, s1 + p2 + 1),
    -            max(6, s1 + p2 + 1))
    +          var intDig = min(DecimalType.MAX_SCALE, p1 - s1 + s2)
    +          var decDig = min(DecimalType.MAX_SCALE, max(6, s1 + p2 + 1))
    +          val diff = (intDig + decDig) - DecimalType.MAX_SCALE
    +          if (diff > 0) {
    +            decDig -= diff / 2 + 1
    +            intDig = DecimalType.MAX_SCALE - decDig
    +            DecimalType.bounded(intDig + decDig, decDig)
    +          }
    +          val resultType = DecimalType.bounded(intDig + decDig, decDig)
               val widerType = widerDecimalType(p1, s1, p2, s2)
    --- End diff --
    
    is the `resultType` always tighter than `widerType`?


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