use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestSequenceFileReader method testExplicitQuery.
@Test
public void testExplicitQuery() throws Exception {
String sql = "select convert_from(binary_key, 'UTF8') as binary_key from cp.`sequencefiles/simple.seq`";
QueryBuilder builder = client.queryBuilder().sql(sql);
RowSet sets = builder.rowSet();
TupleMetadata schema = new SchemaBuilder().addNullable(SequenceFileBatchReader.KEY_SCHEMA, MinorType.VARCHAR).build();
RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow(byteWritableString("key0")).addRow(byteWritableString("key1")).build();
assertEquals(2, sets.rowCount());
new RowSetComparison(expected).verifyAndClearAll(sets);
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestSortEmitOutcome method testSortEmptyBatchFollowedByNonEmptyBatchEmitOutcome.
/**
* Verifies ExternalSortBatch behavior when it receives first incoming batch post buildSchema phase as empty batch
* with EMIT outcome followed by non-empty batch with EMIT outcome. Expectation is sort will handle the EMIT
* boundary correctly and produce 2 empty output batch for first EMIT outcome and 1 non-empty output batch for second
* EMIT outcome.
*/
@Test
public void testSortEmptyBatchFollowedByNonEmptyBatchEmitOutcome() {
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(2, 20, "item2").addRow(4, 40, "item4").addRow(13, 130, "item13").build();
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.container());
inputOutcomes.add(OK_NEW_SCHEMA);
inputOutcomes.add(EMIT);
inputOutcomes.add(EMIT);
final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
sortBatch = new ExternalSortBatch(sortPopConfig, operatorFixture.getFragmentContext(), mockInputBatch);
// BuildSchema phase
assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
outputRecordCount += sortBatch.getRecordCount();
assertEquals(0, outputRecordCount);
// Output for first empty EMIT batch
assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
assertTrue(sortBatch.next() == EMIT);
outputRecordCount += sortBatch.getRecordCount();
assertEquals(0, outputRecordCount);
// Output for second non-empty EMIT batch
assertTrue(sortBatch.next() == EMIT);
outputRecordCount += sortBatch.getRecordCount();
assertEquals(3, outputRecordCount);
// verify results
RowSet actualRowSet = HyperRowSetImpl.fromContainer(sortBatch.getContainer(), sortBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet).verify(actualRowSet);
// Release memory for row sets
nonEmptyInputRowSet2.clear();
expectedRowSet.clear();
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestSortEmitOutcome method testSort_NonEmptyFirst_EmptyOKEmitOutcome.
/**
* Verifies ExternalSortBatch behavior when it receives incoming batches with different IterOutcomes like
* OK_NEW_SCHEMA / OK / EMIT / NONE
*/
@Test
public void testSort_NonEmptyFirst_EmptyOKEmitOutcome() {
final RowSet.SingleRowSet expectedRowSet = operatorFixture.rowSetBuilder(inputSchema).addRow(1, 10, "item1").build();
inputContainer.add(nonEmptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputOutcomes.add(OK_NEW_SCHEMA);
inputOutcomes.add(OK);
inputOutcomes.add(EMIT);
inputOutcomes.add(NONE);
final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
sortBatch = new ExternalSortBatch(sortPopConfig, operatorFixture.getFragmentContext(), mockInputBatch);
// BuildSchema phase output
assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
assertEquals(0, sortBatch.getRecordCount());
// Output batch 1 for first 3 input batches with OK_NEW_SCHEMA/OK/EMIT outcome
assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
assertEquals(1, sortBatch.getRecordCount());
// verify results
RowSet actualRowSet = HyperRowSetImpl.fromContainer(sortBatch.getContainer(), sortBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet).verify(actualRowSet);
// Output batch 2 for first 3 input batches with OK_NEW_SCHEMA/OK/EMIT outcome
assertTrue(sortBatch.next() == EMIT);
assertEquals(0, sortBatch.getRecordCount());
// Output batch for NONE outcome
assertTrue(sortBatch.next() == NONE);
// Release memory for row set
expectedRowSet.clear();
}
use of org.apache.drill.test.rowSet.RowSetComparison in project drill by apache.
the class TestSortEmitOutcome method testTopNMultipleOutputBatch.
@Test
public void testTopNMultipleOutputBatch() {
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(2, 20, "item2").addRow(3, 30, "item3").addRow(4, 40, "item4").addRow(5, 50, "item5").build();
inputContainer.add(nonEmptyInputRowSet.container());
inputContainer.add(emptyInputRowSet.container());
inputContainer.add(nonEmptyInputRowSet2.container());
inputOutcomes.add(OK_NEW_SCHEMA);
inputOutcomes.add(EMIT);
inputOutcomes.add(OK);
final MockRecordBatch mockInputBatch = new MockRecordBatch(operatorFixture.getFragmentContext(), opContext, inputContainer, inputOutcomes, emptyInputRowSet.container().getSchema());
sortBatch = new ExternalSortBatch(sortPopConfig, operatorFixture.getFragmentContext(), mockInputBatch);
// BuildSchema phase output
assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
// Output batch 1 for first EMIT outcome
assertTrue(sortBatch.next() == OK_NEW_SCHEMA);
assertEquals(1, sortBatch.getRecordCount());
// verify results
RowSet actualRowSet1 = HyperRowSetImpl.fromContainer(sortBatch.getContainer(), sortBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet1).verify(actualRowSet1);
// Output batch 2 for first EMIT outcome
assertTrue(sortBatch.next() == EMIT);
assertEquals(0, sortBatch.getRecordCount());
// Output batch for OK outcome
assertTrue(sortBatch.next() == OK);
assertEquals(4, sortBatch.getRecordCount());
// verify results
RowSet actualRowSet2 = HyperRowSetImpl.fromContainer(sortBatch.getContainer(), sortBatch.getSelectionVector4());
new RowSetComparison(expectedRowSet2).verify(actualRowSet2);
// Output batch for NONE outcome
assertTrue(sortBatch.next() == 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 TestPcapngStatRecordReader method testExplicitQuery.
@Test
public void testExplicitQuery() throws Exception {
String sql = "select path, shb_hardware, shb_os, if_name, isb_ifrecv from dfs.`pcapng/sniff.pcapng`";
QueryBuilder builder = client.queryBuilder().sql(sql);
RowSet sets = builder.rowSet();
TupleMetadata schema = new SchemaBuilder().addNullable("path", MinorType.VARCHAR).addNullable("shb_hardware", MinorType.VARCHAR).addNullable("shb_os", MinorType.VARCHAR).addNullable("if_name", MinorType.VARCHAR).addNullable("isb_ifrecv", MinorType.BIGINT).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow("sniff.pcapng", "Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (with SSE4.2)", "Mac OS X 10.13.3, build 17D47 (Darwin 17.4.0)", null, null).addRow("sniff.pcapng", null, null, "en0", null).addRow("sniff.pcapng", null, null, null, 123).build();
assertEquals(3, sets.rowCount());
new RowSetComparison(expected).verifyAndClearAll(sets);
}
Aggregations