Search in sources :

Example 1 with PrimitiveColumnState

use of org.apache.drill.exec.physical.resultSet.impl.ColumnState.PrimitiveColumnState in project drill by apache.

the class ColumnBuilder method buildPrimitive.

/**
 * Build a primitive column. Check if the column is projected. If not,
 * allocate a dummy writer for the column. If projected, then allocate
 * a vector, a writer, and the column state which binds the two together
 * and manages the column.
 *
 * @param parent schema of the new primitive column
 * @param columnSchema implied projection type for the column
 * @return column state for the new column
 */
private ColumnState buildPrimitive(ContainerState parent, ColumnMetadata columnSchema) {
    final ValueVector vector;
    if (parent.projection().projection(columnSchema).isProjected || allowCreation(parent)) {
        // Create the vector for the column.
        vector = parent.vectorCache().vectorFor(columnSchema.schema());
        // from that requested. Update the schema to match.
        if (parent.vectorCache().isPermissive() && !vector.getField().isEquivalent(columnSchema.schema())) {
            columnSchema = ((PrimitiveColumnMetadata) columnSchema).mergeWith(vector.getField());
        }
    } else {
        // Column is not projected. No materialized backing for the column.
        vector = null;
    }
    // Create the writer.
    final AbstractObjectWriter colWriter = ColumnWriterFactory.buildColumnWriter(columnSchema, vector);
    // Build the vector state which manages the vector.
    VectorState vectorState;
    if (vector == null) {
        vectorState = new NullVectorState();
    } else if (columnSchema.isArray()) {
        vectorState = new RepeatedVectorState(colWriter.array(), (RepeatedValueVector) vector);
    } else if (columnSchema.isNullable()) {
        vectorState = new NullableVectorState(colWriter, (NullableVector) vector);
    } else {
        vectorState = SimpleVectorState.vectorState(columnSchema, colWriter.events(), vector);
    }
    // Create the column state which binds the vector and writer together.
    return new PrimitiveColumnState(parent.loader(), colWriter, vectorState);
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) NullableVector(org.apache.drill.exec.vector.NullableVector) PrimitiveColumnState(org.apache.drill.exec.physical.resultSet.impl.ColumnState.PrimitiveColumnState) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) MapVectorState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState) RepeatedListVectorState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState) UnionVectorState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState) OffsetVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState) ListVectorState(org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState) SimpleVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)

Aggregations

PrimitiveColumnState (org.apache.drill.exec.physical.resultSet.impl.ColumnState.PrimitiveColumnState)1 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)1 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)1 OffsetVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState)1 SimpleVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)1 MapVectorState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState)1 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)1 NullableVector (org.apache.drill.exec.vector.NullableVector)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)1 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)1