Search in sources :

Example 6 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class BaseWriterBuilder method buildUnion.

private AbstractObjectWriter buildUnion(UnionVector vector, VectorDescrip descrip) {
    if (vector == null) {
        throw new UnsupportedOperationException("Dummy variant writer not yet supported");
    }
    final AbstractObjectWriter[] variants = new AbstractObjectWriter[MinorType.values().length];
    final MetadataProvider mdProvider = descrip.childProvider();
    int i = 0;
    for (final MinorType type : vector.getField().getType().getSubTypeList()) {
        // This call will create the vector if it does not yet exist.
        // Will throw an exception for unsupported types.
        // so call this only if the MajorType reports that the type
        // already exists.
        final ValueVector memberVector = vector.getMember(type);
        final VectorDescrip memberDescrip = new VectorDescrip(mdProvider, i++, memberVector.getField());
        variants[type.ordinal()] = buildVectorWriter(memberVector, memberDescrip);
    }
    return new VariantObjectWriter(new UnionWriterImpl(descrip.metadata, vector, variants));
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) VariantObjectWriter(org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl.VariantObjectWriter) MetadataProvider(org.apache.drill.exec.physical.resultSet.model.MetadataProvider) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) VectorDescrip(org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) UnionWriterImpl(org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl)

Example 7 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class ColumnBuilder method buildSimpleList.

/**
 * Create a list that is promised to only ever contain a single type (at least
 * during this write session). The list acts as a repeated vector in which each
 * element can be null. The writer is presented as an array of the single type.
 * <p>
 * List vectors (lists of optional values) are not supported in
 * Drill. The code here works up through the scan operator. But, other operators do
 * not support the {@code ListVector</tt> type.
 *
 * @param parent the parent (tuple, union or list) that holds this list
 * @param columnSchema metadata description of the list which must contain
 * exactly one subtype
 * @return the column state for the list
 */
private ColumnState buildSimpleList(ContainerState parent, ColumnMetadata columnSchema) {
    // The variant must have the one and only type.
    assert columnSchema.variantSchema().size() == 1;
    assert columnSchema.variantSchema().isSimple();
    // Create the manager for the one and only column within the list.
    final ListState listState = new ListState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()));
    // Create the child vector, writer and state.
    final ColumnMetadata memberSchema = columnSchema.variantSchema().listSubtype();
    final ColumnState memberState = buildColumn(listState, memberSchema);
    listState.setSubColumn(memberState);
    // Create the list vector. Contains a single type.
    final ListVector listVector = new ListVector(columnSchema.schema().cloneEmpty(), parent.loader().allocator(), null);
    listVector.setChildVector(memberState.vector());
    // Create the list writer: an array of the one type.
    final ListWriterImpl listWriter = new ListWriterImpl(columnSchema, listVector, memberState.writer());
    final AbstractObjectWriter listObjWriter = new ArrayObjectWriter(listWriter);
    // Create the list vector state that tracks the list vector lifecycle.
    final ListVectorState vectorState = new ListVectorState(listWriter, memberState.writer().events(), listVector);
    // Assemble it all into a union column state.
    return new UnionColumnState(parent.loader(), listObjWriter, vectorState, listState);
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) ListWriterImpl(org.apache.drill.exec.vector.accessor.writer.ListWriterImpl) MapColumnState(org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState) PrimitiveColumnState(org.apache.drill.exec.physical.resultSet.impl.ColumnState.PrimitiveColumnState) RepeatedListColumnState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListColumnState) UnionColumnState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionColumnState) ArrayObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractArrayWriter.ArrayObjectWriter) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) ListVector(org.apache.drill.exec.vector.complex.ListVector) RepeatedListVectorState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState) ListVectorState(org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) UnionColumnState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionColumnState)

Example 8 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class ColumnBuilder method buildUnionList.

/**
 * Create a list based on a (possible) union. The list starts empty here. The client
 * can then add types as they are discovered. The list itself will transition from a
 * list of nulls (no child type), to a list of a single type, to a list of unions.
 * The writer interface will consistently present the list as a list of unions, even
 * when the list itself has no subtype or a single subtype.
 * <p>
 * List vectors (lists of unions) are not supported in
 * Drill. The code here works up through the scan operator. But, other operators do
 * not support the {@code ListVector} type.
 *
 * @param parent the parent (tuple, union or list) that holds this list
 * @param columnSchema description of the list (must be empty of
 * subtypes)
 * @return the column state for the list
 */
