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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations