@Override public void reset(AggregationBuffer agg) throws HiveException { StdAgg myagg = (StdAgg) agg; myagg.histogram = new NumericHistogram(); myagg.histogram.reset(); } }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2); if(parameters[0] == null || parameters[1] == null) { return; } StdAgg myagg = (StdAgg) agg; // Parse out the number of histogram bins only once, if we haven't already done // so before. We need at least 2 bins; otherwise, there is no point in creating // a histogram. if(!myagg.histogram.isReady()) { int nbins = PrimitiveObjectInspectorUtils.getInt(parameters[1], nbinsOI); if(nbins < 2) { throw new HiveException(getClass().getSimpleName() + " needs nbins to be at least 2," + " but you supplied " + nbins + "."); } // allocate memory for the histogram bins myagg.histogram.allocate(nbins); } // Process the current data point double v = PrimitiveObjectInspectorUtils.getDouble(parameters[0], inputOI); myagg.histogram.add(v); }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { StdAgg myagg = (StdAgg) agg; if (myagg.histogram.getUsedBins() < 1) { // SQL standard - return null for zero elements return null; } else { ArrayList<DoubleWritable[]> result = new ArrayList<DoubleWritable[]>(); for(int i = 0; i < myagg.histogram.getUsedBins(); i++) { DoubleWritable[] bin = new DoubleWritable[2]; bin[0] = new DoubleWritable(myagg.histogram.getBin(i).x); bin[1] = new DoubleWritable(myagg.histogram.getBin(i).y); result.add(bin); } return result; } }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { PercentileAggBuf myagg = (PercentileAggBuf) agg; if (myagg.histogram.getUsedBins() < 1) { // SQL standard - return null for zero elements return null; } else { assert(myagg.quantiles != null); return new DoubleWritable(myagg.histogram.quantile(myagg.quantiles[0])); } } }
@Override public Object terminatePartial(AggregationBuffer agg) throws HiveException { // Return a single ArrayList where the first element is the number of histogram bins, // and subsequent elements represent histogram (x,y) pairs. StdAgg myagg = (StdAgg) agg; return myagg.histogram.serialize(); }
@Override public void merge(AggregationBuffer agg, Object partial) throws HiveException { if(partial == null) { return; } List<DoubleWritable> partialHistogram = (List<DoubleWritable>) loi.getList(partial); DoubleObjectInspector doi = (DoubleObjectInspector)loi.getListElementObjectInspector(); StdAgg myagg = (StdAgg) agg; myagg.histogram.merge(partialHistogram, doi); }
@Override public AggregationBuffer getNewAggregationBuffer() throws HiveException { PercentileAggBuf result = new PercentileAggBuf(); result.histogram = new NumericHistogram(); reset(result); return result; }
@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 public void reset(AggregationBuffer agg) throws HiveException { PercentileAggBuf result = (PercentileAggBuf) agg; result.histogram.reset(); result.quantiles = null; } }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { PercentileAggBuf myagg = (PercentileAggBuf) agg; if (myagg.histogram.getUsedBins() < 1) { // SQL standard - return null for zero elements return null; } else { assert(myagg.quantiles != null); return new DoubleWritable(myagg.histogram.quantile(myagg.quantiles[0])); } } }
@Override public Object terminatePartial(AggregationBuffer agg) throws HiveException { // Return a single ArrayList where the first element is the number of histogram bins, // and subsequent elements represent histogram (x,y) pairs. StdAgg myagg = (StdAgg) agg; return myagg.histogram.serialize(); }
@Override public void merge(AggregationBuffer agg, Object partial) throws HiveException { if(partial == null) { return; } List<DoubleWritable> partialHistogram = (List<DoubleWritable>) loi.getList(partial); DoubleObjectInspector doi = (DoubleObjectInspector)loi.getListElementObjectInspector(); StdAgg myagg = (StdAgg) agg; myagg.histogram.merge(partialHistogram, doi); }
@Override public AggregationBuffer getNewAggregationBuffer() throws HiveException { PercentileAggBuf result = new PercentileAggBuf(); result.histogram = new NumericHistogram(); reset(result); return result; }
@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 public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { assert (parameters.length == 2); if(parameters[0] == null || parameters[1] == null) { return; } StdAgg myagg = (StdAgg) agg; // Parse out the number of histogram bins only once, if we haven't already done // so before. We need at least 2 bins; otherwise, there is no point in creating // a histogram. if(!myagg.histogram.isReady()) { int nbins = PrimitiveObjectInspectorUtils.getInt(parameters[1], nbinsOI); if(nbins < 2) { throw new HiveException(getClass().getSimpleName() + " needs nbins to be at least 2," + " but you supplied " + nbins + "."); } // allocate memory for the histogram bins myagg.histogram.allocate(nbins); } // Process the current data point double v = PrimitiveObjectInspectorUtils.getDouble(parameters[0], inputOI); myagg.histogram.add(v); }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { PercentileAggBuf myagg = (PercentileAggBuf) agg; if (myagg.histogram.getUsedBins() < 1) { // SQL standard - return null for zero elements return null; } else { ArrayList<DoubleWritable> result = new ArrayList<DoubleWritable>(); assert(myagg.quantiles != null); for(int i = 0; i < myagg.quantiles.length; i++) { result.add(new DoubleWritable(myagg.histogram.quantile(myagg.quantiles[i]))); } return result; } } }
@Override public void reset(AggregationBuffer agg) throws HiveException { StdAgg myagg = (StdAgg) agg; myagg.histogram = new NumericHistogram(); myagg.histogram.reset(); } }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { StdAgg myagg = (StdAgg) agg; if (myagg.histogram.getUsedBins() < 1) { // SQL standard - return null for zero elements return null; } else { ArrayList<DoubleWritable[]> result = new ArrayList<DoubleWritable[]>(); for(int i = 0; i < myagg.histogram.getUsedBins(); i++) { DoubleWritable[] bin = new DoubleWritable[2]; bin[0] = new DoubleWritable(myagg.histogram.getBin(i).x); bin[1] = new DoubleWritable(myagg.histogram.getBin(i).y); result.add(bin); } return result; } }