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