Search in sources :

Example 1 with PercentileDiscDoubleEvaluator

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileDisc.PercentileDiscDoubleEvaluator in project hive by apache.

the class TestGenericUDAFPercentileDisc method checkPercentile.

@SuppressWarnings({ "unchecked", "resource" })
private void checkPercentile(Double[] items, double percentile, double expected) throws Exception {
    PercentileDiscDoubleEvaluator eval = new GenericUDAFPercentileDisc.PercentileDiscDoubleEvaluator();
    PercentileAgg agg = new PercentileDiscDoubleEvaluator().new PercentileAgg();
    agg.percentiles = new ArrayList<DoubleWritable>();
    agg.percentiles.add(new DoubleWritable(percentile));
    agg.isAscending = true;
    for (int i = 0; i < items.length; i++) {
        eval.increment(agg, new DoubleWritable(items[i]), 1);
    }
    DoubleWritable result = (DoubleWritable) eval.terminate(agg);
    Assert.assertEquals(expected, result.get(), 0.01);
    eval.close();
}
Also used : PercentileDiscDoubleEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileDisc.PercentileDiscDoubleEvaluator) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) PercentileAgg(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg)

Aggregations

PercentileAgg (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg)1 PercentileDiscDoubleEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileDisc.PercentileDiscDoubleEvaluator)1 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)1