private ColumnState buildUnionList(ContainerState parent, ColumnMetadata columnSchema) {
    // The variant must start out empty.
    assert columnSchema.variantSchema().size() == 0;
    // Create the union writer, bound to an empty list shim.
    final UnionWriterImpl unionWriter = new UnionWriterImpl(columnSchema);
    unionWriter.bindShim(new EmptyListShim());
    final VariantObjectWriter unionObjWriter = new VariantObjectWriter(unionWriter);
    // Create the list vector. Starts with the default (dummy) data
    // vector which corresponds to the empty union shim above.
    // Don't get the list vector from the vector cache. List vectors may
    // have content that varies from batch to batch. Only the leaf
    // vectors can be cached.
    final ListVector listVector = new ListVector(columnSchema.schema(), parent.loader().allocator(), null);
    // Create the list vector state that tracks the list vector lifecycle.
    final ListVectorState vectorState = new ListVectorState(unionWriter, listVector);
    // Create the list writer: an array of unions.
    final AbstractObjectWriter listWriter = new ArrayObjectWriter(new ListWriterImpl(columnSchema, listVector, unionObjWriter));
    // Create the manager for the columns within the list (which may or
    // may not be grouped into a union.)
    final ListState listState = new ListState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()));
    // Bind the union state to the union writer to handle column additions.
    unionWriter.bindListener(listState);
    // Assemble it all into a union column state.
    return new UnionColumnState(parent.loader(), listWriter, vectorState, listState);
}
Also used : VariantObjectWriter(org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl.VariantObjectWriter) ListWriterImpl(org.apache.drill.exec.vector.accessor.writer.ListWriterImpl) EmptyListShim(org.apache.drill.exec.vector.accessor.writer.EmptyListShim) ArrayObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractArrayWriter.ArrayObjectWriter) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) ListVector(org.apache.drill.exec.vector.complex.ListVector) RepeatedListVectorState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState) ListVectorState(org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState) UnionWriterImpl(org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter) UnionColumnState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionColumnState)

Example 9 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class ColumnBuilder method buildSingleDict.

private ColumnState buildSingleDict(ContainerState parent, ColumnMetadata columnSchema) {
    final ProjectionFilter projFilter = parent.projection();
    final ProjResult projResult = projFilter.projection(columnSchema);
    // Create the dict's offset vector.
    final DictVector dictVector;
    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();
        // vectors can be cached.
        assert columnSchema.tupleSchema().isEmpty();
        dictVector = new DictVector(dictColMetadata.schema(), parent.loader().allocator(), null);
        offsetVector = dictVector.getOffsetVector();
    } else {
        dictVector = null;
        offsetVector = null;
    }
    // Create the writer using the offset vector
    final AbstractObjectWriter writer = ObjectDictWriter.buildDict(columnSchema, dictVector, new ArrayList<>());
    // Wrap the offset vector in a vector state
    final VectorState offsetVectorState;
    if (!projResult.isProjected) {
        offsetVectorState = new NullVectorState();
    } else {
        offsetVectorState = new OffsetVectorState((((AbstractArrayWriter) writer.dict()).offsetWriter()), offsetVector, writer.dict().entry().events());
    }
    final VectorState mapVectorState = new TupleState.SingleDictVectorState(dictVector, offsetVectorState);
    // Assemble it all into the column state.
    final SingleDictState dictArrayState = new SingleDictState(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) SingleDictState(org.apache.drill.exec.physical.resultSet.impl.TupleState.SingleDictState) 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)

Example 10 with AbstractObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter in project drill by apache.

the class ColumnBuilder method buildRepeatedList.

private ColumnState buildRepeatedList(ContainerState parent, ColumnMetadata columnSchema) {
    assert columnSchema.type() == MinorType.LIST;
    assert columnSchema.mode() == DataMode.REPEATED;
    // the element type after creating the repeated writer itself.
    assert columnSchema.childSchema() == null;
    // Build the repeated vector.
    final RepeatedListVector vector = new RepeatedListVector(columnSchema.emptySchema(), parent.loader().allocator(), null);
    // No inner type yet. The result set loader builds the subtype
    // incrementally because it might be complex (a map or another
    // repeated list.) To start, use a dummy to avoid need for if-statements
    // everywhere.
    final ColumnMetadata dummyElementSchema = new PrimitiveColumnMetadata(MaterializedField.create(columnSchema.name(), Types.repeated(MinorType.NULL)));
    final AbstractObjectWriter dummyElement = ColumnWriterFactory.buildDummyColumnWriter(dummyElementSchema);
    // Create the list writer: an array of arrays.
    final AbstractObjectWriter arrayWriter = RepeatedListWriter.buildRepeatedList(columnSchema, vector, dummyElement);
    // Create the list vector state that tracks the list vector lifecycle.
    final RepeatedListVectorState vectorState = new RepeatedListVectorState(arrayWriter, vector);
    // Build the container that tracks the array contents
    final RepeatedListState listState = new RepeatedListState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()));
    // Bind the list state as the list event listener.
    ((RepeatedListWriter) arrayWriter.array()).bindListener(listState);
    // propagate events down to the (one and only) child state.
    return new RepeatedListColumnState(parent.loader(), arrayWriter, vectorState, listState);
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) PrimitiveColumnMetadata(org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata) RepeatedListVector(org.apache.drill.exec.vector.complex.RepeatedListVector) RepeatedListWriter(org.apache.drill.exec.vector.accessor.writer.RepeatedListWriter) RepeatedListColumnState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListColumnState) RepeatedListVectorState(org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState) AbstractObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)

Aggregations

AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)21 ArrayList (java.util.ArrayList)9 ValueVector (org.apache.drill.exec.vector.ValueVector)9 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)7 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)7 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)6 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)5 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 AbstractTupleWriter (org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter)5 SubOperatorTest (org.apache.drill.test.SubOperatorTest)5 Test (org.junit.Test)5 OffsetVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.OffsetVectorState)4 SimpleVectorState (org.apache.drill.exec.physical.resultSet.impl.SingleVectorState.SimpleVectorState)4 MapVectorState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapVectorState)4 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)4 VectorDescrip (org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip)4 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)3 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)3 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)3 RepeatedDictVector (org.apache.drill.exec.vector.complex.RepeatedDictVector)3