use of org.apache.drill.exec.physical.impl.MockRecordBatch in project drill by apache.
the class TestLimitBatchEmitOutcome method testMultipleLimitWithEMITOutcome.
/**
* Test to show that limit refreshes it's state after seeing first EMIT
* outcome and works on data batches following it as new set's of incoming
* batch and apply the limits rule from fresh on those. So for first set of
* batches with OK_NEW_SCHEMA and EMIT outcome but total number of records
* received being less than limit condition, it still produces an output with
* that many records (in this case 1 even though limit number of records is
* 2).
* <p>
* After seeing EMIT, it refreshes it's state and operate on next input
* batches to again return limit number of records. So for 3rd batch with 2
* records but with EMIT outcome it produces an output batch with 2 records
* not with 1 since state is refreshed.
*/
@Test
public void testMultipleLimitWithEMITOutcome() throws Throwable {
final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(2, 20, "item2").addRow(3, 30, "item3").build();
inputContainer.add(nonEmptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.container());
inputContainer.add(emptyInputRowSet.container());
inputOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
inputOutcomes.add(RecordBatch.IterOutcome.EMIT);
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, 2);
@SuppressWarnings("resource") final LimitRecordBatch limitBatch = new LimitRecordBatch(limitConf, operatorFixture.getFragmentContext(), mockInputBatch);
// first limit evaluation
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
assertEquals(1, limitBatch.getRecordCount());
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
assertEquals(0, limitBatch.getRecordCount());
// After seeing EMIT limit will refresh it's state and again evaluate limit on next set of input batches
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
assertEquals(2, limitBatch.getRecordCount());
// Since limit is hit it will return NONE
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.NONE);
}
use of org.apache.drill.exec.physical.impl.MockRecordBatch in project drill by apache.
the class TestLimitBatchEmitOutcome method testLimitNonEmptyFirst_NonEmptyOK_EmptyBatchEmitOutcome.
/**
* Test shows that limit operates on multiple input batches until it finds
* limit number of records or it sees an EMIT outcome to refresh it's state.
*/
@Test
public void testLimitNonEmptyFirst_NonEmptyOK_EmptyBatchEmitOutcome() throws Throwable {
final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(2, 20, "item2").build();
inputContainer.add(nonEmptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.container());
inputContainer.add(emptyInputRowSet.container());
inputOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
inputOutcomes.add(RecordBatch.IterOutcome.OK);
inputOutcomes.add(RecordBatch.IterOutcome.OK);
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, 2);
@SuppressWarnings("resource") final LimitRecordBatch limitBatch = new LimitRecordBatch(limitConf, operatorFixture.getFragmentContext(), mockInputBatch);
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
assertEquals(1, limitBatch.getRecordCount());
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.OK);
assertEquals(1, limitBatch.getRecordCount());
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
assertEquals(0, limitBatch.getRecordCount());
nonEmptyInputRowSet2.clear();
}
use of org.apache.drill.exec.physical.impl.MockRecordBatch in project drill by apache.
the class TestLimitBatchEmitOutcome method testLimitNonEmptyBatchEmitOutcome.
/**
* Test to validate limit considers all the data until it sees EMIT outcome
* and return output batch with data that meets the limit criteria.
*/
@Test
public void testLimitNonEmptyBatchEmitOutcome() 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());
// 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();
assertEquals(0, outputRecordCount);
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
outputRecordCount += limitBatch.getRecordCount();
assertEquals(1, outputRecordCount);
}
use of org.apache.drill.exec.physical.impl.MockRecordBatch in project drill by apache.
the class TestLimitBatchEmitOutcome method testLimitResetsAfterFirstEmitOutcome.
/**
* Test to show that once a limit number of records is produced using first
* set of batches then on getting a batch with EMIT outcome, the limit state
* is again refreshed and applied to next set of batches with data.
*/
@Test
public void testLimitResetsAfterFirstEmitOutcome() throws Throwable {
final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(2, 20, "item2").addRow(3, 30, "item3").build();
inputContainer.add(nonEmptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.container());
inputOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
inputOutcomes.add(RecordBatch.IterOutcome.EMIT);
inputOutcomes.add(RecordBatch.IterOutcome.OK);
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());
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.EMIT);
// State refresh happens and limit again works on new data batches
assertEquals(0, limitBatch.getRecordCount());
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.OK);
assertEquals(1, limitBatch.getRecordCount());
assertTrue(limitBatch.next() == RecordBatch.IterOutcome.NONE);
}
use of org.apache.drill.exec.physical.impl.MockRecordBatch in project drill by apache.
the class TestSortEmitOutcome method testSpillWithNoEmitOutcome.
/**
* Verifies successful spilling in absence of EMIT outcome
* @throws Exception
*/
@Test
public void testSpillWithNoEmitOutcome() throws Exception {
final OperatorFixture.Builder builder = OperatorFixture.builder(dirTestWatcher);
// Configuration that forces Sort to spill after buffering 2 incoming batches with data
builder.configBuilder().put(ExecConstants.EXTERNAL_SORT_BATCH_LIMIT, 2);
final OperatorFixture fixture_local = builder.build();
final RowSet.SingleRowSet local_nonEmptyInputRowSet1 = fixture_local.rowSetBuilder(inputSchema).addRow(3, 30, "item3").addRow(2, 20, "item2").build();
final RowSet.SingleRowSet local_nonEmptyInputRowSet2 = fixture_local.rowSetBuilder(inputSchema).addRow(1, 10, "item1").build();
final RowSet.SingleRowSet local_nonEmptyInputRowSet3 = fixture_local.rowSetBuilder(inputSchema).addRow(4, 40, "item4").build();
inputContainer.add(local_nonEmptyInputRowSet1.container());
inputContainer.add(local_nonEmptyInputRowSet2.container());
inputContainer.add(local_nonEmptyInputRowSet3.container());
inputOutcomes.add(OK_NEW_SCHEMA);
inputOutcomes.add(OK);
inputOutcomes.add(OK);
final PhysicalOperator mockPopConfig_local = new MockStorePOP(null);
final OperatorContext opContext_local = fixture_local.getFragmentContext().newOperatorContext(mockPopConfig_local);
final MockRecordBatch mockInputBatch = new MockRecordBatch(fixture_local.getFragmentContext(), opContext_local, inputContainer, inputOutcomes, local_nonEmptyInputRowSet1.container().getSchema());
final ExternalSortBatch sortBatch_local = new ExternalSortBatch(sortPopConfig, fixture_local.getFragmentContext(), mockInputBatch);
assertTrue(sortBatch_local.next() == OK_NEW_SCHEMA);
assertTrue(sortBatch_local.next() == OK_NEW_SCHEMA);
assertTrue(sortBatch_local.getRecordCount() == 4);
assertTrue(sortBatch_local.getSchema().getSelectionVectorMode() == BatchSchema.SelectionVectorMode.NONE);
assertTrue(sortBatch_local.next() == NONE);
// Release memory for row sets
local_nonEmptyInputRowSet1.clear();
local_nonEmptyInputRowSet2.clear();
local_nonEmptyInputRowSet3.clear();
sortBatch_local.close();
fixture_local.close();
}
Aggregations