Class UnionReaderImpl

java.lang.Object
org.apache.drill.exec.vector.accessor.reader.UnionReaderImpl
All Implemented Interfaces:
ColumnReader, ReaderEvents, VariantReader

public class UnionReaderImpl extends Object implements VariantReader, ReaderEvents
Reader for a union vector. The union vector presents itself as a variant. This is an important, if subtle distinction. The current union vector format is highly inefficient (and buggy and not well supported in Drill's operators.) If the union concept is needed, then it should be redesigned, perhaps as a variable-width vector in which each entry consists of a type/value pair. (For variable-width values such as strings, the implementation would be a triple of (type, length, value). The API here is designed to abstract away the implementation and should work equally well for the current "union" implementation and the possible "variant" implementation. As a result, when changing the API, avoid introducing methods that assume an implementation.
  • Field Details

  • Constructor Details

  • Method Details

    • build

      public static AbstractObjectReader build(ColumnMetadata schema, VectorAccessor va, AbstractObjectReader[] variants)
    • bindNullState

      public void bindNullState(NullStateReader nullStateReader)
      Specified by:
      bindNullState in interface ReaderEvents
    • nullStateReader

      public NullStateReader nullStateReader()
      Specified by:
      nullStateReader in interface ReaderEvents
    • bindIndex

      public void bindIndex(ColumnReaderIndex index)
      Specified by:
      bindIndex in interface ReaderEvents
    • type

      public ObjectType type()
      Description copied from interface: ColumnReader
      The type of this reader.
      Specified by:
      type in interface ColumnReader
      Returns:
      type of reader
    • schema

      public ColumnMetadata schema()
      Specified by:
      schema in interface ColumnReader
    • variantSchema

      public VariantMetadata variantSchema()
      Specified by:
      variantSchema in interface VariantReader
    • size

      public int size()
      Specified by:
      size in interface VariantReader
    • hasType

      public boolean hasType(TypeProtos.MinorType type)
      Description copied from interface: VariantReader
      Determine if a given type is supported by the union vector for some value in the result set.
      Specified by:
      hasType in interface VariantReader
      Parameters:
      type - the Drill minor type to query
      Returns:
      true if a reader for the given type is available, false if a request for a reader of that type will return null.
    • reposition

      public void reposition()
      Specified by:
      reposition in interface ReaderEvents
    • bindBuffer

      public void bindBuffer()
      Specified by:
      bindBuffer in interface ReaderEvents
    • isNull

      public boolean isNull()
      Description copied from interface: ColumnReader
      Determine if this value is null.
      • Nullable scalar: determine if the value is null.
      • Non-nullable scalar: always returns false.
      • Arrays: always returns false</tt.>
      • Lists: determine if the list for the current row is null. In a list, an array entry can be null, empty, or can contain items. In repeated types, the array itself is never null. If the array is null, then it implicitly has no entries.
      • Map or Repeated Map: Always returns false.
      • Map inside a union, or in a list that contains a union, the tuple itself can be null.
      • Union: Determine if the current value is null. Null values have no type and no associated reader.
      Specified by:
      isNull in interface ColumnReader
      Returns:
      true if this value is null; false otherwise
    • dataType

      public TypeProtos.MinorType dataType()
      Description copied from interface: VariantReader
      Return the data type of the current value. (What happens if the row is null, must it be a null of some type?)
      Specified by:
      dataType in interface VariantReader
      Returns:
      data type of the current data value
    • member

      public ObjectReader member(TypeProtos.MinorType type)
      Description copied from interface: VariantReader
      Return the member reader for the given type. The type must be a member of the union. Allows caching readers across rows.
      Specified by:
      member in interface VariantReader
      Parameters:
      type - member type
      Returns:
      reader for that type
    • scalar

      public ScalarReader scalar(TypeProtos.MinorType type)
      Description copied from interface: VariantReader
      Return the scalar reader for the given type member. The type must be a member of the union. Allows caching readers across rows. Identical to:
      >member(type).scalar()
      Specified by:
      scalar in interface VariantReader
      Parameters:
      type - member type
      Returns:
      scalar reader for that type
    • member

      public ObjectReader member()
      Description copied from interface: VariantReader
      Return the reader for the member type of the current row. Same as:
      member(dataType())
      Specified by:
      member in interface VariantReader
      Returns:
      reader for the member type of the current row.
    • scalar

      public ScalarReader scalar()
      Description copied from interface: VariantReader
      Return the appropriate scalar reader for the current value.
      Specified by:
      scalar in interface VariantReader
      Returns:
      null if ColumnReader.isNull() returns true, else the equivalent of scalar( VariantReader.dataType() )
    • tuple

      public TupleReader tuple()
      Specified by:
      tuple in interface VariantReader
    • array

      public ArrayReader array()
      Specified by:
      array in interface VariantReader
    • getObject

      public Object getObject()
      Description copied from interface: ColumnReader
      Return the value of the underlying data as a Java object. Primarily for testing
      • Array: Return the entire array as an List of objects. Note, even if the array is scalar, the elements are still returned as a list.
      Specified by:
      getObject in interface ColumnReader
      Returns:
      the value as a Java object
    • getAsString

      public String getAsString()
      Description copied from interface: ColumnReader
      Return the entire object as a string. Primarily for debugging.
      Specified by:
      getAsString in interface ColumnReader
      Returns:
      string representation of the object