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);
}
Aggregations