Search in sources :

Example 1 with PercentileAgg

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg in project hive by apache.

the class TestGenericUDAFPercentileCont method checkPercentile.

@SuppressWarnings({ "unchecked", "resource" })
private void checkPercentile(Double[] items, double percentile, double expected) throws Exception {
    PercentileContDoubleEvaluator eval = new GenericUDAFPercentileCont.PercentileContDoubleEvaluator();
    PercentileAgg agg = new PercentileContLongEvaluator().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 : PercentileContDoubleEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContDoubleEvaluator) PercentileContLongEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContLongEvaluator) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) PercentileAgg(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg)

Example 2 with PercentileAgg

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg in project hive by apache.

the class TestGenericUDAFPercentileCont method checkPercentile.

@SuppressWarnings({ "unchecked", "resource" })
private void checkPercentile(Long[] items, double percentile, double expected) throws Exception {
    PercentileContLongEvaluator eval = new GenericUDAFPercentileCont.PercentileContLongEvaluator();
    PercentileAgg agg = new PercentileContLongEvaluator().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 LongWritable(items[i]), 1);
    }
    DoubleWritable result = (DoubleWritable) eval.terminate(agg);
    Assert.assertEquals(expected, result.get(), 0.01);
    eval.close();
}
Also used : PercentileContLongEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContLongEvaluator) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) PercentileAgg(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg)

Example 3 with PercentileAgg

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg in project hive by apache.

the class TestGenericUDAFPercentileDisc method checkPercentile.

private void checkPercentile(Long[] items, double percentile, double expected) throws Exception {
    PercentileContLongEvaluator eval = new GenericUDAFPercentileDisc.PercentileDiscLongEvaluator();
    PercentileAgg agg = new PercentileContLongEvaluator().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 LongWritable(items[i]), 1);
    }
    DoubleWritable result = (DoubleWritable) eval.terminate(agg);
    Assert.assertEquals(expected, result.get(), 0.01);
    eval.close();
}
Also used : PercentileContLongEvaluator(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContLongEvaluator) DoubleWritable(org.apache.hadoop.hive.serde2.io.DoubleWritable) LongWritable(org.apache.hadoop.io.LongWritable) PercentileAgg(org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg)

Example 4 with PercentileAgg

use of org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContEvaluator.PercentileAgg 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)4 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)4 PercentileContLongEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContLongEvaluator)3 LongWritable (org.apache.hadoop.io.LongWritable)2 PercentileContDoubleEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileCont.PercentileContDoubleEvaluator)1 PercentileDiscDoubleEvaluator (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFPercentileDisc.PercentileDiscDoubleEvaluator)1