use of org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema in project drill by apache.
the class AbstractSingleRowSet method buildReader.
/**
* Internal method to build the set of column readers needed for
* this row set. Used when building a row set reader.
* @param rowIndex object that points to the current row
* @return an array of column readers: in the same order as the
* (non-map) vectors.
*/
protected RowSetReader buildReader(RowSetIndex rowIndex) {
FlattenedSchema accessSchema = schema().flatAccess();
ValueVector[] valueVectors = vectors();
AbstractColumnReader[] readers = new AbstractColumnReader[valueVectors.length];
for (int i = 0; i < readers.length; i++) {
MinorType type = accessSchema.column(i).getType().getMinorType();
if (type == MinorType.MAP) {
// buildMapAccessor(i);
readers[i] = null;
} else if (type == MinorType.LIST) {
// buildListAccessor(i);
readers[i] = null;
} else {
readers[i] = ColumnAccessorFactory.newReader(valueVectors[i].getField().getType());
readers[i].bind(rowIndex, valueVectors[i]);
}
}
return new RowSetReaderImpl(accessSchema, rowIndex, readers);
}
use of org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema in project drill by apache.
the class HyperRowSetImpl method buildReader.
/**
* Internal method to build the set of column readers needed for
* this row set. Used when building a row set reader.
* @param rowIndex object that points to the current row
* @return an array of column readers: in the same order as the
* (non-map) vectors.
*/
protected RowSetReader buildReader(HyperRowIndex rowIndex) {
FlattenedSchema accessSchema = schema().flatAccess();
AbstractColumnReader[] readers = new AbstractColumnReader[accessSchema.count()];
for (int i = 0; i < readers.length; i++) {
MaterializedField field = accessSchema.column(i);
readers[i] = ColumnAccessorFactory.newReader(field.getType());
HyperVectorWrapper<ValueVector> hvw = getHyperVector(i);
readers[i].bind(rowIndex, field, new HyperVectorAccessor(hvw, rowIndex));
}
return new RowSetReaderImpl(accessSchema, rowIndex, readers);
}
use of org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema in project drill by apache.
the class RowSetTest method testMapSchema.
@Test
public void testMapSchema() {
BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).addMap("a").addNullable("b", MinorType.VARCHAR).add("d", MinorType.INT).addMap("e").add("f", MinorType.VARCHAR).buildMap().add("g", MinorType.INT).buildMap().add("h", MinorType.BIGINT).build();
RowSetSchema schema = new RowSetSchema(batchSchema);
// Access schema: flattened with maps removed
FlattenedSchema access = schema.flatAccess();
assertEquals(6, access.count());
crossCheck(access, 0, "c", MinorType.INT);
crossCheck(access, 1, "a.b", MinorType.VARCHAR);
crossCheck(access, 2, "a.d", MinorType.INT);
crossCheck(access, 3, "a.e.f", MinorType.VARCHAR);
crossCheck(access, 4, "a.g", MinorType.INT);
crossCheck(access, 5, "h", MinorType.BIGINT);
// Should have two maps.
assertEquals(2, access.mapCount());
assertEquals("a", access.map(0).getName());
assertEquals("e", access.map(1).getName());
assertEquals(0, access.mapIndex("a"));
assertEquals(1, access.mapIndex("a.e"));
// Verify physical schema: should mirror the schema created above.
PhysicalSchema physical = schema.physical();
assertEquals(3, physical.count());
assertEquals("c", physical.column(0).field().getName());
assertEquals("c", physical.column(0).fullName());
assertFalse(physical.column(0).isMap());
assertNull(physical.column(0).mapSchema());
assertEquals("a", physical.column(1).field().getName());
assertEquals("a", physical.column(1).fullName());
assertTrue(physical.column(1).isMap());
assertNotNull(physical.column(1).mapSchema());
assertEquals("h", physical.column(2).field().getName());
assertEquals("h", physical.column(2).fullName());
assertFalse(physical.column(2).isMap());
assertNull(physical.column(2).mapSchema());
PhysicalSchema aSchema = physical.column(1).mapSchema();
assertEquals(4, aSchema.count());
assertEquals("b", aSchema.column(0).field().getName());
assertEquals("a.b", aSchema.column(0).fullName());
assertEquals("d", aSchema.column(1).field().getName());
assertEquals("e", aSchema.column(2).field().getName());
assertEquals("g", aSchema.column(3).field().getName());
PhysicalSchema eSchema = aSchema.column(2).mapSchema();
assertEquals(1, eSchema.count());
assertEquals("f", eSchema.column(0).field().getName());
assertEquals("a.e.f", eSchema.column(0).fullName());
}
Aggregations