Search in sources :

Example 1 with FuncSpec

use of org.apache.pig.FuncSpec in project oozie by apache.

the class UDFTester method getArgToFuncMapping.

@Override
public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
    List<FuncSpec> funcList = new ArrayList<FuncSpec>();
    funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY))));
    return funcList;
}
Also used : FuncSpec(org.apache.pig.FuncSpec) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) ArrayList(java.util.ArrayList)

Example 2 with FuncSpec

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

the class DataToSketchTest method textTopExec2.

/*
   * DataToSketch <br>
   * Tests all possible data types: NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE,
   * BYTEARRAY, CHARARRAY. Tests rejection of a non-simple type.
   */
// still triggers unchecked warning
@SuppressWarnings("unchecked")
@Test
public void textTopExec2() throws IOException {
    TupleFactory tupleFactory = TupleFactory.getInstance();
    BagFactory bagFactory = BagFactory.getInstance();
    String[] ctorArgs = { "128" };
    EvalFunc<Tuple> dataUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(udfName, ctorArgs));
    // EvalFunc<Tuple> resultUdf = (EvalFunc<Tuple>)PigContext.
    // instantiateFuncFromSpec(new FuncSpec(resultUdfName));
    Tuple t;
    DataBag bag = bagFactory.newDefaultBag();
    // empty with a null
    bag.add(tupleFactory.newTuple());
    // 1 empty field
    bag.add(tupleFactory.newTuple(1));
    // 1
    t = tupleFactory.newTuple(1);
    t.set(0, new Byte((byte) 1));
    bag.add(t);
    // 2
    t = tupleFactory.newTuple(1);
    // int
    t.set(0, new Integer(2));
    bag.add(t);
    // 3
    t = tupleFactory.newTuple(1);
    t.set(0, new Long(3));
    bag.add(t);
    // 4
    t = tupleFactory.newTuple(1);
    t.set(0, new Float(4));
    bag.add(t);
    // 5
    t = tupleFactory.newTuple(1);
    t.set(0, new Double(5));
    bag.add(t);
    // 6
    t = tupleFactory.newTuple(1);
    byte[] bArr = { 1, 2, 3 };
    t.set(0, new DataByteArray(bArr));
    bag.add(t);
    // -ignore
    t = tupleFactory.newTuple(1);
    // empty
    byte[] bArr2 = new byte[0];
    t.set(0, new DataByteArray(bArr2));
    bag.add(t);
    // 7
    t = tupleFactory.newTuple(1);
    t.set(0, new Double(-0.0));
    bag.add(t);
    // 7 duplicate
    t = tupleFactory.newTuple(1);
    t.set(0, new Double(0.0));
    bag.add(t);
    // 8
    t = tupleFactory.newTuple(1);
    String s = "abcde";
    t.set(0, s);
    bag.add(t);
    // - ignore
    t = tupleFactory.newTuple(1);
    // empty
    String s2 = "";
    t.set(0, s2);
    bag.add(t);
    Tuple in = tupleFactory.newTuple(1);
    in.set(0, bag);
    // should return a sketch
    Tuple resultTuple = dataUdf.exec(in);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    DataByteArray bytes = (DataByteArray) resultTuple.get(0);
    assertTrue(bytes.size() > 0);
    Sketch sketch = tupleToSketch(resultTuple, seed_);
    assertEquals(sketch.getEstimate(), 8.0, 0.0);
}
Also used : DataBag(org.apache.pig.data.DataBag) FuncSpec(org.apache.pig.FuncSpec) TupleFactory(org.apache.pig.data.TupleFactory) EvalFunc(org.apache.pig.EvalFunc) BagFactory(org.apache.pig.data.BagFactory) Sketch(com.yahoo.sketches.theta.Sketch) PigUtil.tupleToSketch(com.yahoo.sketches.pig.theta.PigUtil.tupleToSketch) DataToSketch(com.yahoo.sketches.pig.theta.DataToSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 3 with FuncSpec

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

the class MurmurHash3Test method check3ValidArgs.

@Test
public void check3ValidArgs() throws IOException {
    EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
    Tuple in, out;
    // test multiple integers, seed
    in = mTupleFactory.newTuple(3);
    for (int i = 0; i < 10; i++) {
        in.set(0, i);
        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 4 with FuncSpec

use of org.apache.pig.FuncSpec 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 5 with FuncSpec

use of org.apache.pig.FuncSpec 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)

Aggregations

FuncSpec (org.apache.pig.FuncSpec)13 EvalFunc (org.apache.pig.EvalFunc)12 Tuple (org.apache.pig.data.Tuple)12 Test (org.testng.annotations.Test)12 BagFactory (org.apache.pig.data.BagFactory)2 DataBag (org.apache.pig.data.DataBag)2 DataByteArray (org.apache.pig.data.DataByteArray)2 TupleFactory (org.apache.pig.data.TupleFactory)2 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)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 ArrayList (java.util.ArrayList)1