Exemplo n.º 1
0
 public static PrimitiveTypeInfo deriveMinArgumentCast(
     ExprNodeDesc childExpr, TypeInfo targetType) {
   assert targetType instanceof PrimitiveTypeInfo : "Not a primitive type" + targetType;
   PrimitiveTypeInfo pti = (PrimitiveTypeInfo) targetType;
   // We only do the minimum cast for decimals. Other types are assumed safe; fix if needed.
   // We also don't do anything for non-primitive children (maybe we should assert).
   if ((pti.getPrimitiveCategory() != PrimitiveCategory.DECIMAL)
       || (!(childExpr.getTypeInfo() instanceof PrimitiveTypeInfo))) return pti;
   PrimitiveTypeInfo childTi = (PrimitiveTypeInfo) childExpr.getTypeInfo();
   // If the child is also decimal, no cast is needed (we hope - can target type be narrower?).
   return HiveDecimalUtils.getDecimalTypeForPrimitiveCategory(childTi);
 }
Exemplo n.º 2
0
    @Override
    public Object terminate(AggregationBuffer agg) throws HiveException {
      SumHiveDecimalAgg myagg = (SumHiveDecimalAgg) agg;
      if (myagg.empty || myagg.sum == null) {
        return null;
      }
      if (myagg.sum != null) {
        if (HiveDecimalUtils.enforcePrecisionScale(
                myagg.sum, (DecimalTypeInfo) outputOI.getTypeInfo())
            == null) {
          LOG.warn("The sum of a column with data type HiveDecimal is out of range");
          return null;
        }
      }

      result.set(myagg.sum);
      return result;
    }