@Override protected void doIterate(AverageAggregationBuffer<Double> aggregation, PrimitiveObjectInspector oi, Object parameter) { double value = PrimitiveObjectInspectorUtils.getDouble(parameter, oi); aggregation.count++; aggregation.sum += value; }
/** * Get the float value out of a primitive object. Note that * NullPointerException will be thrown if o is null. Note that * NumberFormatException will be thrown if o is not a valid number. */ public static float getFloat(Object o, PrimitiveObjectInspector oi) { return (float) getDouble(o, oi); }
@Override protected void doIterate(AverageAggregationBuffer<Double> aggregation, PrimitiveObjectInspector oi, Object parameter) { double value = PrimitiveObjectInspectorUtils.getDouble(parameter, oi); aggregation.count++; aggregation.sum += value; }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2); Object px = parameters[0]; Object py = parameters[1]; if (px != null && py != null) { StdAgg myagg = (StdAgg) agg; double vx = PrimitiveObjectInspectorUtils.getDouble(px, xInputOI); double vy = PrimitiveObjectInspectorUtils.getDouble(py, yInputOI); myagg.count++; myagg.yavg = myagg.yavg + (vy - myagg.yavg) / myagg.count; if (myagg.count > 1) { myagg.covar += (vx - myagg.xavg) * (vy - myagg.yavg); } myagg.xavg = myagg.xavg + (vx - myagg.xavg) / myagg.count; } }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2); Object px = parameters[0]; Object py = parameters[1]; if (px != null && py != null) { StdAgg myagg = (StdAgg) agg; double vx = PrimitiveObjectInspectorUtils.getDouble(px, xInputOI); double vy = PrimitiveObjectInspectorUtils.getDouble(py, yInputOI); myagg.count++; myagg.yavg = myagg.yavg + (vy - myagg.yavg) / myagg.count; if (myagg.count > 1) { myagg.covar += (vx - myagg.xavg) * (vy - myagg.yavg); } myagg.xavg = myagg.xavg + (vx - myagg.xavg) / myagg.count; } }
@Override public boolean isDistanceGreater(Object v1, Object v2, int amt) { if (v1 != null && v2 != null) { double d1 = PrimitiveObjectInspectorUtils.getDouble(v1, (PrimitiveObjectInspector) expressionDef.getOI()); double d2 = PrimitiveObjectInspectorUtils.getDouble(v2, (PrimitiveObjectInspector) expressionDef.getOI()); return (d1 -d2) > amt; } return v1 != null || v2 != null; // True if only one value is null }
@Override public boolean isEqual(Object v1, Object v2) { if (v1 != null && v2 != null) { double d1 = PrimitiveObjectInspectorUtils.getDouble(v1, (PrimitiveObjectInspector) expressionDef.getOI()); double d2 = PrimitiveObjectInspectorUtils.getDouble(v2, (PrimitiveObjectInspector) expressionDef.getOI()); return d1 == d2; } return v1 == null && v2 == null; // True if both are null } }
@Override public Object convert(Object input) { if (input == null) { return null; } try { return outputOI.set(r, PrimitiveObjectInspectorUtils.getDouble(input, inputOI)); } catch (NumberFormatException e) { return null; } } }
@Override protected void doMergeAdd(Double sum, ObjectInspectorObject obj) { sum += PrimitiveObjectInspectorUtils.getDouble(obj.getValues()[0], copiedOI); }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2 || parameters.length == 3); if(parameters[0] == null || parameters[1] == null) { return; } PercentileAggBuf myagg = (PercentileAggBuf) agg; // Get and process the current datum double v = PrimitiveObjectInspectorUtils.getDouble(parameters[0], inputOI); myagg.histogram.add(v); }
@Override protected void update(Object p, PrimitiveObjectInspector inputOI) { double v = PrimitiveObjectInspectorUtils.getDouble(p, inputOI); //Update min counter if new value is less than min seen so far if (min == null || v < min) { min = v; } //Update max counter if new value is greater than max seen so far if (max == null || v > max) { max = v; } // Add value to NumDistinctValue Estimator numDV.addToEstimator(v); }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2 || parameters.length == 3); if(parameters[0] == null || parameters[1] == null) { return; } PercentileAggBuf myagg = (PercentileAggBuf) agg; // Get and process the current datum double v = PrimitiveObjectInspectorUtils.getDouble(parameters[0], inputOI); myagg.histogram.add(v); }
@Override protected void doMergeAdd(Double sum, ObjectInspectorObject obj) { sum += PrimitiveObjectInspectorUtils.getDouble(obj.getValues()[0], copiedOI); }
@Override public boolean isDistanceGreater(Object v1, Object v2, int amt) { if (v1 != null && v2 != null) { double d1 = PrimitiveObjectInspectorUtils.getDouble(v1, (PrimitiveObjectInspector) expressionDef.getOI()); double d2 = PrimitiveObjectInspectorUtils.getDouble(v2, (PrimitiveObjectInspector) expressionDef.getOI()); return (d1 -d2) > amt; } return v1 != null || v2 != null; // True if only one value is null }
@Override public boolean isEqual(Object v1, Object v2) { if (v1 != null && v2 != null) { double d1 = PrimitiveObjectInspectorUtils.getDouble(v1, (PrimitiveObjectInspector) expressionDef.getOI()); double d2 = PrimitiveObjectInspectorUtils.getDouble(v2, (PrimitiveObjectInspector) expressionDef.getOI()); return d1 == d2; } return v1 == null && v2 == null; // True if both are null } }
@Override protected void update(Object p, PrimitiveObjectInspector inputOI) { double v = PrimitiveObjectInspectorUtils.getDouble(p, inputOI); //Update min counter if new value is less than min seen so far if (min == null || v < min) { min = v; } //Update max counter if new value is greater than max seen so far if (max == null || v > max) { max = v; } // Add value to NumDistinctValue Estimator numDV.addToEstimator(v); }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 1); try { if (isEligibleValue((SumDoubleAgg) agg, parameters[0])) { ((SumDoubleAgg)agg).empty = false; ((SumDoubleAgg)agg).sum += PrimitiveObjectInspectorUtils.getDouble(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 public void merge(AggregationBuffer agg, Object partial) throws HiveException { if (partial != null) { SumDoubleAgg myagg = (SumDoubleAgg) agg; myagg.empty = false; if (isWindowingDistinct()) { throw new HiveException("Distinct windowing UDAF doesn't support merge and terminatePartial"); } else { myagg.sum += PrimitiveObjectInspectorUtils.getDouble(partial, inputOI); } } }
/** * Compare 2 Primitive Objects with their Object Inspector, conversions * allowed. Note that NULL does not equal to NULL according to SQL standard. */ public static boolean comparePrimitiveObjectsWithConversion(Object o1, PrimitiveObjectInspector oi1, Object o2, PrimitiveObjectInspector oi2) { if (o1 == null || o2 == null) { return false; } if (oi1.getPrimitiveCategory() == oi2.getPrimitiveCategory()) { return comparePrimitiveObjects(o1, oi1, o2, oi2); } // If not equal, convert all to double and compare try { return getDouble(o1, oi1) == getDouble(o2, oi2); } catch (NumberFormatException e) { return false; } }
@Override public void merge(AggregationBuffer agg, Object partial) throws HiveException { if (partial != null) { SumDoubleAgg myagg = (SumDoubleAgg) agg; myagg.empty = false; if (isWindowingDistinct()) { throw new HiveException("Distinct windowing UDAF doesn't support merge and terminatePartial"); } else { myagg.sum += PrimitiveObjectInspectorUtils.getDouble(partial, inputOI); } } }