Interface VariantWriter
- All Superinterfaces:
ColumnWriter
- All Known Implementing Classes:
UnionWriterImpl
At write time, the set of possible types is expanded upon the
first write to each type. A request to obtain a writer for type
will create the underlying storage vector if needed, then return
a write of the proper type. Note that unlike most other writers,
the caller is required to call the
scalar(MinorType)
method for each value so that this
writer knows which type of value is to be stored.
Alternatively, the client can cache a writer by calling
memberWriter(MinorType)
to retrieve a writer (without setting
the type for a row), then calling the set method on that writer for each
row, and calling setType(MinorType)
for each row.
This writer acts as somewhat like a map: it allows access to type-specific writers.
Although the union and list vectors supports a union of any Drill type, the only sane combinations are:
- One of a (single or repeated) (map or list), or
- One or more scalar type.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddMember
(ColumnMetadata schema) array()
boolean
hasType
(TypeProtos.MinorType type) Determine if the union vector has materialized storage for the given type.member
(TypeProtos.MinorType type) Set the type of the present value and get the writer for that type.Create or retrieve a writer for the given type.scalar
(TypeProtos.MinorType type) void
setType
(TypeProtos.MinorType type) Explicitly set the type of the present value.int
size()
Returns the number of types in the variant.tuple()
Metadata description of the variant that includes the set of types, along with extended properties of the types such as expected allocations sizes, expected array cardinality, etc.Methods inherited from interface org.apache.drill.exec.vector.accessor.ColumnWriter
copy, isProjected, nullable, schema, setNull, setObject, type
-
Method Details
-
variantSchema
VariantMetadata variantSchema()Metadata description of the variant that includes the set of types, along with extended properties of the types such as expected allocations sizes, expected array cardinality, etc.- Returns:
- metadata for the variant
-
size
int size()Returns the number of types in the variant. Some implementations (such as lists) impart special meaning to a variant with a single type.- Returns:
- number of types in the variant
-
hasType
Determine if the union vector has materialized storage for the given type. (The storage will be created as needed during writing.)- Parameters:
type
- data type- Returns:
true
if a value of the given type has been written and storage allocated (or storage was allocated implicitly),false
otherwise
-
addMember
-
addMember
-
memberWriter
Create or retrieve a writer for the given type. Use this form when caching writers. This form does not set the type of the current row; callsetType(MinorType)
per row when the writers are cached. This method can be called at any time as it does not depend on an active batch.- Parameters:
type
- the type of the writer to cache- Returns:
- the writer for that type without setting the type of the current row.
-
setType
Explicitly set the type of the present value. Use this when the writers are cached. The writer must already exist.- Parameters:
type
- type to set for the current row
-
member
Set the type of the present value and get the writer for that type. Available only when a batch is active. Use this form to declare the type of the current row, and retrieve a writer for that value.- Parameters:
type
- type to set for the current row- Returns:
- writer for the type just set
-
scalar
-
tuple
TupleWriter tuple() -
array
ArrayWriter array()
-