Class FileSchema

java.lang.Object
dev.hardwood.schema.FileSchema

public class FileSchema extends Object
Root schema container representing the complete Parquet schema. Supports both flat schemas and nested structures (structs, lists, maps).
See Also:
  • Method Details

    • getName

      public String getName()
      Returns the schema name (typically "schema" or "message").
    • getColumns

      public List<ColumnSchema> getColumns()
      Returns an unmodifiable list of all leaf columns in schema order.
    • getColumn

      public ColumnSchema getColumn(int index)
      Returns the column at the given zero-based index.
      Parameters:
      index - zero-based column index
    • getColumn

      public ColumnSchema getColumn(String name)

      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; use getColumn(FieldPath) or getColumn(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

      public ColumnSchema getColumn(FieldPath fieldPath)

      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

      public SchemaNode.GroupNode getRootNode()
      Returns the hierarchical schema tree representation.
    • getField

      public SchemaNode getField(String name)

      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

      public static FileSchema.Builder builder(String name)
      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 - if name is null
    • builder

      public static FileSchema.Builder builder(String name, Consumer<FileSchema.StructBuilder> fields)

      Creates a builder whose root fields fields declares on a FileSchema.StructBuilder, the type a nested struct is 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 before FileSchema.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 - if name or fields is null, or fields declares an invalid field
    • toSchemaElements

      public List<SchemaElement> toSchemaElements()
      Flattens this schema back into the depth-first SchemaElement list written to the file footer, the inverse of fromSchemaElements(List): the root element followed by each node in pre-order, groups carrying their child count.
    • fromSchemaElements

      public static FileSchema fromSchemaElements(List<SchemaElement> elements)
      Reconstructs a schema from the depth-first SchemaElement list a footer carries: the root, then each group followed by as many descendants as its numChildren counts. An element without a repetition is read as REQUIRED at the root and OPTIONAL elsewhere.
      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 as STRING on an INT32 or UUID on a FIXED_LEN_BYTE_ARRAY of other than 16 bytes
    • toString

      public String toString()
      Overrides:
      toString in class Object