Search in sources :

Example 36 with EvalFunc

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

the class UnionStringsSketchTest method algebraicIntermediateFinalNullInputTuple.

@Test
public void algebraicIntermediateFinalNullInputTuple() throws Exception {
    @SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new UnionStringsSketch().getIntermed()).newInstance();
    Tuple resultTuple = func.exec(null);
    ItemsSketch<String> sketch = getSketch(resultTuple);
    Assert.assertTrue(sketch.isEmpty());
}
Also used : EvalFunc(org.apache.pig.EvalFunc) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 37 with EvalFunc

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

the class UnionStringsSketchTest method algebraicIntermediateFinalWrongType.

@Test(expectedExceptions = IllegalArgumentException.class)
public void algebraicIntermediateFinalWrongType() throws Exception {
    @SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new UnionStringsSketch().getIntermed()).newInstance();
    DataBag bag = BAG_FACTORY.newDefaultBag();
    // this bag must have tuples with either bags or data byte arrays
    bag.add(TUPLE_FACTORY.newTuple(1.0));
    func.exec(TUPLE_FACTORY.newTuple(bag));
}
Also used : DataBag(org.apache.pig.data.DataBag) EvalFunc(org.apache.pig.EvalFunc) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 38 with EvalFunc

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

the class DataToSketchTest method testRejectionOfNonSimpleType.

// still triggers unchecked warning
@SuppressWarnings("unchecked")
@Test(expectedExceptions = IllegalArgumentException.class)
public void testRejectionOfNonSimpleType() throws IOException {
    TupleFactory mTupleFactory = TupleFactory.getInstance();
    BagFactory bagFactory = BagFactory.getInstance();
    Tuple outerTuple = mTupleFactory.newTuple(1);
    DataBag outerBag = bagFactory.newDefaultBag();
    Tuple innerTuple = mTupleFactory.newTuple(1);
    DataBag innerBag = bagFactory.newDefaultBag();
    innerTuple.set(0, innerBag);
    outerBag.add(innerTuple);
    outerTuple.set(0, outerBag);
    String[] ctorArgs = { "128" };
    EvalFunc<Tuple> dataUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(udfName, ctorArgs));
    dataUdf.exec(outerTuple);
}
Also used : DataBag(org.apache.pig.data.DataBag) FuncSpec(org.apache.pig.FuncSpec) TupleFactory(org.apache.pig.data.TupleFactory) BagFactory(org.apache.pig.data.BagFactory) EvalFunc(org.apache.pig.EvalFunc) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 39 with EvalFunc

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

the class MurmurHash3Test method check2ValidArg.

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

Example 40 with EvalFunc

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

the class MurmurHash3Test method checkExceptions5.

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkExceptions5() throws IOException {
    EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
    Tuple in, out;
    // divisor must be INTEGER > 0
    in = mTupleFactory.newTuple(3);
    in.set(0, new String("ABC"));
    in.set(1, 0);
    in.set(2, new Integer(0));
    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)

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