Search in sources :

Example 1 with VariantObjectWriter

use of org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl.VariantObjectWriter 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 2 with VariantObjectWriter

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

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

the class ColumnBuilder method buildUnion.

/**
 * Builds a union column.
 * <p>
 * The union vector type is not well supported in Drill. The idea is that
 * arbitrary operators can absorb schema changes by converting vectors to
 * unions so that an operator can handle, say, a nullable int and a varchar.
 * In practice, most operators don't support this feature. (Sort does -- but
 * does not manage memory for the union case.) In principal, union can't solve
 * the problem because ODBC and JDBC don't support unions, and it is easy
 * to envision changes that unions won't solve (int and varchar types combining
 * in a join column, say.) Still, Drill supports unions, so the code here
 * does so. Unions are fully tested in the row set writer mechanism.
 *
 * @param parent container of vectors
 * @param columnSchema implied projection type for the column
 * @return column
 */
private ColumnState buildUnion(ContainerState parent, ColumnMetadata columnSchema) {
    assert columnSchema.isVariant() && !columnSchema.isArray();
    // vectors can be cached.
    assert columnSchema.variantSchema().size() == 0;
    final UnionVector vector = new UnionVector(columnSchema.schema(), parent.loader().allocator(), null);
    // Then the union writer.
    final UnionWriterImpl unionWriter = new UnionWriterImpl(columnSchema, vector, null);
    final VariantObjectWriter writer = new VariantObjectWriter(unionWriter);
    // The union vector state which manages the types vector.
    final UnionVectorState vectorState = new UnionVectorState(vector, unionWriter);
    // Create the manager for the columns within the union.
    final UnionState unionState = new UnionState(parent.loader(), parent.vectorCache().childCache(columnSchema.name()));
    // Bind the union state to the union writer to handle column additions.
    unionWriter.bindListener(unionState);
    // Assemble it all into a union column state.
    return new UnionColumnState(parent.loader(), writer, vectorState, unionState);
}
Also used : VariantObjectWriter(org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl.VariantObjectWriter) UnionVector(org.apache.drill.exec.vector.complex.UnionVector) UnionVectorState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState) UnionWriterImpl(org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl) UnionColumnState(org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionColumnState)

Aggregations

UnionWriterImpl (org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl)3 VariantObjectWriter (org.apache.drill.exec.vector.accessor.writer.UnionWriterImpl.VariantObjectWriter)3 UnionColumnState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionColumnState)2 AbstractObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractObjectWriter)2 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 ListVectorState (org.apache.drill.exec.physical.resultSet.impl.ListState.ListVectorState)1 RepeatedListVectorState (org.apache.drill.exec.physical.resultSet.impl.RepeatedListState.RepeatedListVectorState)1 UnionVectorState (org.apache.drill.exec.physical.resultSet.impl.UnionState.UnionVectorState)1 MetadataProvider (org.apache.drill.exec.physical.resultSet.model.MetadataProvider)1 VectorDescrip (org.apache.drill.exec.physical.resultSet.model.MetadataProvider.VectorDescrip)1 ValueVector (org.apache.drill.exec.vector.ValueVector)1 ArrayObjectWriter (org.apache.drill.exec.vector.accessor.writer.AbstractArrayWriter.ArrayObjectWriter)1 EmptyListShim (org.apache.drill.exec.vector.accessor.writer.EmptyListShim)1 ListWriterImpl (org.apache.drill.exec.vector.accessor.writer.ListWriterImpl)1 ListVector (org.apache.drill.exec.vector.complex.ListVector)1 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)1 UnionVector (org.apache.drill.exec.vector.complex.UnionVector)1