Search in sources :

Example 1 with AbstractMapVector

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

the class VectorContainerBuilder method buildMap.

@SuppressWarnings("resource")
private void buildMap(TupleProxy parentTuple, BaseMapColumnState colModel) {
    // 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.
    ColumnMetadata mapColSchema = colModel.schema().cloneEmpty();
    // Don't get the map vector from the vector cache. Map vectors may
    // have content that varies from batch to batch. Only the leaf
    // vectors can be cached.
    AbstractMapVector mapVector;
    if (mapColSchema.isArray()) {
        // A repeated map shares an offset vector with the internal
        // repeated map.
        UInt4Vector offsets = (UInt4Vector) colModel.vector();
        mapVector = new RepeatedMapVector(mapColSchema.schema(), offsets, null);
    } else {
        mapVector = new MapVector(mapColSchema.schema(), allocator(), null);
    }
    // Add the map vector and schema to the parent tuple
    parentTuple.add(mapVector);
    int index = parentTuple.schema.addColumn(mapColSchema);
    assert parentTuple.size() == parentTuple.size();
    // Update the tuple, which will add the new columns in the map
    updateTuple(colModel.mapState(), parentTuple.mapProxy(index));
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) UInt4Vector(org.apache.drill.exec.vector.UInt4Vector) RepeatedMapVector(org.apache.drill.exec.vector.complex.RepeatedMapVector) MapVector(org.apache.drill.exec.vector.complex.MapVector) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector)

Example 2 with AbstractMapVector

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

the class HyperVectorWrapper method getChildWrapper.

@Override
public VectorWrapper<?> getChildWrapper(int[] ids) {
    if (ids.length == 1) {
        return this;
    }
    final ValueVector[] vectors = new ValueVector[this.vectors.length];
    int index = 0;
    for (final ValueVector v : this.vectors) {
        ValueVector vector = v;
        for (int i = 1; i < ids.length; i++) {
            final AbstractMapVector mapLike = AbstractMapVector.class.cast(vector);
            if (mapLike == null) {
                return null;
            }
            vector = mapLike.getChildByOrdinal(ids[i]);
        }
        vectors[index] = vector;
        index++;
    }
    return new HyperVectorWrapper<ValueVector>(vectors[0].getField(), vectors);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector)

Example 3 with AbstractMapVector

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

the class SimpleVectorWrapper method getChildWrapper.

@Override
public VectorWrapper<?> getChildWrapper(int[] ids) {
    if (ids.length == 1) {
        return this;
    }
    ValueVector vector = this.vector;
    for (int i = 1; i < ids.length; i++) {
        final AbstractMapVector mapLike = AbstractMapVector.class.cast(vector);
        if (mapLike == null) {
            return null;
        }
        vector = mapLike.getChildByOrdinal(ids[i]);
    }
    return new SimpleVectorWrapper<>(vector);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector)

Example 4 with AbstractMapVector

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

the class BuildVectorsFromMetadata method buildMap.

/**
 * Build a map column including the members of the map given a map
 * column schema.
 *
 * @param schema the schema of the map column
 * @return the completed map vector column model
 */
private AbstractMapVector buildMap(ColumnMetadata schema) {
    // 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.
    MaterializedField mapField = schema.schema();
    MaterializedField emptyClone = MaterializedField.create(mapField.getName(), mapField.getType());
    // Don't get the map vector from the vector cache. Map vectors may
    // have content that varies from batch to batch. Only the leaf
    // vectors can be cached.
    AbstractMapVector mapVector = (AbstractMapVector) TypeHelper.getNewVector(emptyClone, allocator, null);
    // Create the contents building the model as we go.
    TupleMetadata mapSchema = schema.mapSchema();
    for (int i = 0; i < mapSchema.size(); i++) {
        ColumnMetadata childSchema = mapSchema.metadata(i);
        mapVector.putChild(childSchema.name(), buildVector(childSchema));
    }
    return mapVector;
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 5 with AbstractMapVector

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

the class SimpleVectorWrapper method getChildWrapper.

@SuppressWarnings("resource")
@Override
public VectorWrapper<?> getChildWrapper(int[] ids) {
    if (ids.length == 1) {
        return this;
    }
    ValueVector vector = this.vector;
    for (int i = 1; i < ids.length; i++) {
        final AbstractMapVector mapLike = AbstractMapVector.class.cast(vector);
        if (mapLike == null) {
            return null;
        }
        vector = mapLike.getChildByOrdinal(ids[i]);
    }
    return new SimpleVectorWrapper<>(vector);
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) AbstractMapVector(org.apache.drill.exec.vector.complex.AbstractMapVector)

Aggregations

AbstractMapVector (org.apache.drill.exec.vector.complex.AbstractMapVector)7 ValueVector (org.apache.drill.exec.vector.ValueVector)4 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)2 MaterializedField (org.apache.drill.exec.record.MaterializedField)1 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)1 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)1 MapVector (org.apache.drill.exec.vector.complex.MapVector)1 RepeatedMapVector (org.apache.drill.exec.vector.complex.RepeatedMapVector)1