Search in sources :

Example 6 with FuncSpec

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

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

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

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

Example 10 with FuncSpec

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

the class MurmurHash3Test method outputSchemaTestMurmurHash3Udf.

/**
 * Test the outputSchema method for MurmurHash3.
 * @throws IOException thrown by Pig
 */
@Test
public void outputSchemaTestMurmurHash3Udf() throws IOException {
    EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
    Schema inputSchema = null;
    Schema nullOutputSchema = null;
    Schema outputSchema = null;
    Schema.FieldSchema outputOuterFs0 = null;
    Schema outputInnerSchema = null;
    Schema.FieldSchema outputInnerFs0 = null;
    Schema.FieldSchema outputInnerFs1 = null;
    Schema.FieldSchema outputInnerFs2 = null;
    nullOutputSchema = hashUdf.outputSchema(null);
    // CHARARRAY is one of many different input types
    inputSchema = Schema.generateNestedSchema(DataType.BAG, DataType.CHARARRAY);
    outputSchema = hashUdf.outputSchema(inputSchema);
    outputOuterFs0 = outputSchema.getField(0);
    outputInnerSchema = outputOuterFs0.schema;
    outputInnerFs0 = outputInnerSchema.getField(0);
    outputInnerFs1 = outputInnerSchema.getField(1);
    outputInnerFs2 = outputInnerSchema.getField(2);
    Assert.assertNull(nullOutputSchema, "Should be null");
    Assert.assertNotNull(outputOuterFs0, "outputSchema.getField(0) may not be null");
    String expected = "tuple";
    String result = DataType.findTypeName(outputOuterFs0.type);
    Assert.assertEquals(result, expected);
    expected = "long";
    Assert.assertNotNull(outputInnerFs0, "innerSchema.getField(0) may not be null");
    result = DataType.findTypeName(outputInnerFs0.type);
    Assert.assertEquals(result, expected);
    expected = "long";
    Assert.assertNotNull(outputInnerFs1, "innerSchema.getField(1) may not be null");
    result = DataType.findTypeName(outputInnerFs1.type);
    Assert.assertEquals(result, expected);
    expected = "int";
    Assert.assertNotNull(outputInnerFs2, "innerSchema.getField(2) may not be null");
    result = DataType.findTypeName(outputInnerFs2.type);
    Assert.assertEquals(result, expected);
    // print schemas
    // @formatter:off
    StringBuilder sb = new StringBuilder();
    sb.append("input schema: ").append(inputSchema).append(LS).append("output schema: ").append(outputSchema).append(LS).append("outputOuterFs: ").append(outputOuterFs0).append(", type: ").append(DataType.findTypeName(outputOuterFs0.type)).append(LS).append("outputInnerSchema: ").append(outputInnerSchema).append(LS).append("outputInnerFs0: ").append(outputInnerFs0).append(", type: ").append(DataType.findTypeName(outputInnerFs0.type)).append(LS).append("outputInnerFs1: ").append(outputInnerFs1).append(", type: ").append(DataType.findTypeName(outputInnerFs1.type)).append(LS).append("outputInnerFs2: ").append(outputInnerFs2).append(", type: ").append(DataType.findTypeName(outputInnerFs2.type)).append(LS);
    println(sb.toString());
// @formatter:on
// end print schemas
}
Also used : FuncSpec(org.apache.pig.FuncSpec) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) 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