use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.
the class ColumnBuilder method buildDictArray.
private ColumnState buildDictArray(ContainerState parent, ColumnMetadata columnSchema) {
final ProjectionFilter projFilter = parent.projection();
final ProjResult projResult = projFilter.projection(columnSchema);
// Create the dict's offset vector.
final RepeatedDictVector repeatedDictVector;
final UInt4Vector offsetVector;
if (projResult.isProjected) {
// Creating the dict vector will create its contained vectors if we
// give it a materialized field with children. So, instead pass a clone
// without children so we can add them.
final ColumnMetadata dictColMetadata = columnSchema.cloneEmpty();
assert columnSchema.tupleSchema().isEmpty();
repeatedDictVector = new RepeatedDictVector(dictColMetadata.schema(), parent.loader().allocator(), null);
offsetVector = repeatedDictVector.getOffsetVector();
} else {
repeatedDictVector = null;
offsetVector = null;
}
// Create the writer using the offset vector
final AbstractObjectWriter writer = ObjectDictWriter.buildDictArray(columnSchema, repeatedDictVector, new ArrayList<>());
// Wrap the offset vector in a vector state
VectorState offsetVectorState;
VectorState dictOffsetVectorState;
if (!projResult.isProjected) {
offsetVectorState = new NullVectorState();
dictOffsetVectorState = new NullVectorState();
} else {
AbstractArrayWriter arrayWriter = (AbstractArrayWriter) writer.array();
offsetVectorState = new OffsetVectorState(arrayWriter.offsetWriter(), offsetVector, writer.array().entry().events());
dictOffsetVectorState = new OffsetVectorState(((AbstractArrayWriter) arrayWriter.array()).offsetWriter(), ((DictVector) repeatedDictVector.getDataVector()).getOffsetVector(), writer.array().entry().dict().entry().events());
}
final VectorState mapVectorState = new TupleState.DictArrayVectorState(repeatedDictVector, offsetVectorState, dictOffsetVectorState);
// Assemble it all into the column state.
final TupleState.DictArrayState dictArrayState = new TupleState.DictArrayState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()), projResult.mapFilter);
return new TupleState.DictColumnState(dictArrayState, writer, mapVectorState, parent.isVersioned());
}
Aggregations