Search in sources :

Example 1 with Intersect

use of com.yahoo.sketches.pig.theta.Intersect in project sketches-pig by DataSketches.

the class IntersectTest method checkNotDBAExcep.

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkNotDBAExcep() throws IOException {
    Intersect inter = new Intersect();
    // 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 Intersect();
    // add wrong type
    inter.accumulate(inputTuple);
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) DataBag(org.apache.pig.data.DataBag) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 2 with Intersect

use of com.yahoo.sketches.pig.theta.Intersect in project sketches-pig by DataSketches.

the class IntersectTest method outputSchemaTest.

@Test
public void outputSchemaTest() throws IOException {
    EvalFunc<Tuple> udf = new Intersect();
    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
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 3 with Intersect

use of com.yahoo.sketches.pig.theta.Intersect in project sketches-pig by DataSketches.

the class IntersectTest method checkNullInput.

@Test
public void checkNullInput() throws IOException {
    EvalFunc<Tuple> interFunc = new Intersect();
    EvalFunc<Double> estFunc = new Estimate();
    Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
    // null bag
    Tuple resultTuple = interFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    Double est = estFunc.exec(resultTuple);
    assertEquals(est, 0.0, 0.0);
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) Estimate(com.yahoo.sketches.pig.theta.Estimate) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 4 with Intersect

use of com.yahoo.sketches.pig.theta.Intersect in project sketches-pig by DataSketches.

the class IntersectTest method checkConstructors.

@SuppressWarnings("unused")
@Test
public void checkConstructors() {
    Intersect inter = new Intersect();
    inter = new Intersect(9001);
    Intersect.Initial initial = new Intersect.Initial();
    initial = new Intersect.Initial("9001");
    Intersect.IntermediateFinal interFin = new Intersect.IntermediateFinal();
    interFin = new Intersect.IntermediateFinal("9001");
    interFin = new Intersect.IntermediateFinal(9001);
    inter.cleanup();
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) Test(org.testng.annotations.Test)

Example 5 with Intersect

use of com.yahoo.sketches.pig.theta.Intersect in project sketches-pig by DataSketches.

the class IntersectTest method checkGetValueExcep.

@Test(expectedExceptions = IllegalStateException.class)
public void checkGetValueExcep() {
    Intersect inter = new Intersect();
    inter.getValue();
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) Test(org.testng.annotations.Test)

Aggregations

Intersect (com.yahoo.sketches.pig.theta.Intersect)9 Test (org.testng.annotations.Test)9 Tuple (org.apache.pig.data.Tuple)7 Estimate (com.yahoo.sketches.pig.theta.Estimate)4 DataBag (org.apache.pig.data.DataBag)4 DataByteArray (org.apache.pig.data.DataByteArray)1 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)1