Search in sources :

Example 16 with Limit

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

the class TestLimitBatchEmitOutcome method testLimitEmptyBatchEmitOutcome.

/**
 * Test to show empty batch with both OK_NEW_SCHEMA and EMIT outcome is not
 * ignored by Limit and is pass through to the downstream operator.
 */
@Test
public void testLimitEmptyBatchEmitOutcome() 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());
    // Only set for this Test class
    mockInputBatch.useUnnestKillHandlingForLimit(true);
    final Limit limitConf = new Limit(null, 0, 1);
    @SuppressWarnings("resource") final LimitRecordBatch limitBatch = new LimitRecordBatch(limitConf, operatorFixture.getFragmentContext(), mockInputBatch);
    assertTrue(limitBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    outputRecordCount += limitBatch.getRecordCount();
    assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
    outputRecordCount += limitBatch.getRecordCount();
    assertEquals(0, outputRecordCount);
}
Also used : MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) Limit(org.apache.drill.exec.physical.config.Limit) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 17 with Limit

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

the class TestLimitBatchEmitOutcome method testLimitNonEmptyFirst_EmptyOKEmitOutcome.

/**
 * Test to show that when the limit number of records is found with first
 * incoming batch, then next empty incoming batch with OK outcome is ignored,
 * but the empty EMIT outcome batch is not ignored. Empty incoming batch with
 * EMIT outcome produces empty output batch with EMIT outcome.
 */
@Test
public void testLimitNonEmptyFirst_EmptyOKEmitOutcome() throws Throwable {
    inputContainer.add(nonEmptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputContainer.add(emptyInputRowSet.container());
    inputOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    inputOutcomes.add(RecordBatch.IterOutcome.OK);
    inputOutcomes.add(RecordBatch.IterOutcome.EMIT);
    inputOutcomes.add(RecordBatch.IterOutcome.NONE);
    final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
    // Only set for this Test class
    mockInputBatch.useUnnestKillHandlingForLimit(true);
    final Limit limitConf = new Limit(null, 0, 1);
    @SuppressWarnings("resource") final LimitRecordBatch limitBatch = new LimitRecordBatch(limitConf, operatorFixture.getFragmentContext(), mockInputBatch);
    assertTrue(limitBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
    assertEquals(1, limitBatch.getRecordCount());
    // OK will not be received since it's was accompanied with empty batch
    assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
    assertEquals(0, limitBatch.getRecordCount());
    assertTrue(limitBatch.next() == RecordBatch.IterOutcome.NONE);
}
Also used : MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) Limit(org.apache.drill.exec.physical.config.Limit) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

Limit (org.apache.drill.exec.physical.config.Limit)17 Test (org.junit.Test)15 OperatorTest (org.apache.drill.categories.OperatorTest)6 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)6 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)3 PartitionLimit (org.apache.drill.exec.physical.config.PartitionLimit)1