Search in sources :

Example 21 with RepeatedMapVector

use of org.apache.drill.exec.vector.complex.RepeatedMapVector 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 22 with RepeatedMapVector

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

the class UnnestRecordBatch method setUnnestVector.

private void setUnnestVector() {
    MaterializedField field = incoming.getSchema().getColumn(unnestTypedFieldId.getFieldIds()[0]);
    RepeatedValueVector vector;
    ValueVector inVV = incoming.getValueAccessorById(field.getValueClass(), unnestTypedFieldId.getFieldIds()).getValueVector();
    if (!(inVV instanceof RepeatedValueVector)) {
        if (incoming.getRecordCount() != 0) {
            throw UserException.unsupportedError().message("Unnest does not support inputs of non-list values.").build(logger);
        }
        // Inherited from FLATTEN. When does this happen???
        // when incoming recordCount is 0, don't throw exception since the type being seen here is not solid
        logger.error("setUnnestVector cast failed and recordcount is 0, create empty vector anyway.");
        vector = new RepeatedMapVector(field, oContext.getAllocator(), null);
    } else {
        vector = RepeatedValueVector.class.cast(inVV);
    }
    unnest.setUnnestField(vector);
}
Also used : RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) ValueVector(org.apache.drill.exec.vector.ValueVector) RepeatedValueVector(org.apache.drill.exec.vector.complex.RepeatedValueVector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Aggregations

RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)22 ValueVector (org.apache.drill.exec.vector.ValueVector)11 Test (org.junit.Test)10 MaterializedField (org.apache.drill.exec.record.MaterializedField)9 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)9 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)7 SubOperatorTest (org.apache.drill.test.SubOperatorTest)7 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)6 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)5 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)5 TransferPair (org.apache.drill.exec.record.TransferPair)4 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)4 TupleWriter (org.apache.drill.exec.vector.accessor.TupleWriter)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)3 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)3 MapVector (org.apache.drill.exec.vector.complex.MapVector)3 BaseTest (org.apache.drill.test.BaseTest)3 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)2 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)2 BaseValueVector (org.apache.drill.exec.vector.BaseValueVector)2