use of org.apache.drill.exec.record.metadata.TupleNameSpace in project drill by apache.
the class TestColumnConverter method testScalarConverter.
/**
* Test doing type conversion using (ad-hoc) properties on the
* column metadata to drive conversion. Verifies that the properties
* are available to the converter.
*/
@Test
public void testScalarConverter() {
// Defined schema for scan output
TupleMetadata outputSchema = new SchemaBuilder().add("a", MinorType.INT).addArray("b", MinorType.INT).buildSchema();
// Writer
RowSetWriter writer = makeWriter(outputSchema);
// Row and column formats
TupleNameSpace<MockConverter> rowFormat = new TupleNameSpace<>();
rowFormat.add(writer.column(0).schema().name(), new MockIntConverter(writer.column(0)));
rowFormat.add(writer.column(1).schema().name(), new MockArrayConverter(writer.column(1)));
// Write data as both a string as an integer
MockSource source = new MockSource();
for (int i = 0; i < 2; i++) {
// Simulate a row
source.rowNo = i + 1;
for (int j = 0; j < rowFormat.count(); j++) {
rowFormat.get(j).setColumn(source);
}
writer.save();
}
// Verify
final SingleRowSet expected = fixture.rowSetBuilder(outputSchema).addRow(10, intArray(101, 102, 103)).addRow(20, intArray(201, 202, 203)).build();
RowSetUtilities.verify(expected, writer.done());
}
Aggregations