Interface VariantWriter

All Superinterfaces:
All Known Implementing Classes:

public interface VariantWriter extends ColumnWriter
Writer for a Drill "union vector." The union vector is presented as a writer over a set of variants. In the old Visual Basic world, "the Variant data type is a tagged union that can be used to represent any other data type." The term is used here to avoid confusion with the "union operator" which is something entirely different.

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.
  • 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.
      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.
      number of types in the variant
    • hasType

      boolean hasType(TypeProtos.MinorType type)
      Determine if the union vector has materialized storage for the given type. (The storage will be created as needed during writing.)
      type - data type
      true if a value of the given type has been written and storage allocated (or storage was allocated implicitly), false otherwise
    • addMember

    • addMember

      ObjectWriter addMember(ColumnMetadata schema)
    • memberWriter

      ObjectWriter memberWriter(TypeProtos.MinorType type)
      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; call setType(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.
      type - the type of the writer to cache
      the writer for that type without setting the type of the current row.
    • setType

      void setType(TypeProtos.MinorType type)
      Explicitly set the type of the present value. Use this when the writers are cached. The writer must already exist.
      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.
      type - type to set for the current row
      writer for the type just set
    • scalar

    • tuple

      TupleWriter tuple()
    • array

      ArrayWriter array()