@Override public Object convert(Object input) { if (input == null) { return null; } return outputOI.set(r, PrimitiveObjectInspectorUtils.getHiveDecimal(input, inputOI)); } }
@Override protected void doIterate(AverageAggregationBuffer<HiveDecimal> aggregation, PrimitiveObjectInspector oi, Object parameter) { HiveDecimal value = PrimitiveObjectInspectorUtils.getHiveDecimal(parameter, oi); aggregation.count++; if (aggregation.sum != null) { aggregation.sum = aggregation.sum.add(value); } }
@Override protected void doIterate(AverageAggregationBuffer<HiveDecimal> aggregation, PrimitiveObjectInspector oi, Object parameter) { HiveDecimal value = PrimitiveObjectInspectorUtils.getHiveDecimal(parameter, oi); aggregation.count++; if (aggregation.sum != null) { aggregation.sum = aggregation.sum.add(value); } }
@Override public boolean isEqual(Object v1, Object v2) { HiveDecimal d1 = PrimitiveObjectInspectorUtils.getHiveDecimal(v1, (PrimitiveObjectInspector) expressionDef.getOI()); HiveDecimal d2 = PrimitiveObjectInspectorUtils.getHiveDecimal(v2, (PrimitiveObjectInspector) expressionDef.getOI()); if ( d1 != null && d2 != null ) { return d1.equals(d2); } return d1 == null && d2 == null; // True if both are null } }
@Override public boolean isEqual(Object v1, Object v2) { HiveDecimal d1 = PrimitiveObjectInspectorUtils.getHiveDecimal(v1, (PrimitiveObjectInspector) expressionDef.getOI()); HiveDecimal d2 = PrimitiveObjectInspectorUtils.getHiveDecimal(v2, (PrimitiveObjectInspector) expressionDef.getOI()); if ( d1 != null && d2 != null ) { return d1.equals(d2); } return d1 == null && d2 == null; // True if both are null } }
@Override public boolean isDistanceGreater(Object v1, Object v2, int amt) { HiveDecimal d1 = PrimitiveObjectInspectorUtils.getHiveDecimal(v1, (PrimitiveObjectInspector) expressionDef.getOI()); HiveDecimal d2 = PrimitiveObjectInspectorUtils.getHiveDecimal(v2, (PrimitiveObjectInspector) expressionDef.getOI()); if ( d1 != null && d2 != null ) { return d1.subtract(d2).intValue() > amt; // TODO: lossy conversion! } return d1 != null || d2 != null; // True if only one value is null }
@Override protected void doMergeAdd( HiveDecimal sum, ObjectInspectorObject obj) { sum.add(PrimitiveObjectInspectorUtils.getHiveDecimal(obj.getValues()[0], copiedOI)); }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 1); try { if (isEligibleValue((SumHiveDecimalWritableAgg) agg, parameters[0])) { ((SumHiveDecimalWritableAgg)agg).empty = false; ((SumHiveDecimalWritableAgg)agg).sum.mutateAdd( PrimitiveObjectInspectorUtils.getHiveDecimal(parameters[0], inputOI)); } } catch (NumberFormatException e) { if (!warned) { warned = true; LOG.warn(getClass().getSimpleName() + " " + StringUtils.stringifyException(e)); LOG .warn(getClass().getSimpleName() + " ignoring similar exceptions."); } } }
@Override protected void doMergeAdd( HiveDecimal sum, ObjectInspectorObject obj) { sum.add(PrimitiveObjectInspectorUtils.getHiveDecimal(obj.getValues()[0], copiedOI)); }
@Override public boolean isDistanceGreater(Object v1, Object v2, int amt) { HiveDecimal d1 = PrimitiveObjectInspectorUtils.getHiveDecimal(v1, (PrimitiveObjectInspector) expressionDef.getOI()); HiveDecimal d2 = PrimitiveObjectInspectorUtils.getHiveDecimal(v2, (PrimitiveObjectInspector) expressionDef.getOI()); if ( d1 != null && d2 != null ) { return d1.subtract(d2).intValue() > amt; // TODO: lossy conversion! } return d1 != null || d2 != null; // True if only one value is null }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 1); try { if (isEligibleValue((SumHiveDecimalWritableAgg) agg, parameters[0])) { ((SumHiveDecimalWritableAgg)agg).empty = false; ((SumHiveDecimalWritableAgg)agg).sum.mutateAdd( PrimitiveObjectInspectorUtils.getHiveDecimal(parameters[0], inputOI)); } } catch (NumberFormatException e) { if (!warned) { warned = true; LOG.warn(getClass().getSimpleName() + " " + StringUtils.stringifyException(e)); LOG .warn(getClass().getSimpleName() + " ignoring similar exceptions."); } } }
@Override protected void update(Object p, PrimitiveObjectInspector inputOI) { HiveDecimal v = PrimitiveObjectInspectorUtils.getHiveDecimal(p, inputOI); //Update min counter if new value is less than min seen so far if (min == null || v.compareTo(min) < 0) { min = v; } //Update max counter if new value is greater than max seen so far if (max == null || v.compareTo(max) > 0) { max = v; } // Add value to NumDistinctValue Estimator numDV.addToEstimator(v); }
@Override protected void update(Object p, PrimitiveObjectInspector inputOI) { HiveDecimal v = PrimitiveObjectInspectorUtils.getHiveDecimal(p, inputOI); //Update min counter if new value is less than min seen so far if (min == null || v.compareTo(min) < 0) { min = v; } //Update max counter if new value is greater than max seen so far if (max == null || v.compareTo(max) > 0) { max = v; } // Add value to NumDistinctValue Estimator numDV.addToEstimator(v); }
@Override public void merge(AggregationBuffer agg, Object partial) throws HiveException { if (partial != null) { SumHiveDecimalWritableAgg myagg = (SumHiveDecimalWritableAgg) agg; if (myagg.sum == null || !myagg.sum.isSet()) { return; } myagg.empty = false; if (isWindowingDistinct()) { throw new HiveException("Distinct windowing UDAF doesn't support merge and terminatePartial"); } else { // If partial is NULL, then there was an overflow and myagg.sum will be marked as not set. myagg.sum.mutateAdd(PrimitiveObjectInspectorUtils.getHiveDecimal(partial, inputOI)); } } }
@Override public void evaluate(VectorizedRowBatch batch) throws HiveException { if (!initialized) { Object lVal = leftDynamicValue.getValue(); Object rVal = rightDynamicValue.getValue(); if (lVal == null || rVal == null) { isLeftOrRightNull = true; } else { HiveDecimal min = (PrimitiveObjectInspectorUtils.getHiveDecimal( lVal, leftDynamicValue.getObjectInspector())); setLeftValue(min); HiveDecimal max = (PrimitiveObjectInspectorUtils.getHiveDecimal( rVal, rightDynamicValue.getObjectInspector())); setRightValue(max); } initialized = true; } // Special case for dynamic values - min/max can be null if (isLeftOrRightNull) { // Entire batch is filtered out batch.size = 0; } super.evaluate(batch); } }
@Override public void merge(AggregationBuffer agg, Object partial) throws HiveException { if (partial != null) { SumHiveDecimalWritableAgg myagg = (SumHiveDecimalWritableAgg) agg; if (myagg.sum == null || !myagg.sum.isSet()) { return; } myagg.empty = false; if (isWindowingDistinct()) { throw new HiveException("Distinct windowing UDAF doesn't support merge and terminatePartial"); } else { myagg.sum.mutateAdd(PrimitiveObjectInspectorUtils.getHiveDecimal(partial, inputOI)); } } }
@Override public void evaluate(VectorizedRowBatch batch) { if (!initialized) { Object lVal = leftDynamicValue.getValue(); Object rVal = rightDynamicValue.getValue(); if (lVal == null || rVal == null) { isLeftOrRightNull = true; } else { HiveDecimal min = (PrimitiveObjectInspectorUtils.getHiveDecimal( lVal, leftDynamicValue.getObjectInspector())); setLeftValue(min); HiveDecimal max = (PrimitiveObjectInspectorUtils.getHiveDecimal( rVal, rightDynamicValue.getObjectInspector())); setRightValue(max); } initialized = true; } // Special case for dynamic values - min/max can be null if (isLeftOrRightNull) { // Entire batch is filtered out batch.size = 0; } super.evaluate(batch); } }
HiveDecimal hdLeft = PrimitiveObjectInspectorUtils.getHiveDecimal(left, leftOI); HiveDecimal hdRight = PrimitiveObjectInspectorUtils.getHiveDecimal(right, rightOI); if (hdLeft == null || hdRight == null) { return null;
break; case DECIMAL: decimalValue = PrimitiveObjectInspectorUtils.getHiveDecimal(val, poi); break; case DATE:
break; case DECIMAL: decimalValue = PrimitiveObjectInspectorUtils.getHiveDecimal(val, poi); break; case DATE: