Search in sources :

Example 16 with EvalFunc

use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.

the class MurmurHash3Test method check1ValidArg.

@Test
public void check1ValidArg() throws IOException {
    EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
    Tuple in, out;
    // test Integer, Long, Float, Double, DataByteArray, String
    in = mTupleFactory.newTuple(1);
    in.set(0, null);
    out = hashUdf.exec(in);
    Assert.assertNull(out.get(0));
    Assert.assertNull(out.get(1));
    Assert.assertNull(out.get(2));
    in.set(0, new Integer(1));
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new Long(1));
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new Float(1));
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new Double(0.0));
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new Double(-0.0));
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, Double.NaN);
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new String("1"));
    out = hashUdf.exec(in);
    checkOutput(out, false);
    // empty
    in.set(0, new String(""));
    out = hashUdf.exec(in);
    Assert.assertNull(out.get(0));
    Assert.assertNull(out.get(1));
    Assert.assertNull(out.get(2));
    byte[] bArr = { 1, 2, 3, 4 };
    DataByteArray dba = new DataByteArray(bArr);
    in.set(0, dba);
    out = hashUdf.exec(in);
    checkOutput(out, false);
    // empty
    bArr = new byte[0];
    dba = new DataByteArray(bArr);
    in.set(0, dba);
    out = hashUdf.exec(in);
    Assert.assertNull(out.get(0));
    Assert.assertNull(out.get(1));
    Assert.assertNull(out.get(2));
}
Also used : FuncSpec(org.apache.pig.FuncSpec) EvalFunc(org.apache.pig.EvalFunc) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 17 with EvalFunc

use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.

the class MurmurHash3Test method checkExceptions4.

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkExceptions4() throws IOException {
    EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
    Tuple in, out;
    // divisor must be INTEGER
    in = mTupleFactory.newTuple(3);
    in.set(0, new String("ABC"));
    in.set(1, 0);
    in.set(2, new Long(8));
    out = hashUdf.exec(in);
}
Also used : FuncSpec(org.apache.pig.FuncSpec) EvalFunc(org.apache.pig.EvalFunc) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 18 with EvalFunc

use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.

the class MurmurHash3Test method check3ValidArg.

@Test
public void check3ValidArg() throws IOException {
    EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
    Tuple in, out;
    // test String, seed
    in = mTupleFactory.newTuple(3);
    in.set(0, new String("1"));
    // 2nd is null
    // 3rd is null
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new String("1"));
    in.set(1, 9001);
    // 3rd is null
    out = hashUdf.exec(in);
    checkOutput(out, false);
    in.set(0, new String("1"));
    in.set(1, 9001);
    in.set(2, 7);
    out = hashUdf.exec(in);
    checkOutput(out, true);
}
Also used : FuncSpec(org.apache.pig.FuncSpec) EvalFunc(org.apache.pig.EvalFunc) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 19 with EvalFunc

use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.

the class DataToSketchTest method algebraicIntermediateFromIntermediate.

@Test
public void algebraicIntermediateFromIntermediate() throws Exception {
    @SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new DataToSketch().getIntermed()).newInstance();
    HllSketch inputSketch = new HllSketch(12);
    inputSketch.update("a");
    inputSketch.update("b");
    DataBag bag = bagFactory.newDefaultBag();
    bag.add(tupleFactory.newTuple(new DataByteArray(inputSketch.toCompactByteArray())));
    Tuple result = func.exec(tupleFactory.newTuple(bag));
    HllSketch sketch = getSketch((DataByteArray) result.get(0));
    Assert.assertFalse(sketch.isEmpty());
    Assert.assertEquals(sketch.getEstimate(), 2.0, 0.01);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) DataBag(org.apache.pig.data.DataBag) EvalFunc(org.apache.pig.EvalFunc) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 20 with EvalFunc

use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.

the class DataToSketchTest method algebraicFinalFromInitial.

@Test
public void algebraicFinalFromInitial() throws Exception {
    @SuppressWarnings("unchecked") EvalFunc<DataByteArray> func = (EvalFunc<DataByteArray>) Class.forName(new DataToSketch().getFinal()).newInstance();
    DataBag outerBag = bagFactory.newDefaultBag();
    DataBag innerBag = bagFactory.newDefaultBag();
    innerBag.add(tupleFactory.newTuple("a"));
    innerBag.add(tupleFactory.newTuple("b"));
    innerBag.add(tupleFactory.newTuple("c"));
    outerBag.add(tupleFactory.newTuple(innerBag));
    DataByteArray result = func.exec(tupleFactory.newTuple(outerBag));
    HllSketch sketch = getSketch(result);
    Assert.assertFalse(sketch.isEmpty());
    Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
}
Also used : HllSketch(com.yahoo.sketches.hll.HllSketch) DataBag(org.apache.pig.data.DataBag) EvalFunc(org.apache.pig.EvalFunc) DataByteArray(org.apache.pig.data.DataByteArray) Test(org.testng.annotations.Test)

Aggregations

EvalFunc (org.apache.pig.EvalFunc)44 Test (org.testng.annotations.Test)44 Tuple (org.apache.pig.data.Tuple)35 HllSketch (com.yahoo.sketches.hll.HllSketch)18 DataBag (org.apache.pig.data.DataBag)16 DataByteArray (org.apache.pig.data.DataByteArray)16 FuncSpec (org.apache.pig.FuncSpec)12 ItemsSketch (com.yahoo.sketches.quantiles.ItemsSketch)2 BagFactory (org.apache.pig.data.BagFactory)2 TupleFactory (org.apache.pig.data.TupleFactory)2 DataToSketch (com.yahoo.sketches.pig.theta.DataToSketch)1 PigUtil.tupleToSketch (com.yahoo.sketches.pig.theta.PigUtil.tupleToSketch)1 Sketch (com.yahoo.sketches.theta.Sketch)1 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)1