Search in sources :

Example 1 with ItemsSketch

use of com.yahoo.sketches.quantiles.ItemsSketch in project sketches-pig by DataSketches.

the class DataToStringsSketchTest method algebraicIntermediateFinalNormalCase.

@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
    @SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new DataToStringsSketch().getIntermed()).newInstance();
    DataBag bag = BAG_FACTORY.newDefaultBag();
    {
        // this is to simulate an output from Initial
        DataBag innerBag = BAG_FACTORY.newDefaultBag();
        innerBag.add(TUPLE_FACTORY.newTuple("a"));
        bag.add(TUPLE_FACTORY.newTuple(innerBag));
    }
    {
        // this is to simulate an output from a prior call of IntermediateFinal
        ItemsSketch<String> qs = ItemsSketch.getInstance(COMPARATOR);
        qs.update("b");
        bag.add(TUPLE_FACTORY.newTuple(new DataByteArray(qs.toByteArray(SER_DE))));
    }
    Tuple resultTuple = func.exec(TUPLE_FACTORY.newTuple(bag));
    ItemsSketch<String> sketch = getSketch(resultTuple);
    Assert.assertFalse(sketch.isEmpty());
    Assert.assertEquals(sketch.getN(), 2);
}
Also used : DataBag(org.apache.pig.data.DataBag) EvalFunc(org.apache.pig.EvalFunc) ItemsSketch(com.yahoo.sketches.quantiles.ItemsSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 2 with ItemsSketch

use of com.yahoo.sketches.quantiles.ItemsSketch in project sketches-pig by DataSketches.

the class UnionStringsSketchTest method algebraicIntermediateFinalNormalCase.

@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
    @SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new UnionStringsSketch().getIntermed()).newInstance();
    DataBag bag = BAG_FACTORY.newDefaultBag();
    {
        // this is to simulate an output from Initial
        DataBag innerBag = BAG_FACTORY.newDefaultBag();
        ItemsSketch<String> qs = ItemsSketch.getInstance(COMPARATOR);
        qs.update("a");
        innerBag.add(TUPLE_FACTORY.newTuple(new DataByteArray(qs.toByteArray(SER_DE))));
        bag.add(TUPLE_FACTORY.newTuple(innerBag));
    }
    {
        // this is to simulate an output from a prior call of IntermediateFinal
        ItemsSketch<String> qs = ItemsSketch.getInstance(COMPARATOR);
        qs.update("b");
        bag.add(TUPLE_FACTORY.newTuple(new DataByteArray(qs.toByteArray(SER_DE))));
    }
    Tuple resultTuple = func.exec(TUPLE_FACTORY.newTuple(bag));
    ItemsSketch<String> sketch = getSketch(resultTuple);
    Assert.assertFalse(sketch.isEmpty());
    Assert.assertEquals(sketch.getN(), 2);
}
Also used : DataBag(org.apache.pig.data.DataBag) EvalFunc(org.apache.pig.EvalFunc) ItemsSketch(com.yahoo.sketches.quantiles.ItemsSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Aggregations

ItemsSketch (com.yahoo.sketches.quantiles.ItemsSketch)2 EvalFunc (org.apache.pig.EvalFunc)2 DataBag (org.apache.pig.data.DataBag)2 DataByteArray (org.apache.pig.data.DataByteArray)2 Tuple (org.apache.pig.data.Tuple)2 Test (org.testng.annotations.Test)2