Search in sources :

Example 6 with RepeatedDictVector

use of org.apache.drill.exec.vector.complex.RepeatedDictVector in project drill by apache.

the class BuildVectorsFromMetadata method buildRepeatedDict.

private RepeatedDictVector buildRepeatedDict(ColumnMetadata schema) {
    // Creating the repeated 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 the children as we add vectors.
    final RepeatedDictVector repeatedDictVector = (RepeatedDictVector) TypeHelper.getNewVector(schema.emptySchema(), allocator, null);
    populateDict(repeatedDictVector, schema.tupleSchema());
    return repeatedDictVector;
}
Also used : RepeatedDictVector(org.apache.drill.exec.vector.complex.RepeatedDictVector)

Example 7 with RepeatedDictVector

use of org.apache.drill.exec.vector.complex.RepeatedDictVector in project drill by apache.

the class BuildVectorsFromMetadata method populateDict.

private void populateDict(RepeatedDictVector vector, TupleMetadata dictMetadata) {
    for (int i = 0; i < dictMetadata.size(); i++) {
        final ColumnMetadata childSchema = dictMetadata.metadata(i);
        DictVector dataVector = (DictVector) vector.getDataVector();
        dataVector.putChild(childSchema.name(), buildVector(childSchema));
    }
}
Also used : DictVector(org.apache.drill.exec.vector.complex.DictVector) RepeatedDictVector(org.apache.drill.exec.vector.complex.RepeatedDictVector) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata)

Example 8 with RepeatedDictVector

use of org.apache.drill.exec.vector.complex.RepeatedDictVector 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());
}
Also used : DictVector(org.apache.drill.exec.vector.complex.DictVector) RepeatedDictVector(org.apache.drill.exec.vector.complex.RepeatedDictVector) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) OffsetVectorState(org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) AbstractArrayWriter(org.apache.drill.exec.vector.accessor.writer.AbstractArrayWriter) RepeatedDictVector(org.apache.drill.exec.vector.complex.RepeatedDictVector) 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

RepeatedDictVector (org.apache.drill.exec.vector.complex.RepeatedDictVector)8 DictVector (org.apache.drill.exec.vector.complex.DictVector)5 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)3 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)2 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)2 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)2 DictWriter (org.apache.drill.exec.vector.accessor.DictWriter)2 AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)2 SubOperatorTest (org.apache.drill.test.SubOperatorTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ResultSetLoader (org.apache.drill.exec.physical.resultSet.ResultSetLoader)1 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)1 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)1 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)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