use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestHDF5Format method testStarQueryWithoutPreview.
@Test
public void testStarQueryWithoutPreview() throws Exception {
String sql = "SELECT * FROM table(dfs.`hdf5/dset.h5` (type => 'hdf5', showPreview => false))";
RowSet results = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("path", MinorType.VARCHAR, DataMode.OPTIONAL).add("data_type", MinorType.VARCHAR, DataMode.OPTIONAL).add("file_name", MinorType.VARCHAR, DataMode.OPTIONAL).add("data_size", MinorType.BIGINT, DataMode.OPTIONAL).add("is_link", MinorType.BIT, DataMode.OPTIONAL).add("element_count", MinorType.BIGINT, DataMode.OPTIONAL).add("dataset_data_type", MinorType.VARCHAR, DataMode.OPTIONAL).add("dimensions", MinorType.VARCHAR, DataMode.OPTIONAL).build();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("/dset", "DATASET", "dset.h5", 96, false, 24, "int", "[4, 6]").build();
new RowSetComparison(expected).verifyAndClearAll(results);
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestPartitionLimitBatch method testPartitionLimitCommon.
/**
* Common method used by all the tests for {@link PartitionLimitRecordBatch} below. It creates the MockRecordBatch
* and {@link PartitionLimitRecordBatch} with the populated containers and outcomes list in the test. It also
* verifies the expected outcomes list and record count populated by each test against each next() call to
* {@link PartitionLimitRecordBatch}. For cases when the expected record count is >0 it verifies the actual output
* returned by {@link PartitionLimitRecordBatch} with expected output rows.
* @param start - Start offset for {@link PartitionLimit} PopConfig
* @param end - End offset for {@link PartitionLimit} PopConfig
*/
private void testPartitionLimitCommon(Integer start, Integer end) {
final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, inputContainerSv2, inputContainer.get(0).getSchema());
final PartitionLimit limitConf = new PartitionLimit(null, start, end, PARTITION_COLUMN);
limitBatch = new PartitionLimitRecordBatch(limitConf, operatorFixture.getFragmentContext(), mockInputBatch);
int i = 0;
int expectedRowSetIndex = 0;
while (i < expectedOutcomes.size()) {
try {
assertTrue(expectedOutcomes.get(i) == limitBatch.next());
assertTrue(expectedRecordCounts.get(i++) == limitBatch.getRecordCount());
if (limitBatch.getRecordCount() > 0) {
final RowSet actualRowSet = IndirectRowSet.fromSv2(limitBatch.getContainer(), limitBatch.getSelectionVector2());
new RowSetComparison(expectedRowSets.get(expectedRowSetIndex++)).verify(actualRowSet);
}
} finally {
limitBatch.getSelectionVector2().clear();
limitBatch.getContainer().zeroVectors();
}
}
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestStreamingAggEmitOutcome method t2_testStreamingAggrNonEmptyBatchEmitOutcome.
/**
* Verifies that if StreamingAgg receives a RecordBatch with EMIT outcome post build schema phase then it produces
* output for those input batch correctly. The first output batch will always be returned with OK_NEW_SCHEMA
* outcome followed by EMIT with empty batch. The test verifies the output order with the expected baseline.
*/
@Test
public void t2_testStreamingAggrNonEmptyBatchEmitOutcome() {
final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(13, 130, "item13").addRow(13, 130, "item13").addRow(2, 20, "item2").addRow(2, 20, "item2").addRow(4, 40, "item4").build();
final RowSet.SingleRowSet expectedRowSet = operatorFixture.rowSetBuilder(resultSchema).addRow("item1", (long) 11).addRow("item13", (long) 286).addRow("item2", (long) 44).addRow("item4", (long) 44).build();
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.container());
inputOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
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 StreamingAggregate streamAggrConfig = new StreamingAggregate(null, parseExprs("name_left", "name"), parseExprs("sum(id_left+cost_left)", "total_sum"));
final StreamingAggBatch strAggBatch = new StreamingAggBatch(streamAggrConfig, mockInputBatch, operatorFixture.getFragmentContext());
assertTrue(strAggBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
// Data before EMIT is returned with an OK_NEW_SCHEMA.
assertTrue(strAggBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
assertEquals(4, strAggBatch.getRecordCount());
RowSet actualRowSet = DirectRowSet.fromContainer(strAggBatch.getContainer());
new RowSetComparison(expectedRowSet).verify(actualRowSet);
// EMIT comes with an empty batch
assertTrue(strAggBatch.next() == RecordBatch.IterOutcome.EMIT);
assertTrue(strAggBatch.next() == RecordBatch.IterOutcome.NONE);
// Release memory for row sets
nonEmptyInputRowSet2.clear();
expectedRowSet.clear();
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestTopNEmitOutcome method testTopNMultipleOutputBatchWithLowerLimits.
/**
* Verifies that if TopNBatch receives multiple non-empty record batch with EMIT outcome in between then it produces
* output for those input batch correctly. In this case it receives first non-empty batch with OK_NEW_SCHEMA in
* buildSchema phase followed by an empty batch with EMIT outcome. For this combination it produces output for the
* record received so far along with EMIT outcome. Then it receives second non-empty batch with OK outcome and
* produces output for it differently. The test validates that for each output received the order of the records are
* correct
*/
@Test
public void testTopNMultipleOutputBatchWithLowerLimits() {
final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(4, 40, "item4").addRow(2, 20, "item2").addRow(5, 50, "item5").addRow(3, 30, "item3").build();
final RowSet.SingleRowSet expectedRowSet1 = operatorFixture.rowSetBuilder(inputSchema).addRow(1, 10, "item1").build();
final RowSet.SingleRowSet expectedRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(5, 50, "item5").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());
final TopN topNConfig = new TopN(null, Lists.newArrayList(ordering("id_left", RelFieldCollation.Direction.DESCENDING, RelFieldCollation.NullDirection.FIRST)), false, 1);
final TopNBatch topNBatch = new TopNBatch(topNConfig, operatorFixture.getFragmentContext(), mockInputBatch);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
assertEquals(1, topNBatch.getRecordCount());
// verify results with baseline
RowSet actualRowSet1 = HyperRowSetImpl.fromContainer(topNBatch.getContainer(), topNBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet1).verify(actualRowSet1);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.EMIT);
assertEquals(0, topNBatch.getRecordCount());
// State refresh happens and limit again works on new data batches
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.OK);
assertEquals(1, topNBatch.getRecordCount());
// verify results with baseline
RowSet actualRowSet2 = HyperRowSetImpl.fromContainer(topNBatch.getContainer(), topNBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet2).verify(actualRowSet2);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.NONE);
// Release memory for row sets
nonEmptyInputRowSet2.clear();
expectedRowSet2.clear();
expectedRowSet1.clear();
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestTopNEmitOutcome method testTopNNonEmptyBatchEmitOutcome.
/**
* Verifies that if TopNBatch receives a RecordBatch with EMIT outcome post build schema phase then it produces
* output for those input batch correctly. The first output batch will always be returned with OK_NEW_SCHEMA
* outcome followed by EMIT with empty batch. The test verifies the output order with the expected baseline.
*/
@Test
public void testTopNNonEmptyBatchEmitOutcome() {
final RowSet.SingleRowSet nonEmptyInputRowSet2 = operatorFixture.rowSetBuilder(inputSchema).addRow(2, 20, "item2").addRow(13, 130, "item13").addRow(4, 40, "item4").build();
final RowSet.SingleRowSet expectedRowSet = operatorFixture.rowSetBuilder(inputSchema).addRow(13, 130, "item13").addRow(4, 40, "item4").addRow(2, 20, "item2").build();
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.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 TopN topNConfig = new TopN(null, Lists.newArrayList(ordering("id_left", RelFieldCollation.Direction.DESCENDING, RelFieldCollation.NullDirection.FIRST)), false, 10);
final TopNBatch topNBatch = new TopNBatch(topNConfig, operatorFixture.getFragmentContext(), mockInputBatch);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
outputRecordCount += topNBatch.getRecordCount();
assertEquals(0, outputRecordCount);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.OK_NEW_SCHEMA);
outputRecordCount += topNBatch.getRecordCount();
assertEquals(3, outputRecordCount);
// verify results
RowSet actualRowSet = HyperRowSetImpl.fromContainer(topNBatch.getContainer(), topNBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet).verify(actualRowSet);
assertTrue(topNBatch.next() == RecordBatch.IterOutcome.EMIT);
outputRecordCount += topNBatch.getRecordCount();
assertEquals(3, outputRecordCount);
// Release memory for row sets
nonEmptyInputRowSet2.clear();
expectedRowSet.clear();
}
Aggregations