Class SchemaBuilder
java.lang.Object
org.apache.drill.exec.record.metadata.SchemaBuilder
Builder of a row set schema expressed as a list of materialized
fields. Optimized for use when creating schemas by hand in tests.
Example usage to create the following schema:
(c: INT, a: MAP(b: VARCHAR, d: INT, e: MAP(f: VARCHAR), g: INT),
h: UNION(INT, MAP(h1: INT), LIST(BIGINT)),
i: BIGINT[], j: VARCHAR[][][])
Code:
TupleMetadata schema = new SchemaBuilder()
.add("c", MinorType.INT)
.addMap("a")
.addNullable("b", MinorType.VARCHAR)
.add("d", MinorType.INT)
.addMap("e") // or .addMapArray("e")
.add("f", MinorType.VARCHAR)
.resumeMap()
.add("g", MinorType.INT)
.resumeSchema()
.addUnion("h") // or .addList("h")
.addType(MinorType.INT)
.addMap()
.add("h1", MinorType.INT)
.resumeUnion()
.addList()
.addType(MinorType.BIGINT)
.resumeUnion()
.resumeSchema()
.addArray("i", MinorType.BIGINT)
.addRepeatedList("j")
.addDimension()
.addArray(MinorType.VARCHAR)
.resumeList()
.resumeSchema()
.buildSchema();
</code
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(String name, TypeProtos.MajorType type) add
(String name, TypeProtos.MinorType type) add
(String name, TypeProtos.MinorType type, int width) add
(String name, TypeProtos.MinorType type, int precision, int scale) add
(String name, TypeProtos.MinorType type, TypeProtos.DataMode mode) add
(MaterializedField col) add
(ColumnMetadata column) addAll
(TupleMetadata from) addArray
(String name, TypeProtos.MinorType type) addArray
(String name, TypeProtos.MinorType type, int dims) Add a multi-dimensional array, implemented as a repeated vector along with 0 or more repeated list vectors.addArray
(String name, TypeProtos.MinorType type, int precision, int scale) void
addColumn
(ColumnMetadata column) addDecimal
(String name, TypeProtos.MinorType type, TypeProtos.DataMode mode, int precision, int scale) addDict
(String name, TypeProtos.MajorType keyType) addDict
(String name, TypeProtos.MinorType keyType) addDictArray
(String name, TypeProtos.MajorType keyType) addDictArray
(String name, TypeProtos.MinorType keyType) addDynamic
(String name) Add a map column.addMapArray
(String name) addNullable
(String name, TypeProtos.MinorType type) addNullable
(String name, TypeProtos.MinorType type, int width) addNullable
(String name, TypeProtos.MinorType type, int precision, int scale) addRepeatedList
(String name) build()
static MaterializedField
columnSchema
(String name, TypeProtos.MinorType type, TypeProtos.DataMode mode) Create a column schema using the "basic three" properties of name, type and cardinality (AKA "data mode.") Use theColumnBuilder
for to set other schema attributes.
-
Constructor Details
-
SchemaBuilder
public SchemaBuilder()
-
-
Method Details
-
columnSchema
public static MaterializedField columnSchema(String name, TypeProtos.MinorType type, TypeProtos.DataMode mode) Create a column schema using the "basic three" properties of name, type and cardinality (AKA "data mode.") Use theColumnBuilder
for to set other schema attributes. Name is relative to the enclosing map or tuple; it is not the fully qualified path name. -
addColumn
-
add
-
add
-
add
-
add
-
add
-
add
-
add
-
addNullable
-
addNullable
-
addNullable
-
addArray
-
addArray
-
addDecimal
public SchemaBuilder addDecimal(String name, TypeProtos.MinorType type, TypeProtos.DataMode mode, int precision, int scale) -
addArray
Add a multi-dimensional array, implemented as a repeated vector along with 0 or more repeated list vectors.- Parameters:
name
- column nametype
- base data typedims
- number of dimensions, 1 or more- Returns:
- this builder
-
addDynamic
-
addAll
-
addMap
Add a map column. The returned schema builder is for the nested map. Building that map, usingMapBuilder.resumeSchema()
, will return the original schema builder.- Parameters:
name
- the name of the map column- Returns:
- a builder for the map
-
addMapArray
-
addDict
-
addDict
-
addDictArray
-
addDictArray
-
addUnion
-
addList
-
addRepeatedList
-
buildSchema
-
build
-