Class UnionReaderImpl
java.lang.Object
org.apache.drill.exec.vector.accessor.reader.UnionReaderImpl
- All Implemented Interfaces:
ColumnReader
,ReaderEvents
,VariantReader
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.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionUnionReaderImpl
(ColumnMetadata schema, VectorAccessor va, AbstractObjectReader[] variants) -
Method Summary
Modifier and TypeMethodDescriptionarray()
void
void
bindIndex
(ColumnReaderIndex index) void
bindNullState
(NullStateReader nullStateReader) static AbstractObjectReader
build
(ColumnMetadata schema, VectorAccessor va, AbstractObjectReader[] variants) dataType()
Return the data type of the current value.Return the entire object as a string.Return the value of the underlying data as a Java object.boolean
hasType
(TypeProtos.MinorType type) Determine if a given type is supported by the union vector for some value in the result set.boolean
isNull()
Determine if this value is null.member()
Return the reader for the member type of the current row.member
(TypeProtos.MinorType type) Return the member reader for the given type.void
scalar()
Return the appropriate scalar reader for the current value.scalar
(TypeProtos.MinorType type) Return the scalar reader for the given type member.schema()
int
size()
tuple()
type()
The type of this reader.
-
Field Details
-
nullStateReader
-
-
Constructor Details
-
UnionReaderImpl
-
-
Method Details
-
build
public static AbstractObjectReader build(ColumnMetadata schema, VectorAccessor va, AbstractObjectReader[] variants) -
bindNullState
- Specified by:
bindNullState
in interfaceReaderEvents
-
nullStateReader
- Specified by:
nullStateReader
in interfaceReaderEvents
-
bindIndex
- Specified by:
bindIndex
in interfaceReaderEvents
-
type
Description copied from interface:ColumnReader
The type of this reader.- Specified by:
type
in interfaceColumnReader
- Returns:
- type of reader
-
schema
- Specified by:
schema
in interfaceColumnReader
-
variantSchema
- Specified by:
variantSchema
in interfaceVariantReader
-
size
public int size()- Specified by:
size
in interfaceVariantReader
-
hasType
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 interfaceVariantReader
- 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 interfaceReaderEvents
-
bindBuffer
public void bindBuffer()- Specified by:
bindBuffer
in interfaceReaderEvents
-
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 interfaceColumnReader
- Returns:
- true if this value is null; false otherwise
-
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 interfaceVariantReader
- Returns:
- data type of the current data value
-
member
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 interfaceVariantReader
- Parameters:
type
- member type- Returns:
- reader for that type
-
scalar
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 interfaceVariantReader
- Parameters:
type
- member type- Returns:
- scalar reader for that type
-
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 interfaceVariantReader
- Returns:
- reader for the member type of the current row.
-
scalar
Description copied from interface:VariantReader
Return the appropriate scalar reader for the current value.- Specified by:
scalar
in interfaceVariantReader
- Returns:
- null if
ColumnReader.isNull()
returns true, else the equivalent ofscalar
(VariantReader.dataType()
)
-
tuple
- Specified by:
tuple
in interfaceVariantReader
-
array
- Specified by:
array
in interfaceVariantReader
-
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 interfaceColumnReader
- Returns:
- the value as a Java object
-
getAsString
Description copied from interface:ColumnReader
Return the entire object as a string. Primarily for debugging.- Specified by:
getAsString
in interfaceColumnReader
- Returns:
- string representation of the object
-