Search in sources :

Example 11 with Filter

use of org.apache.drill.exec.physical.config.Filter in project drill by axbaretto.

the class TestNullInputMiniPlan method testFilterEmpty.

@Test
public void testFilterEmpty() throws Exception {
    final PhysicalOperator filter = new Filter(null, parseExpr("a=5"), 1.0f);
    testSingleInputNullBatchHandling(filter);
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) Test(org.junit.Test)

Example 12 with Filter

use of org.apache.drill.exec.physical.config.Filter in project drill by axbaretto.

the class TestNullInputMiniPlan method testUnionFilterAll.

@Test
public void testUnionFilterAll() throws Exception {
    List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : \"name1\" }]");
    List<String> rightJsonBatches = Lists.newArrayList("[{\"a\": 50, \"b\" : \"name2\" }]");
    RecordBatch leftScan = new JsonScanBuilder().jsonBatches(leftJsonBatches).columnsToRead("a", "b").build();
    RecordBatch leftFilter = new PopBuilder().physicalOperator(new Filter(null, parseExpr("a < 0"), 1.0f)).addInput(leftScan).build();
    RecordBatch rightScan = new JsonScanBuilder().jsonBatches(rightJsonBatches).columnsToRead("a", "b").build();
    RecordBatch rightFilter = new PopBuilder().physicalOperator(new Filter(null, parseExpr("a < 0"), 1.0f)).addInput(rightScan).build();
    RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
    new UnionAll(Collections.EMPTY_LIST)).addInput(leftFilter).addInput(rightFilter).build();
    BatchSchema expectedSchema = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.VARCHAR).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
    new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).expectZeroRow(true).go();
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) BatchSchema(org.apache.drill.exec.record.BatchSchema) RecordBatch(org.apache.drill.exec.record.RecordBatch) SchemaBuilder(org.apache.drill.test.rowSet.schema.SchemaBuilder) UnionAll(org.apache.drill.exec.physical.config.UnionAll) Test(org.junit.Test)

Example 13 with Filter

use of org.apache.drill.exec.physical.config.Filter in project drill by axbaretto.

the class TestOpSerialization method testSerializedDeserialize.

@Test
public void testSerializedDeserialize() throws Throwable {
    MockSubScanPOP s = new MockSubScanPOP("abc", false, null);
    s.setOperatorId(3);
    Filter f = new Filter(s, new ValueExpressions.BooleanExpression("true", ExpressionPosition.UNKNOWN), 0.1f);
    f.setOperatorId(2);
    UnionExchange e = new UnionExchange(f);
    e.setOperatorId(1);
    Screen screen = new Screen(e, CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
    screen.setOperatorId(0);
    boolean reversed = false;
    while (true) {
        List<PhysicalOperator> pops = Lists.newArrayList();
        pops.add(s);
        pops.add(e);
        pops.add(f);
        pops.add(screen);
        if (reversed) {
            pops = Lists.reverse(pops);
        }
        PhysicalPlan plan1 = new PhysicalPlan(PlanProperties.builder().build(), pops);
        String json = plan1.unparse(writer);
        PhysicalPlan plan2 = reader.readPhysicalPlan(json);
        PhysicalOperator root = plan2.getSortedOperators(false).iterator().next();
        assertEquals(0, root.getOperatorId());
        PhysicalOperator o1 = root.iterator().next();
        assertEquals(1, o1.getOperatorId());
        PhysicalOperator o2 = o1.iterator().next();
        assertEquals(2, o2.getOperatorId());
        if (reversed) {
            break;
        }
        reversed = !reversed;
    }
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) Filter(org.apache.drill.exec.physical.config.Filter) UnionExchange(org.apache.drill.exec.physical.config.UnionExchange) Screen(org.apache.drill.exec.physical.config.Screen) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) ValueExpressions(org.apache.drill.common.expression.ValueExpressions) MockSubScanPOP(org.apache.drill.exec.store.mock.MockSubScanPOP) Test(org.junit.Test)

Example 14 with Filter

use of org.apache.drill.exec.physical.config.Filter in project drill by apache.

the class TestOpSerialization method testSerializedDeserialize.

