Github user davies commented on the pull request:

    https://github.com/apache/spark/pull/8409#issuecomment-134491791
  
    @chenghao-intel Yes. 
    
    This is how precision of division is determined in Hive:
    ```
      /**
       * A balanced way to determine the precision/scale of decimal division 
result. Integer digits and
       * decimal digits are computed independently. However, when the precision 
from above reaches above
       * HiveDecimal.MAX_PRECISION, interger digit and decimal digits are 
shrunk equally to fit.
       */
      @Override
      protected DecimalTypeInfo deriveResultDecimalTypeInfo(int prec1, int 
scale1, int prec2, int scale2) {
        int intDig = Math.min(HiveDecimal.MAX_SCALE, prec1 - scale1 + scale2);
        int decDig = Math.min(HiveDecimal.MAX_SCALE, Math.max(6, scale1 + prec2 
+ 1));
        int diff = intDig + decDig -  HiveDecimal.MAX_SCALE;
        if (diff > 0) {
          decDig -= diff/2 + 1; // Slight negative bias.
          intDig = HiveDecimal.MAX_SCALE - decDig;
        }
        return TypeInfoFactory.getDecimalTypeInfo(intDig + decDig, decDig);
      }
    ```


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