Search in sources :

Example 1 with DataQualityWritable

use of co.cask.cdap.dq.DataQualityWritable in project cdap by caskdata.

the class AggregationFunctionsTest method uniqueValuesGenerateAggregationTest.

@Test
public void uniqueValuesGenerateAggregationTest() throws Exception {
    DataQualityWritable val1 = new DataQualityWritable();
    DataQualityWritable val2 = new DataQualityWritable();
    DataQualityWritable val3 = new DataQualityWritable();
    val1.set(new Text("a"));
    val2.set(new Text("a"));
    val3.set(new Text("a"));
    UniqueValues uniqueValues = new UniqueValues();
    uniqueValues.add(val1);
    uniqueValues.add(val2);
    uniqueValues.add(val3);
    byte[] output = uniqueValues.aggregate();
    Assert.assertEquals("[a]", Bytes.toString(output));
}
Also used : Text(org.apache.hadoop.io.Text) DataQualityWritable(co.cask.cdap.dq.DataQualityWritable) UniqueValues(co.cask.cdap.dq.functions.UniqueValues) Test(org.junit.Test)

Example 2 with DataQualityWritable

use of co.cask.cdap.dq.DataQualityWritable in project cdap by caskdata.

the class AggregationFunctionsTest method discreteValuesGenerateAggregationTest.

@Test
public void discreteValuesGenerateAggregationTest() throws Exception {
    DataQualityWritable val1 = new DataQualityWritable();
    DataQualityWritable val2 = new DataQualityWritable();
    DataQualityWritable val3 = new DataQualityWritable();
    val1.set(new Text("a"));
    val2.set(new Text("a"));
    val3.set(new Text("b"));
    DiscreteValuesHistogram discreteValuesHistogram = new DiscreteValuesHistogram();
    discreteValuesHistogram.add(val1);
    discreteValuesHistogram.add(val2);
    discreteValuesHistogram.add(val3);
    Map<String, Integer> expectedMap = Maps.newHashMap();
    expectedMap.put("a", 2);
    expectedMap.put("b", 1);
    byte[] outputVal = discreteValuesHistogram.aggregate();
    Map<String, Integer> outputMap = GSON.fromJson(Bytes.toString(outputVal), TOKEN_TYPE_MAP_STRING_INTEGER);
    Assert.assertEquals(expectedMap, outputMap);
}
Also used : DiscreteValuesHistogram(co.cask.cdap.dq.functions.DiscreteValuesHistogram) Text(org.apache.hadoop.io.Text) DataQualityWritable(co.cask.cdap.dq.DataQualityWritable) Test(org.junit.Test)

Example 3 with DataQualityWritable

use of co.cask.cdap.dq.DataQualityWritable in project cdap by caskdata.

the class AggregationFunctionsTest method standardDeviationGenerateAggregationTest.

@Test
public void standardDeviationGenerateAggregationTest() throws Exception {
    DataQualityWritable val1 = new DataQualityWritable();
    val1.set(new DoubleWritable(2.0));
    DataQualityWritable val2 = new DataQualityWritable();
    val2.set(new DoubleWritable(5.0));
    DataQualityWritable val3 = new DataQualityWritable();
    val3.set(new DoubleWritable(10.0));
    DataQualityWritable val4 = new DataQualityWritable();
    val4.set(new DoubleWritable(52.0));
    StandardDeviation standardDeviation = new StandardDeviation();
    standardDeviation.add(val1);
    standardDeviation.add(val2);
    standardDeviation.add(val3);
    standardDeviation.add(val4);
    byte[] output = standardDeviation.aggregate();
    Assert.assertEquals(20.265426, Bytes.toDouble(output), 0.001);
}
Also used : DoubleWritable(org.apache.hadoop.io.DoubleWritable) StandardDeviation(co.cask.cdap.dq.functions.StandardDeviation) DataQualityWritable(co.cask.cdap.dq.DataQualityWritable) Test(org.junit.Test)

Example 4 with DataQualityWritable

use of co.cask.cdap.dq.DataQualityWritable in project cdap by caskdata.

the class AggregationFunctionsTest method averageGenerateAggregationTest.

@Test
public void averageGenerateAggregationTest() throws Exception {
    DataQualityWritable val1 = new DataQualityWritable();
    val1.set(new DoubleWritable(2.0));
    DataQualityWritable val2 = new DataQualityWritable();
    val2.set(new DoubleWritable(2.0));
    Mean mean = new Mean();
    mean.add(val1);
    mean.add(val2);
    byte[] output = mean.aggregate();
    Assert.assertEquals(2.0, Bytes.toDouble(output), 0);
}
Also used : Mean(co.cask.cdap.dq.functions.Mean) DoubleWritable(org.apache.hadoop.io.DoubleWritable) DataQualityWritable(co.cask.cdap.dq.DataQualityWritable) Test(org.junit.Test)

Example 5 with DataQualityWritable

use of co.cask.cdap.dq.DataQualityWritable 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)5 Test (org.junit.Test)5 DoubleWritable (org.apache.hadoop.io.DoubleWritable)2 Text (org.apache.hadoop.io.Text)2 DiscreteValuesHistogram (co.cask.cdap.dq.functions.DiscreteValuesHistogram)1 HistogramWithBucketing (co.cask.cdap.dq.functions.HistogramWithBucketing)1 Mean (co.cask.cdap.dq.functions.Mean)1 StandardDeviation (co.cask.cdap.dq.functions.StandardDeviation)1 UniqueValues (co.cask.cdap.dq.functions.UniqueValues)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IntWritable (org.apache.hadoop.io.IntWritable)1