Search in sources :

Example 1 with MapColumnState

use of org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState in project drill by apache.

the class ColumnBuilder method buildMapArray.

private ColumnState buildMapArray(ContainerState parent, ColumnMetadata columnSchema) {
    final ProjectionFilter projFilter = parent.projection();
    final ProjResult projResult = projFilter.projection(columnSchema);
    // Create the map's offset vector.
    final RepeatedMapVector mapVector;
    final UInt4Vector offsetVector;
    if (projResult.isProjected) {
        // Creating the map 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 mapColSchema = columnSchema.cloneEmpty();
        // vectors can be cached.
        assert columnSchema.tupleSchema().isEmpty();
        mapVector = new RepeatedMapVector(mapColSchema.schema(), parent.loader().allocator(), null);
        offsetVector = mapVector.getOffsetVector();
    } else {
        mapVector = null;
        offsetVector = null;
    }
    // Create the writer using the offset vector
    final AbstractObjectWriter writer = MapWriter.buildMapArray(columnSchema, mapVector, new ArrayList<>());
    // Wrap the offset vector in a vector state
    VectorState offsetVectorState;
    if (!projResult.isProjected) {
        offsetVectorState = new NullVectorState();
    } else {
        offsetVectorState = new OffsetVectorState((((AbstractArrayWriter) writer.array()).offsetWriter()), offsetVector, writer.array().entry().events());
    }
    final VectorState mapVectorState = new MapVectorState(mapVector, offsetVectorState);
    // Assemble it all into the column state.
    final MapArrayState mapState = new MapArrayState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()), projResult.mapFilter);
    return new MapColumnState(mapState, writer, mapVectorState, parent.isVersioned());
}
Also used : 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) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) MapColumnState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) MapVectorState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState) 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) MapArrayState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapArrayState)

Example 2 with MapColumnState

use of org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState in project drill by apache.

the class ColumnBuilder method buildSingleMap.

private ColumnState buildSingleMap(ContainerState parent, ColumnMetadata columnSchema) {
    final ProjectionFilter projFilter = parent.projection();
    final ProjResult projResult = projFilter.projection(columnSchema);
    final MapVector vector;
    final VectorState vectorState;
    if (projResult.isProjected) {
        // vectors can be cached.
        assert columnSchema.tupleSchema().isEmpty();
        vector = new MapVector(columnSchema.schema(), parent.loader().allocator(), null);
        vectorState = new MapVectorState(vector, new NullVectorState());
    } else {
        vector = null;
        vectorState = new NullVectorState();
    }
    final TupleObjectWriter mapWriter = MapWriter.buildMap(columnSchema, vector, new ArrayList<>());
    final SingleMapState mapState = new SingleMapState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()), projResult.mapFilter);
    return new MapColumnState(mapState, mapWriter, vectorState, parent.isVersioned());
}
Also used : SingleMapState(org.apache.drill.exec.physical.resultSet.impl.TupleState.SingleMapState) MapVectorState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState) ProjResult(org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult) MapColumnState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState) 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) TupleObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter.TupleObjectWriter) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Aggregations

ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)2 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)2 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)2 OffsetVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState)2 SimpleVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)2 MapColumnState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState)2 MapVectorState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState)2 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)2 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)2 MapArrayState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapArrayState)1 SingleMapState (org.apache.drill.exec.physical.resultSet.impl.TupleState.SingleMapState)1 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)1 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)1 AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)1 TupleObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter.TupleObjectWriter)1 MapVector (org.apache.drill.exec.vector.complex.MapVector)1