Class BuildFromSchema

java.lang.Object
org.apache.drill.exec.physical.resultSet.impl.BuildFromSchema

public class BuildFromSchema extends Object
Build the set of writers from a defined schema. Uses the same mechanism as dynamic schema: walks the schema tree adding each column, then recursively adds the contents of maps and variants.

Recursion is much easier if we can go bottom-up. But, writers require top-down construction.

This particular class builds a column and all its contents. For example, given a map, which contains a repeated list which contains a repeated INT, this class first builds the map, then adds the repeated list, then adds the INT array. To do so, it will create a copy of the structured metadata.

A drawback of this approach is that the metadata objects used in the "parent" writers will be copies of, not the same as, those in the schema from which we are building the writers. At present, this is not an issue, but it is something to be aware of as uses become more sophisticated.

This class contrasts with the @{link ColumnBuilder} class which builds the structure within a single vector and writer.

  • Method Details

    • instance

      public static BuildFromSchema instance()
    • buildTuple

      public void buildTuple(TupleWriter writer, TupleMetadata schema)
      When creating a schema up front, provide the schema of the desired tuple, then build vectors and writers to match. Allows up-front schema definition in addition to on-the-fly schema creation handled elsewhere.
      Parameters:
      schema - desired tuple schema to be materialized
    • buildColumn

      public ObjectWriter buildColumn(TupleState state, ColumnMetadata colSchema)
      Build a column recursively. Called internally when adding a column via the addColumn() method on the tuple writer.
      Parameters:
      state - the loader state for the tuple, a row or a map
      colSchema - the schema of the column to add
      Returns:
      the object writer for the added column
    • buildUnion

      public void buildUnion(VariantWriter writer, VariantMetadata schema)