Class StructType

Object
io.delta.kernel.types.DataType
io.delta.kernel.types.StructType

@Evolving public final class StructType extends DataType
Struct type which contains one or more columns.
Since:
3.0.0
  • Constructor Details

    • StructType

      public StructType()
    • StructType

      public StructType(List<StructField> fields)
  • Method Details

    • add

      public StructType add(StructField field)
    • add

      public StructType add(String name, DataType dataType)
    • add

      public StructType add(String name, DataType dataType, boolean nullable)
    • add

      public StructType add(String name, DataType dataType, FieldMetadata metadata)
    • add

      public StructType add(String name, DataType dataType, boolean nullable, FieldMetadata metadata)
    • addMetadataColumn

      public StructType addMetadataColumn(String name, MetadataColumnSpec colType)
      Add a predefined metadata column of MetadataColumnSpec to the struct type.
    • fields

      public List<StructField> fields()
      Returns:
      array of fields
    • fieldNames

      public List<String> fieldNames()
      Returns:
      array of field names
    • length

      public int length()
      Returns:
      the number of fields
    • indexOf

      public int indexOf(String fieldName)
      Returns:
      the index of the field with the given name, or -1 if not found
    • indexOf

      public int indexOf(MetadataColumnSpec spec)
      Returns:
      the index of the metadata column of the given spec, or -1 if not found
    • contains

      public boolean contains(MetadataColumnSpec spec)
      Returns:
      true if the struct type contains a metadata column of the given spec
    • get

      public StructField get(String fieldName)
    • at

      public StructField at(int index)
    • column

      public Column column(int ordinal)
      Creates a Column expression for the field at the given ordinal
      Parameters:
      ordinal - the ordinal of the StructField to create a column for
      Returns:
      a Column expression for the StructField with ordinal ordinal
    • toJson

      public String toJson()
      Convert the struct type to Delta protocol specified serialization format.
      Returns:
      serialized in JSON format.
    • equivalent

      public boolean equivalent(DataType dataType)
      Description copied from class: DataType
      Are the data types same? The metadata, collations or column names could be different.

      Should be used for schema comparisons during schema evolution.

      Overrides:
      equivalent in class DataType
      Parameters:
      dataType -
      Returns:
    • isWriteCompatible

      public boolean isWriteCompatible(DataType dataType)
      Checks whether the given dataType is compatible with this type when writing data. Collation differences are ignored.

      This method is intended to be used during the write path to validate that an input type matches the expected schema before data is written.

      It should not be used in other cases, such as the read path.

      Overrides:
      isWriteCompatible in class DataType
      Parameters:
      dataType - the input data type being written
      Returns:
      true if the input type is compatible with this type.
    • isNested

      public boolean isNested()
      Description copied from class: DataType
      Returns true iff this data is a nested data type (it logically parameterized by other types).

      For example StructType, ArrayType, MapType are nested data types.

      Specified by:
      isNested in class DataType
    • toString

      public String toString()
      Specified by:
      toString in class DataType
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in class DataType
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class DataType