The RowSet Framework allows you to create custom instances of:
- BatchSchema
- VectorContainer
- TupleMetadata
- RecordBatch: This is effectively a fake instance of an upstream operator.
It also allows the comparison of data container in VectorContainers through the use of the RowSetComparison and RowSetUtilities.
Creating A BatchSchema
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.
Creating TupleMetadata
TupleMetadata schema = new SchemaBuilder()
.add(...)
.add(...)
.buildSchema();
Creating Test VectorContainer
VectorContainers populated with data can be created with the RowSetBuilder. In order to use it do the following:
- Create an allocator
BufferAllocator allocator = operatorFixture.allocator();
- Create the desired BatchSchema using the SchemaBuilder.
TupleMetadata schema = new SchemaBuilder() .add(...) .add(...) .buildSchema();
- Create a RowSetBuilder and add
records to it. Then build a RowSet.
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();
- Retrieve the VectorContainer wrapped by the
RowSet.
VectorContainer container = rowSet.container();
Create a RowSet and then create a RowSetBatch
RecordBatch batch = new RowSetBatch(rowSet);
Compare Two RowSets
Use RowSetUtilities.
RowSetUtilities.verify(expectedRowSet, actualRowSet)
Compare A VectorContainer To A RowSet
You can convert a VectorContainer into a RowSet a few ways:
- If you are using an OperatorFixture the best way to do this is with:
operatorFixture.wrap(container);
- When there is no selection vector you can do the following:
RowSet rowSet = DirectRowSet.fromContainer(container);
- When there is a SelectionVector2.
RowSet rowSet = IndirectRowSet.fromSv2(container, container.getSelectionVector2());
- When there is a SelectionVector4.
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.