use of com.yahoo.sketches.pig.theta.Union in project sketches-pig by DataSketches.
the class UnionTest method checkNullEmptyAccumulator.
@Test
public void checkNullEmptyAccumulator() throws IOException {
Accumulator<Tuple> unionFunc = new Union("256");
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = null;
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// invalid size
inputTuple = TupleFactory.getInstance().newTuple(0);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// valid size, but null
inputTuple = TupleFactory.getInstance().newTuple(1);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// valid size
inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// correct type, but empty
inputTuple.set(0, bag);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// empty
Tuple innerTuple = TupleFactory.getInstance().newTuple(0);
bag.add(innerTuple);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// valid size
inputTuple = TupleFactory.getInstance().newTuple(1);
bag = BagFactory.getInstance().newDefaultBag();
// correct type
inputTuple.set(0, bag);
// correct size
innerTuple = TupleFactory.getInstance().newTuple(1);
// but innerTuple(0) is null
bag.add(innerTuple);
// ignores
unionFunc.accumulate(inputTuple);
Tuple resultTuple = unionFunc.getValue();
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
Double est = estFunc.exec(resultTuple);
assertEquals(est, 0.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Union in project sketches-pig by DataSketches.
the class UnionTest method checkConstructors.
@SuppressWarnings("unused")
@Test
public void checkConstructors() {
Union inter = new Union();
inter = new Union("1024");
inter = new Union("1024", "1.0");
inter = new Union("1024", "1.0", "9001");
inter = new Union(1024, (float) 1.0, 9001);
Union.Initial initial = new Union.Initial();
initial = new Union.Initial("1024");
initial = new Union.Initial("1024", "1.0");
initial = new Union.Initial("1024", "1.0", "9001");
Union.IntermediateFinal interFin = new Union.IntermediateFinal();
interFin = new Union.IntermediateFinal("1024");
interFin = new Union.IntermediateFinal("1024", "1.0");
interFin = new Union.IntermediateFinal("1024", "1.0", "9001");
interFin = new Union.IntermediateFinal(1024, (float) 1.0, 9001);
}
use of com.yahoo.sketches.pig.theta.Union in project sketches-pig by DataSketches.
the class UnionTest method checkExactTopExec.
@Test
public void checkExactTopExec() throws IOException {
// default 4096
EvalFunc<Tuple> unionFunc = new Union();
EvalFunc<Double> estFunc = new Estimate();
// create inputTuple and a bag, add bag to inputTuple
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
inputTuple.set(0, bag);
// create 4 distinct sketches of 64 in a bag
for (int i = 0; i < 4; i++) {
Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
dataTuple.set(0, createDbaFromQssRange(64, i * 64, 64));
bag.add(dataTuple);
}
Tuple resultTuple = unionFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
Double est = estFunc.exec(resultTuple);
assertEquals(est, 256.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Union in project sketches-pig by DataSketches.
the class UnionTest method outputSchemaTest.
@Test
public void outputSchemaTest() throws IOException {
EvalFunc<Tuple> udf = new Union("512");
Schema inputSchema = null;
Schema nullOutputSchema = null;
Schema outputSchema = null;
Schema.FieldSchema outputOuterFs0 = null;
Schema outputInnerSchema = null;
Schema.FieldSchema outputInnerFs0 = null;
inputSchema = Schema.generateNestedSchema(DataType.BAG, DataType.BYTEARRAY);
nullOutputSchema = udf.outputSchema(null);
outputSchema = udf.outputSchema(inputSchema);
outputOuterFs0 = outputSchema.getField(0);
outputInnerSchema = outputOuterFs0.schema;
outputInnerFs0 = outputInnerSchema.getField(0);
Assert.assertNull(nullOutputSchema, "Should be null");
Assert.assertNotNull(outputOuterFs0, "outputSchema.getField(0) schema may not be null");
String expected = "tuple";
String result = DataType.findTypeName(outputOuterFs0.type);
Assert.assertEquals(result, expected);
expected = "bytearray";
Assert.assertNotNull(outputInnerFs0, "innerSchema.getField(0) schema may not be null");
result = DataType.findTypeName(outputInnerFs0.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);
println(sb.toString());
// @formatter:on
// end print schemas
}
use of com.yahoo.sketches.pig.theta.Union in project sketches-pig by DataSketches.
the class UnionTest method checkNotDBAExcep.
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkNotDBAExcep() throws IOException {
Union inter = new Union();
// create inputTuple and a bag, add bag to inputTuple
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
inputTuple.set(0, bag);
Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
bag.add(innerTuple);
// add empty tuple
inter.accumulate(inputTuple);
// not a DBA
innerTuple.set(0, new Double(1.0));
inter = new Union();
// add wrong type
inter.accumulate(inputTuple);
}
Aggregations