Search in sources :

Example 1 with HistogramWithBucketing

use of co.cask.cdap.dq.functions.HistogramWithBucketing in project cdap by caskdata.

the class AggregationFunctionsTest method histogramWithBucketingTest.

@Test
public void histogramWithBucketingTest() throws Exception {
    DataQualityWritable val1 = new DataQualityWritable();
    DataQualityWritable val2 = new DataQualityWritable();
    DataQualityWritable val3 = new DataQualityWritable();
    DataQualityWritable val4 = new DataQualityWritable();
    DataQualityWritable val5 = new DataQualityWritable();
    DataQualityWritable val6 = new DataQualityWritable();
    DataQualityWritable val7 = new DataQualityWritable();
    DataQualityWritable val8 = new DataQualityWritable();
    val1.set(new IntWritable(2));
    val2.set(new IntWritable(3));
    val3.set(new IntWritable(4));
    val4.set(new IntWritable(16));
    val5.set(new IntWritable(16));
    val6.set(new IntWritable(26));
    val7.set(new IntWritable(46));
    val8.set(new IntWritable(56));
    HistogramWithBucketing histogramWithBucketing = new HistogramWithBucketing();
    histogramWithBucketing.add(val1);
    histogramWithBucketing.add(val2);
    histogramWithBucketing.add(val3);
    histogramWithBucketing.add(val4);
    histogramWithBucketing.add(val5);
    histogramWithBucketing.add(val6);
    histogramWithBucketing.add(val7);
    histogramWithBucketing.add(val8);
    histogramWithBucketing.aggregate();
    Map<Map.Entry<Double, Double>, Long> expectedMap = new HashMap<>();
    Map.Entry<Double, Double> expectedMapEntry = new AbstractMap.SimpleEntry<>(2.0, 86.0);
    expectedMap.put(expectedMapEntry, new Long(8));
    Assert.assertEquals(histogramWithBucketing.histogram, expectedMap);
}
Also used : HistogramWithBucketing(co.cask.cdap.dq.functions.HistogramWithBucketing) HashMap(java.util.HashMap) DataQualityWritable(co.cask.cdap.dq.DataQualityWritable) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Aggregations

DataQualityWritable (co.cask.cdap.dq.DataQualityWritable)1 HistogramWithBucketing (co.cask.cdap.dq.functions.HistogramWithBucketing)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IntWritable (org.apache.hadoop.io.IntWritable)1 Test (org.junit.Test)1