use of org.apache.pig.EvalFunc 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
}
use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.
the class MurmurHash3Test method checkExceptions2.
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkExceptions2() throws IOException {
EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
Tuple in, out;
// seed must be INTEGER or LONG
in = mTupleFactory.newTuple(2);
in.set(0, new String("ABC"));
in.set(1, new Double(9001));
out = hashUdf.exec(in);
}
use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.
the class MurmurHash3Test method checkExceptions3.
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkExceptions3() throws IOException {
EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
Tuple in, out;
// improper hash object = Tuple
in = mTupleFactory.newTuple(1);
in.set(0, in);
out = hashUdf.exec(in);
}
use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.
the class MurmurHash3Test method checkExceptions1.
@Test
public void checkExceptions1() throws IOException {
EvalFunc<Tuple> hashUdf = (EvalFunc<Tuple>) PigContext.instantiateFuncFromSpec(new FuncSpec(hashUdfName));
Tuple in, out;
// Empty input tuple
in = mTupleFactory.newTuple(0);
out = hashUdf.exec(in);
Assert.assertNull(out);
}
Aggregations