The RowSet Framework allows you to create custom instances of:
It also allows the comparison of data container in VectorContainers through the use of the RowSetComparison and RowSetUtilities.
The SchemaBuilder class can be used to create an instance BatchSchema. An example of how to to this can be found the secondTest() method of ExampleTest.
Note: The BatchSchema class has limited complex type support. When possible use TupleMetadata and TupleSchema instead.
TupleMetadata schema = new SchemaBuilder() .add(...) .add(...) .buildSchema();
VectorContainers populated with data can be created with the RowSetBuilder. In order to use it do the following:
BufferAllocator allocator = operatorFixture.allocator();
TupleMetadata schema = new SchemaBuilder() .add(...) .add(...) .buildSchema();
RowSet rowSet = new RowSetBuilder(allocator, schema) .addRow(110, "green", new floatArray(5.5f, 2.3f), strArray("1a", "1b")) .addRow(109, "blue", new floatArray(1.5f), strArray("2a")) .addRow(108, "red", new floatArray(-11.1f, 0.0f, .5f), strArray("3a", "3b", "3c")) .build();
VectorContainer container = rowSet.container();
Create a RowSet and then create a RowSetBatch
MockRecordBatch.Builder rowSetBatchBuilder = new MockRecordBatch.Builder() .sendData(rowSet)
Use RowSetUtilities.
RowSetUtilities.verify(expectedRowSet, actualRowSet)
You can convert a VectorContainer into a RowSet a few ways:
operatorFixture.wrap(container);
RowSet rowSet = DirectRowSet.fromContainer(container);
RowSet rowSet = IndirectRowSet.fromSv2(container, container.getSelectionVector2());
RowSet rowSet = HyperRowSetImpl.fromContainer(container, container.getSelectionVector4());
After the VectorContainer is wrapped in a [RowSet](../. ./exec/java-exec/src/test/java/org/apache/drill/test/rowSet/RowSet.java) you can compare the two RowSets as usual.
A good example of building a RowSet and comparing results can be found in the testInitialSchema() test in TestResultSetLoaderProtocol.