Search in sources :

Example 1 with TupleSchema

use of org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema in project drill by apache.

the class DirectRowSet method buildWriter.

/**
   * Build writer objects for each column based on the column type.
   *
   * @param rowIndex the index which points to each row
   * @return an array of writers
   */
protected RowSetWriter buildWriter(ExtendableRowIndex rowIndex) {
    ValueVector[] valueVectors = vectors();
    AbstractColumnWriter[] writers = new AbstractColumnWriter[valueVectors.length];
    for (int i = 0; i < writers.length; i++) {
        writers[i] = ColumnAccessorFactory.newWriter(valueVectors[i].getField().getType());
        writers[i].bind(rowIndex, valueVectors[i]);
    }
    TupleSchema accessSchema = schema().hierarchicalAccess();
    return new RowSetWriterImpl(this, accessSchema, rowIndex, writers);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) AbstractColumnWriter(org.apache.drill.exec.vector.accessor.impl.AbstractColumnWriter) TupleSchema(org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema)

Example 2 with TupleSchema

use of org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema in project drill by apache.

the class RowSetPrinter method printSchema.

private void printSchema(PrintStream out, SelectionVectorMode selectionMode) {
    out.print("#");
    switch(selectionMode) {
        case FOUR_BYTE:
            out.print(" (batch #, row #)");
            break;
        case TWO_BYTE:
            out.print(" (row #)");
            break;
        default:
            break;
    }
    out.print(": ");
    TupleSchema schema = rowSet.schema().hierarchicalAccess();
    for (int i = 0; i < schema.count(); i++) {
        if (i > 0) {
            out.print(", ");
        }
        out.print(schema.column(i).getLastName());
    }
    out.println();
}
Also used : TupleSchema(org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema)

Example 3 with TupleSchema

use of org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema in project drill by apache.

the class RowSetTest method testSchema.

/**
   * Test a simple physical schema with no maps.
   */
@Test
public void testSchema() {
    BatchSchema batchSchema = new SchemaBuilder().add("c", MinorType.INT).add("a", MinorType.INT, DataMode.REPEATED).addNullable("b", MinorType.VARCHAR).build();
    assertEquals("c", batchSchema.getColumn(0).getName());
    assertEquals("a", batchSchema.getColumn(1).getName());
    assertEquals("b", batchSchema.getColumn(2).getName());
    RowSetSchema schema = new RowSetSchema(batchSchema);
    TupleSchema access = schema.hierarchicalAccess();
    assertEquals(3, access.count());
    crossCheck(access, 0, "c", MinorType.INT);
    assertEquals(DataMode.REQUIRED, access.column(0).getDataMode());
    assertEquals(DataMode.REQUIRED, access.column(0).getType().getMode());
    assertTrue(!access.column(0).isNullable());
    crossCheck(access, 1, "a", MinorType.INT);
    assertEquals(DataMode.REPEATED, access.column(1).getDataMode());
    assertEquals(DataMode.REPEATED, access.column(1).getType().getMode());
    assertTrue(!access.column(1).isNullable());
    crossCheck(access, 2, "b", MinorType.VARCHAR);
    assertEquals(MinorType.VARCHAR, access.column(2).getType().getMinorType());
    assertEquals(DataMode.OPTIONAL, access.column(2).getDataMode());
    assertEquals(DataMode.OPTIONAL, access.column(2).getType().getMode());
    assertTrue(access.column(2).isNullable());
    // No maps: physical schema is the same as access schema.
    PhysicalSchema physical = schema.physical();
    assertEquals(3, physical.count());
    assertEquals("c", physical.column(0).field().getName());
    assertEquals("a", physical.column(1).field().getName());
    assertEquals("b", physical.column(2).field().getName());
}
Also used : PhysicalSchema(org.apache.drill.test.rowSet.RowSetSchema.PhysicalSchema) BatchSchema(org.apache.drill.exec.record.BatchSchema) SchemaBuilder(org.apache.drill.test.rowSet.SchemaBuilder) RowSetSchema(org.apache.drill.test.rowSet.RowSetSchema) TupleSchema(org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema) Test(org.junit.Test)

Aggregations

TupleSchema (org.apache.drill.exec.vector.accessor.TupleAccessor.TupleSchema)3 BatchSchema (org.apache.drill.exec.record.BatchSchema)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 AbstractColumnWriter (org.apache.drill.exec.vector.accessor.impl.AbstractColumnWriter)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