Class FileSchema.Builder
java.lang.Object
dev.hardwood.schema.FileSchema.Builder
- Enclosing class:
FileSchema
Builder for constructing a FileSchema programmatically.
Fields are added as top-level primitive leaves (addColumn(String, PhysicalType, RepetitionType)), nested struct
groups (struct(String, RepetitionType, Consumer)), LIST groups (list(String, RepetitionType, Consumer)), or MAP groups (map(String, RepetitionType, PhysicalType, Consumer)). The LIST
and MAP groups emit the canonical 3-level and 2-level physical layouts.
-
Method Summary
Modifier and TypeMethodDescriptionaddColumn(String columnName, PhysicalType type, RepetitionType repetition) Append a primitive column.addColumn(String columnName, PhysicalType type, RepetitionType repetition, int typeLength) Append a primitive column, giving the fixed byte length of aFIXED_LEN_BYTE_ARRAYcolumn.addColumn(String columnName, PhysicalType type, RepetitionType repetition, int typeLength, LogicalType logicalType) Append a primitive column carrying a logical type annotation, giving the fixed byte length of aFIXED_LEN_BYTE_ARRAYcolumn.addColumn(String columnName, PhysicalType type, RepetitionType repetition, LogicalType logicalType) Append a primitive column carrying a logical type annotation.build()Build the schema.list(String listName, RepetitionType repetition, Consumer<FileSchema.ElementBuilder> element) Append aLISTgroup whose element is declared byelement.map(String mapName, RepetitionType repetition, PhysicalType keyType, int keyTypeLength, LogicalType keyLogicalType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose key carries a logical type annotation, giving the fixed byte length of aFIXED_LEN_BYTE_ARRAYkey.map(String mapName, RepetitionType repetition, PhysicalType keyType, LogicalType keyLogicalType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose key carries a logical type annotation — aSTRINGkey being the common case.map(String mapName, RepetitionType repetition, PhysicalType keyType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose value is declared byvalue.struct(String structName, RepetitionType repetition, Consumer<FileSchema.StructBuilder> filler) Append astructgroup whose fields are declared byfiller.
-
Method Details
-
addColumn
public FileSchema.Builder addColumn(String columnName, PhysicalType type, RepetitionType repetition) Append a primitive column.- Parameters:
columnName- the column nametype- the physical typerepetition-REQUIREDorOPTIONAL- Throws:
IllegalArgumentException- ifrepetitionisREPEATED
-
addColumn
public FileSchema.Builder addColumn(String columnName, PhysicalType type, RepetitionType repetition, int typeLength) Append a primitive column, giving the fixed byte length of aFIXED_LEN_BYTE_ARRAYcolumn.- Parameters:
columnName- the column nametype- the physical typerepetition-REQUIREDorOPTIONALtypeLength- the fixed byte length (required and positive forFIXED_LEN_BYTE_ARRAY, rejected for any other type)- Throws:
IllegalArgumentException- ifrepetitionisREPEATEDortypeLengthdoes not match the type
-
addColumn
public FileSchema.Builder addColumn(String columnName, PhysicalType type, RepetitionType repetition, LogicalType logicalType) Append a primitive column carrying a logical type annotation.- Parameters:
columnName- the column nametype- the physical typerepetition-REQUIREDorOPTIONALlogicalType- the annotation, which must be legal fortype- Throws:
IllegalArgumentException- ifrepetitionisREPEATEDor the annotation does not apply to the physical type
-
addColumn
public FileSchema.Builder addColumn(String columnName, PhysicalType type, RepetitionType repetition, int typeLength, LogicalType logicalType) Append a primitive column carrying a logical type annotation, giving the fixed byte length of aFIXED_LEN_BYTE_ARRAYcolumn.- Parameters:
columnName- the column nametype- the physical typerepetition-REQUIREDorOPTIONALtypeLength- the fixed byte length (required and positive forFIXED_LEN_BYTE_ARRAY, rejected for any other type)logicalType- the annotation, which must be legal fortypeandtypeLength- Throws:
IllegalArgumentException- ifrepetitionisREPEATED,typeLengthdoes not match the type, or the annotation does not apply to the physical type
-
struct
public FileSchema.Builder struct(String structName, RepetitionType repetition, Consumer<FileSchema.StructBuilder> filler) Append astructgroup whose fields are declared byfiller.- Parameters:
structName- the group namerepetition-REQUIREDorOPTIONALfiller- declares the group's fields- Throws:
IllegalArgumentException- ifrepetitionisREPEATEDor the group has no fields
-
list
public FileSchema.Builder list(String listName, RepetitionType repetition, Consumer<FileSchema.ElementBuilder> element) Append aLISTgroup whose element is declared byelement.- Parameters:
listName- the list group namerepetition-REQUIREDorOPTIONAL(whether the list itself may be null)element- declares the list's element- Throws:
IllegalArgumentException- ifrepetitionisREPEATEDor no element is declared
-
map
public FileSchema.Builder map(String mapName, RepetitionType repetition, PhysicalType keyType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose value is declared byvalue. The key is a required primitive ofkeyTypeper the canonical layout.- Parameters:
mapName- the map group namerepetition-REQUIREDorOPTIONAL(whether the map itself may be null)keyType- the physical type of the requiredkeyvalue- declares the map's value, like a list element- Throws:
IllegalArgumentException- ifrepetitionisREPEATEDor no value is declared
-
map
public FileSchema.Builder map(String mapName, RepetitionType repetition, PhysicalType keyType, LogicalType keyLogicalType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose key carries a logical type annotation — aSTRINGkey being the common case.- Parameters:
mapName- the map group namerepetition-REQUIREDorOPTIONAL(whether the map itself may be null)keyType- the physical type of the requiredkeykeyLogicalType- the key's annotation, which must be legal forkeyTypevalue- declares the map's value, like a list element- Throws:
IllegalArgumentException- ifrepetitionisREPEATED, no value is declared, or the annotation does not apply to the key's physical type
-
map
public FileSchema.Builder map(String mapName, RepetitionType repetition, PhysicalType keyType, int keyTypeLength, LogicalType keyLogicalType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose key carries a logical type annotation, giving the fixed byte length of aFIXED_LEN_BYTE_ARRAYkey.- Parameters:
mapName- the map group namerepetition-REQUIREDorOPTIONAL(whether the map itself may be null)keyType- the physical type of the requiredkeykeyTypeLength- the key's fixed byte length (required and positive forFIXED_LEN_BYTE_ARRAY, rejected for any other type)keyLogicalType- the key's annotation, which must be legal forkeyTypeandkeyTypeLengthvalue- declares the map's value, like a list element- Throws:
IllegalArgumentException- ifrepetitionisREPEATED, no value is declared,keyTypeLengthdoes not match the key's type, or the annotation does not apply to it
-
build
Build the schema.- Throws:
IllegalArgumentException- if no fields were added
-