protected DecimalTypeInfo adjustPrecScale(int precision, int scale) {
    // Assumptions:
    // precision >= scale
    // scale >= 0

    if (precision <= HiveDecimal.MAX_PRECISION) {
      // Adjustment only needed when we exceed max precision
      return new DecimalTypeInfo(precision, scale);
    }

    // Precision/scale exceed maximum precision. Result must be adjusted to HiveDecimal.MAX_PRECISION.
    // See https://blogs.msdn.microsoft.com/sqlprogrammability/2006/03/29/multiplication-and-division-with-numerics/
    int intDigits = precision - scale;
    // If original scale less than 6, use original scale value; otherwise preserve at least 6 fractional digits
    int minScaleValue = Math.min(scale, MINIMUM_ADJUSTED_SCALE);
    int adjustedScale = HiveDecimal.MAX_PRECISION - intDigits;
    adjustedScale = Math.max(adjustedScale, minScaleValue);

    return new DecimalTypeInfo(HiveDecimal.MAX_PRECISION, adjustedScale);
  }
Create DecimalTypeInfo from input precision/scale, adjusting if necessary to fit max precision
@param precision precision value before adjustment
@param scale scale value before adjustment
@return
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBaseNumeric.java