Class FileSchema
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for constructing aFileSchemaprogrammatically.static final classDeclares the element of aLIST, or the value of aMAP: a primitive, a nestedstruct, a nestedLIST, or a nestedMAP.static final classSets the optional attributes of aLIST,MAPorFILEgroup itself, as opposed to its element, value or children.static final classSets the optional attributes of a primitive leaf: a column, a list element, a map key or a map value.static final classDeclares the fields of astructgroup. -
Method Summary
Modifier and TypeMethodDescriptionstatic FileSchema.BuilderCreates a builder for constructing a schema, flat or nested, programmatically, for use with the writer.static FileSchema.Builderbuilder(String name, Consumer<FileSchema.StructBuilder> fields) Creates a builder whose root fieldsfieldsdeclares on aFileSchema.StructBuilder, the type a nestedstructis declared on, so code that converts another schema model declares the root and every struct with the same method.static FileSchemafromSchemaElements(List<SchemaElement> elements) Reconstructs a schema from the depth-firstSchemaElementlist a footer carries: the root, then each group followed by as many descendants as itsnumChildrencounts.getColumn(int index) Returns the column at the given zero-based index.Returns the column with the given field path.Returns the column with the given name or dot-separated path.intReturns the total number of leaf columns in this schema.Returns an unmodifiable list of all leaf columns in schema order.Finds a top-level field by name in the schema tree.getName()Returns the schema name (typically "schema" or "message").Returns the hierarchical schema tree representation.booleanReturns true if this schema supports direct columnar access.Flattens this schema back into the depth-firstSchemaElementlist written to the file footer, the inverse offromSchemaElements(List): the root element followed by each node in pre-order, groups carrying their child count.toString()
-
Method Details
-
getName
Returns the schema name (typically "schema" or "message"). -
getColumns
Returns an unmodifiable list of all leaf columns in schema order. -
getColumn
Returns the column at the given zero-based index.- Parameters:
index- zero-based column index
-
getColumn
Returns the column with the given name or dot-separated path.
For flat schemas, the name is the column name (e.g.
"passenger_count"). For nested schemas, use the dot-separated field path (e.g."address.zip") to avoid ambiguity when multiple nested columns share a leaf name.A field name may contain dots itself (e.g.
"sepal.length"). When the paths of two fields join to the same dot-separated name, the name is ambiguous; usegetColumn(FieldPath)orgetColumn(int)for such a column.- Parameters:
name- column name or dot-separated field path- Throws:
IllegalArgumentException- if no column with the given name exists, or the name is the path of more than one column
-
getColumn
Returns the column with the given field path.
Sibling fields may share a name, so two columns may share a path; use
getColumn(int)for such a column.- Parameters:
fieldPath- path from schema root to leaf column- Throws:
IllegalArgumentException- if no column with the given path exists, or more than one column has it
-
getColumnCount
public int getColumnCount()Returns the total number of leaf columns in this schema. -
getRootNode
Returns the hierarchical schema tree representation. -
getField
Finds a top-level field by name in the schema tree.
Sibling fields may share a name; use
getRootNode()and its children for such a field.- Throws:
IllegalArgumentException- if no top-level field has the name, or more than one has it
-
isFlatSchema
public boolean isFlatSchema()Returns true if this schema supports direct columnar access. For such schemas, enabling direct columnar access without record assembly.
A schema supports columnar access if all top-level fields are primitives (no nested structs, lists, or maps) and no columns have repetition.
-
builder
Creates a builder for constructing a schema, flat or nested, programmatically, for use with the writer.- Parameters:
name- the schema (message) name, conventionally"schema"- Throws:
IllegalArgumentException- ifnameisnull
-
builder
Creates a builder whose root fields
fieldsdeclares on aFileSchema.StructBuilder, the type a nestedstructis declared on, so code that converts another schema model declares the root and every struct with the same method. More fields can be added to the returned builder beforeFileSchema.Builder.build().FileSchema schema = FileSchema.builder("schema", root -> addFields(root, source.fields())) .build();- Parameters:
name- the schema (message) name, conventionally"schema"fields- declares the root's fields- Throws:
IllegalArgumentException- ifnameorfieldsisnull, orfieldsdeclares an invalid field
-
toSchemaElements
Flattens this schema back into the depth-firstSchemaElementlist written to the file footer, the inverse offromSchemaElements(List): the root element followed by each node in pre-order, groups carrying their child count. -
fromSchemaElements
Reconstructs a schema from the depth-firstSchemaElementlist a footer carries: the root, then each group followed by as many descendants as itsnumChildrencounts. An element without a repetition is read asREQUIREDat the root andOPTIONALelsewhere.- Throws:
IllegalArgumentException- if the list is empty, its root is not a group, its child counts do not describe exactly the elements it holds, a primitive declares children, or an element carries an annotation its field cannot carry, such asSTRINGon anINT32orUUIDon aFIXED_LEN_BYTE_ARRAYof other than 16 bytes
-
toString
-