Search in sources :

Example 1 with FlattenedSchema

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);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) FlattenedSchema(org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) AbstractColumnReader(org.apache.drill.exec.vector.accessor.impl.AbstractColumnReader)

Example 2 with FlattenedSchema

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);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) FlattenedSchema(org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema) MaterializedField(org.apache.drill.exec.record.MaterializedField) AbstractColumnReader(org.apache.drill.exec.vector.accessor.impl.AbstractColumnReader)

Example 3 with FlattenedSchema

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());
}
Also used : PhysicalSchema(org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema) BatchSchema(org.apache.drill.exec.record.BatchSchema) FlattenedSchema(org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetSchema(org.apache.drill.test.rowSet.RowSetSchema) Test(org.junit.Test)

Aggregations

FlattenedSchema (org.apache.drill.test.rowSet.RowSetSchema.FlattenedSchema)3 ValueVector (org.apache.drill.exec.vector.ValueVector)2 AbstractColumnReader (org.apache.drill.exec.vector.accessor.impl.AbstractColumnReader)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 MaterializedField (org.apache.drill.exec.record.MaterializedField)1 RowSetSchema (org.apache.drill.test.rowSet.RowSetSchema)1 PhysicalSchema (org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema)1 SchemaBuilder (org.apache.drill.test.rowSet.SchemaBuilder)1 Test (org.junit.Test)1