@Test
public void testSerializedDeserialize() throws Throwable {
    MockSubScanPOP s = new MockSubScanPOP("abc", false, null);
    s.setOperatorId(3);
    Filter f = new Filter(s, new ValueExpressions.BooleanExpression("true", ExpressionPosition.UNKNOWN), 0.1f);
    f.setOperatorId(2);
    UnionExchange e = new UnionExchange(f);
    e.setOperatorId(1);
    Screen screen = new Screen(e, CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
    screen.setOperatorId(0);
    boolean reversed = false;
    while (true) {
        List<PhysicalOperator> pops = Lists.newArrayList();
        pops.add(s);
        pops.add(e);
        pops.add(f);
        pops.add(screen);
        if (reversed) {
            pops = Lists.reverse(pops);
        }
        PhysicalPlan plan1 = new PhysicalPlan(PlanProperties.builder().build(), pops);
        String json = plan1.unparse(writer);
        PhysicalPlan plan2 = reader.readPhysicalPlan(json);
        PhysicalOperator root = plan2.getSortedOperators(false).iterator().next();
        assertEquals(0, root.getOperatorId());
        PhysicalOperator o1 = root.iterator().next();
        assertEquals(1, o1.getOperatorId());
        PhysicalOperator o2 = o1.iterator().next();
        assertEquals(2, o2.getOperatorId());
        if (reversed) {
            break;
        }
        reversed = !reversed;
    }
}
Also used : PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) Filter(org.apache.drill.exec.physical.config.Filter) UnionExchange(org.apache.drill.exec.physical.config.UnionExchange) Screen(org.apache.drill.exec.physical.config.Screen) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) ValueExpressions(org.apache.drill.common.expression.ValueExpressions) MockSubScanPOP(org.apache.drill.exec.store.mock.MockSubScanPOP) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 15 with Filter

use of org.apache.drill.exec.physical.config.Filter in project drill by apache.

the class TestFilterBatchEmitOutcome method testFilterEmptyBatchEmitOutcome.

/**
 * Test to show if an empty batch is accompanied with EMIT outcome then Filter operator is not ignoring it and
 * asking for next batch with data. Instead it is just returning the empty batch along with EMIT outcome right away.
 *
 * This test also shows that if first batch accompanied with OK_NEW_SCHEMA is empty then it is also pass through by
 * Filter operator rather than ignoring it and waiting for a batch with some data in it.
 * @throws Throwable
 */
@Test
public void testFilterEmptyBatchEmitOutcome() throws Throwable {
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    inputOutcomes.add(RecordBatch.IterOutcome.EMIT);
    final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
    final Filter filterConf = new Filter(null, parseExpr("id_left=5"), 1.0f);
    final FilterRecordBatch filterRecordBatch = new FilterRecordBatch(filterConf, mockInputBatch, operatorFixture.getFragmentContext());
    assertTrue(filterRecordBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    outputRecordCount += filterRecordBatch.getRecordCount();
    assertTrue(filterRecordBatch.next() == RecordBatch.IterOutcome.EMIT);
    outputRecordCount += filterRecordBatch.getRecordCount();
    assertEquals(0, outputRecordCount);
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

Filter (org.apache.drill.exec.physical.config.Filter)19 Test (org.junit.Test)17 OperatorTest (org.apache.drill.categories.OperatorTest)6 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)6 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)6 UnionAll (org.apache.drill.exec.physical.config.UnionAll)5 BatchSchema (org.apache.drill.exec.record.BatchSchema)5 RecordBatch (org.apache.drill.exec.record.RecordBatch)5 PlannerTest (org.apache.drill.categories.PlannerTest)2 ValueExpressions (org.apache.drill.common.expression.ValueExpressions)2 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)2 Screen (org.apache.drill.exec.physical.config.Screen)2 UnionExchange (org.apache.drill.exec.physical.config.UnionExchange)2 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)2 BatchSchemaBuilder (org.apache.drill.exec.record.BatchSchemaBuilder)2 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)2 MockSubScanPOP (org.apache.drill.exec.store.mock.MockSubScanPOP)2 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)2 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)1 BaseTest (org.apache.drill.test.BaseTest)1