Search in sources :

Example 1 with ListWriterImpl

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

the class BaseWriterBuilder method build1DList.

private AbstractObjectWriter build1DList(ListVector vector, VectorDescrip descrip) {
    final ValueVector dataVector = vector.getDataVector();
    VectorDescrip dataMetadata;
    if (dataVector.getField().getType().getMinorType() == MinorType.UNION) {
        // If the list holds a union, then the list and union are collapsed
        // together in the metadata layer.
        dataMetadata = descrip;
    } else {
        dataMetadata = new VectorDescrip(descrip.childProvider(), 0, dataVector.getField());
    }
    return new ArrayObjectWriter(new ListWriterImpl(descrip.metadata, vector, buildVectorWriter(dataVector, dataMetadata)));
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) ListWriterImpl(org.apache.drill.exec.vector.accessor.writer.ListWriterImpl) ArrayObjectWriter(org.apache.drill.exec.vector.accessor.writer.AbstractArrayWriter.ArrayObjectWriter) VectorDescrip(org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip)

Example 2 with ListWriterImpl

use of org.apache.drill.exec.vector.accessor.writer.ListWriterImpl 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 3 with ListWriterImpl

use of org.apache.drill.exec.vector.accessor.writer.ListWriterImpl 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)

Aggregations

ArrayObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractArrayWriter.ArrayObjectWriter)3 ListWriterImpl (org.apache.drill.exec.vector.accessor.writer.ListWriterImpl)3 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)2 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)2 UnionColumnState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionColumnState)2 AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)2 ListVector (org.apache.drill.exec.vector.complex.ListVector)2 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)2 PrimitiveColumnState (org.apache.drill.exec.physical.resultSet.impl.ColumnState.PrimitiveColumnState)1 RepeatedListColumnState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListColumnState)1 MapColumnState (org.apache.drill.exec.physical.resultSet.impl.TupleState.MapColumnState)1 VectorDescrip (org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip)1 ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)1 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 EmptyListShim (org.apache.drill.exec.vector.accessor.writer.EmptyListShim)1 UnionWriterImpl (org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl)1 VariantObjectWriter (org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl.VariantObjectWriter)1