Search in sources :

Example 16 with Filter

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

the class TestFilterBatchEmitOutcome method testFilterNonEmptyBatchEmitOutcome.

/**
 * Test to show if a non-empty batch is accompanied with EMIT outcome then Filter operator produces output for
 * that batch with data matching filter condition and return the output using EMIT outcome.
 * @throws Throwable
 */
@Test
public void testFilterNonEmptyBatchEmitOutcome() throws Throwable {
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(nonEmptyInputRowSet.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=1"), 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(1, 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)

Example 17 with Filter

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

the class TestFilterBatchEmitOutcome method testFilterNonEmptyFirst_EmptyBatchEmitOutcome.

/**
 * Test to show that non-empty first batch produces output for that batch with OK_NEW_SCHEMA and later empty batch
 * with EMIT outcome is also passed through rather than getting ignored.
 * @throws Throwable
 */
@Test
public void testFilterNonEmptyFirst_EmptyBatchEmitOutcome() throws Throwable {
    inputContainer.add(nonEmptyInputRowSet.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=1"), 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(1, 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)

Example 18 with Filter

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

the class TestMiniPlan method testUnionFilter.

@Test
public void testUnionFilter() throws Exception {
    List<String> leftJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 1 }]", "[{\"a\": 5, \"b\" : 5},{\"a\": 3, \"b\" : 8}]", "[{\"a\": 40, \"b\" : 3},{\"a\": 13, \"b\" : 100}]");
    List<String> rightJsonBatches = Lists.newArrayList("[{\"a\": 5, \"b\" : 10 }]", "[{\"a\": 50, \"b\" : 100}]");
    RecordBatch batch = new PopBuilder().physicalOperator(// Children list is provided through RecordBatch
    new UnionAll(Collections.<PhysicalOperator>emptyList())).addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=5"), 1.0f)).addJsonScanAsChild().jsonBatches(leftJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().addInputAsChild().physicalOperator(new Filter(null, parseExpr("a=50"), 1.0f)).addJsonScanAsChild().jsonBatches(rightJsonBatches).columnsToRead("a", "b").buildAddAsInput().buildAddAsInput().build();
    SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("a", TypeProtos.MinorType.BIGINT).addNullable("b", TypeProtos.MinorType.BIGINT);
    BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).withSVMode(BatchSchema.SelectionVectorMode.NONE).build();
    new MiniPlanTestBuilder().root(batch).expectSchema(expectedSchema).baselineValues(5l, 1l).baselineValues(5l, 5l).baselineValues(50l, 100l).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.exec.record.metadata.SchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) BatchSchemaBuilder(org.apache.drill.exec.record.BatchSchemaBuilder) UnionAll(org.apache.drill.exec.physical.config.UnionAll) Test(org.junit.Test) PlannerTest(org.apache.drill.categories.PlannerTest)

Example 19 with Filter

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

the class FilterPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    Prel child = (Prel) this.getInput();
    PhysicalOperator childPOP = child.getPhysicalOperator(creator);
    Filter p = new Filter(childPOP, getFilterExpression(new DrillParseContext(PrelUtil.getSettings(getCluster()))), 1.0f);
    return creator.addMetadata(this, p);
}
Also used : Filter(org.apache.drill.exec.physical.config.Filter) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext)

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