Search in sources :

Example 1 with TupleNameSpace

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());
}
Also used : RowSetWriter(org.apache.drill.exec.physical.rowSet.RowSetWriter) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) TupleNameSpace(org.apache.drill.exec.record.metadata.TupleNameSpace) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)1 RowSetWriter (org.apache.drill.exec.physical.rowSet.RowSetWriter)1 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)1 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1 TupleNameSpace (org.apache.drill.exec.record.metadata.TupleNameSpace)1 SubOperatorTest (org.apache.drill.test.SubOperatorTest)1 Test (org.junit.Test)1