Class FileSchema.Builder
- Enclosing class:
FileSchema
Builder for constructing a FileSchema programmatically.
Fields are added as top-level primitive leaves (primitive(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.
Every method of this builder and of the builders its lambdas receive throws
IllegalArgumentException for a null argument, and for a field name that is empty or
already declared among the same group's fields. Error messages name a nested field by its
dotted path, a list element as <list>.list.element and a map value as
<map>.key_value.value.
The name, physical type and repetition of a primitive leaf are positional. Its optional
attributes (logical type, type length, field id) are set in a FileSchema.PrimitiveBuilder lambda:
FileSchema schema = FileSchema.builder("schema")
.primitive("id", PhysicalType.FIXED_LEN_BYTE_ARRAY, RepetitionType.REQUIRED,
col -> col.logicalType(LogicalType.uuid()).fieldId(1))
.primitive("name", PhysicalType.BYTE_ARRAY, RepetitionType.OPTIONAL,
col -> col.logicalType(LogicalType.string()).fieldId(2))
.build();
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the schema.file(String fileName, RepetitionType repetition) Append aFILEgroup, a reference to a range of bytes stored inline or in an external file.file(String fileName, RepetitionType repetition, Consumer<FileSchema.GroupBuilder> group) Append aFILEgroup whose own attributes are set bygroup, asfile(String, RepetitionType)describes.list(String listName, RepetitionType repetition, Consumer<FileSchema.ElementBuilder> element) Append aLISTgroup whose element is declared byelement.list(String listName, RepetitionType repetition, Consumer<FileSchema.GroupBuilder> group, Consumer<FileSchema.ElementBuilder> element) Append aLISTgroup whose own attributes are set bygroupand whose element is declared byelement.map(String mapName, RepetitionType repetition, PhysicalType keyType, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose value is declared byvalue.map(String mapName, RepetitionType repetition, PhysicalType keyType, Consumer<FileSchema.PrimitiveBuilder> key, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose key has optional attributes, set bykey.map(String mapName, RepetitionType repetition, Consumer<FileSchema.GroupBuilder> group, PhysicalType keyType, Consumer<FileSchema.PrimitiveBuilder> key, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose own attributes are set bygroupand whose key has optional attributes, set bykey, asmap(String, RepetitionType, PhysicalType, Consumer, Consumer)describes.primitive(String columnName, PhysicalType type, RepetitionType repetition) Append a primitive column without optional attributes.primitive(String columnName, PhysicalType type, RepetitionType repetition, Consumer<FileSchema.PrimitiveBuilder> column) Append a primitive column whose optional attributes are set bycolumn.struct(String structName, RepetitionType repetition, Consumer<FileSchema.StructBuilder> filler) Append astructgroup whose fields are declared byfiller.
-
Method Details
-
primitive
public FileSchema.Builder primitive(String columnName, PhysicalType type, RepetitionType repetition) Append a primitive column without optional attributes.- Parameters:
columnName- the column nametype- the physical typerepetition-REQUIREDorOPTIONAL- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATED, ortypeisFIXED_LEN_BYTE_ARRAY(which needs a type length or an annotation that implies one)
-
primitive
public FileSchema.Builder primitive(String columnName, PhysicalType type, RepetitionType repetition, Consumer<FileSchema.PrimitiveBuilder> column) Append a primitive column whose optional attributes are set by
column.A
FIXED_LEN_BYTE_ARRAYcolumn without aFileSchema.PrimitiveBuilder.typeLengthtakes the length its annotation implies: 16 bytes forUUID, 12 forINTERVAL, 2 forFLOAT16, and forDECIMALthe fewest bytes that hold its precision.- Parameters:
columnName- the column nametype- the physical typerepetition-REQUIREDorOPTIONALcolumn- sets the column's logical type, type length and field id- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATED, the type length does not match the type, the annotation does not apply to the type, ortypeisFIXED_LEN_BYTE_ARRAYwith no type length and no annotation that implies one
-
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, and optionally its field id- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATEDor the group has no fields
-
file
Append aFILEgroup, a reference to a range of bytes stored inline or in an external file. The group declares all six children the format defines, eachOPTIONAL:uriandcontent_typeandchecksum(BYTE_ARRAYannotatedSTRING),offsetandsize(INT64), andinline(BYTE_ARRAY). A row writes it throughStructBuilder.setFile(String, dev.hardwood.row.PqFile).- Parameters:
fileName- the group namerepetition-REQUIREDorOPTIONAL- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull, orrepetitionisREPEATED
-
file
public FileSchema.Builder file(String fileName, RepetitionType repetition, Consumer<FileSchema.GroupBuilder> group) Append aFILEgroup whose own attributes are set bygroup, asfile(String, RepetitionType)describes. The children of the group have no field id.- Parameters:
fileName- the group namerepetition-REQUIREDorOPTIONALgroup- sets the group's field id- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull, orrepetitionisREPEATED
-
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- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATEDor no element is declared
-
list
public FileSchema.Builder list(String listName, RepetitionType repetition, Consumer<FileSchema.GroupBuilder> group, Consumer<FileSchema.ElementBuilder> element) Append aLISTgroup whose own attributes are set bygroupand whose element is declared byelement.- Parameters:
listName- the list group namerepetition-REQUIREDorOPTIONAL(whether the list itself may be null)group- sets the list group's field idelement- declares the list's element- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATEDor 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- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATED, no value is declared, orkeyTypeisFIXED_LEN_BYTE_ARRAY
-
map
public FileSchema.Builder map(String mapName, RepetitionType repetition, PhysicalType keyType, Consumer<FileSchema.PrimitiveBuilder> key, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose key has optional attributes, set bykey. ASTRINGkey is the usual case. AFIXED_LEN_BYTE_ARRAYkey takes a type length asprimitive(String, PhysicalType, RepetitionType, Consumer)describes.- Parameters:
mapName- the map group namerepetition-REQUIREDorOPTIONAL(whether the map itself may be null)keyType- the physical type of the requiredkeykey- sets the key's logical type, type length and field idvalue- declares the map's value like a list element- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATED, no value is declared, or the key's attributes do not matchkeyType
-
map
public FileSchema.Builder map(String mapName, RepetitionType repetition, Consumer<FileSchema.GroupBuilder> group, PhysicalType keyType, Consumer<FileSchema.PrimitiveBuilder> key, Consumer<FileSchema.ElementBuilder> value) Append aMAPgroup whose own attributes are set bygroupand whose key has optional attributes, set bykey, asmap(String, RepetitionType, PhysicalType, Consumer, Consumer)describes.- Parameters:
mapName- the map group namerepetition-REQUIREDorOPTIONAL(whether the map itself may be null)group- sets the map group's field idkeyType- the physical type of the requiredkeykey- sets the key's logical type, type length and field idvalue- declares the map's value like a list element- Throws:
IllegalArgumentException- if the name isnull, empty or already declared, an argument isnull,repetitionisREPEATED, no value is declared, or the key's attributes do not matchkeyType
-
build
Build the schema.- Throws:
UnsupportedOperationException- if no fields were added; the writer does not produce a schema with no columns
-