Class StructType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<StructField>

    public class StructType
    extends DataType
    implements java.lang.Iterable<StructField>
    StructType data type, represents table schema.
    Since:
    0.9.0
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      StructType​(StructField[] fields)
      Creates a StructType object based on the given Array of StructField.
      StructType​(StructType other)
      Clones the given StructType object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      StructType add​(StructField field)
      Creates new StructType by appending the given StructField to the end of this StructType.
      StructType add​(java.lang.String name, DataType dataType)
      Creates new StructType by appending a new StructField with the given info to the end of this StructType.
      StructType add​(java.lang.String name, DataType dataType, boolean nullable)
      Creates new StructType by appending a new StructField with the given info to the end of this StructType.
      static StructType create​(StructField... fields)
      Creates a StructType object based on the given StructField
      boolean equals​(java.lang.Object other)
      Verifies if a StructType equals to this one.
      int fieldIndex​(java.lang.String fieldName)
      Return the index of the specified field.
      java.lang.String[] fieldNames()
      Retrieves the names of all StructField in this StructType.
      StructField get​(int index)
      Retrieves the StructField object from the given index.
      int hashCode()
      Calculates the hash code of this StructType Object.
      java.util.Iterator<StructField> iterator()
      Creates an Iterator of StructFields.
      java.lang.String[] names()
      Retrieves the names of all StructField in this StructType.
      java.util.Optional<StructField> nameToField​(java.lang.String name)
      Retrieves the corresponding StructField object of the given name.
      void printTreeString()
      Prints the schema StructType content in a tree structure diagram.
      int size()
      Counts the number of StructFields in this StructType object.
      java.lang.String toString()
      Generates a String value to represent this StructType.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • StructType

        public StructType​(StructType other)
        Clones the given StructType object.
        Parameters:
        other - A StructType object
        Since:
        0.9.0
      • StructType

        public StructType​(StructField[] fields)
        Creates a StructType object based on the given Array of StructField.
        Parameters:
        fields - An Array of StructField
        Since:
        0.9.0
    • Method Detail

      • create

        public static StructType create​(StructField... fields)
        Creates a StructType object based on the given StructField
        Parameters:
        fields - A list of StructFields
        Returns:
        A new StructType object
        Since:
        0.9.0
      • fieldIndex

        public int fieldIndex​(java.lang.String fieldName)
        Return the index of the specified field.
        Parameters:
        fieldName - the name of the field.
        Returns:
        the index of the field with the specified name.
        Throws:
        java.lang.IllegalArgumentException - if the given field name does not exist in the schema.
        Since:
        1.15.0
      • names

        public java.lang.String[] names()
        Retrieves the names of all StructField in this StructType.

        Example:

        
         StructType schema = new StructType(new StructField[] {
           new StructField("c1", DataTypes.IntegerType),
           new StructField("c2", DataTypes.StringType),
         });
         schema.names();
         // res: String[] = {"C1", "C2"}
         
        Returns:
        an array representing the names of the fields in this StructType.
        Since:
        0.9.0
      • fieldNames

        public java.lang.String[] fieldNames()
        Retrieves the names of all StructField in this StructType. This is an alias of names().

        Example:

        
         StructType schema = new StructType(new StructField[] {
           new StructField("c1", DataTypes.IntegerType),
           new StructField("c2", DataTypes.StringType),
         });
         schema.fieldNames();
         // res: String[] = {"C1", "C2"}
         
        Returns:
        an array representing the names of the fields in this StructType.
        Since:
        1.17.0
      • size

        public int size()
        Counts the number of StructFields in this StructType object.
        Returns:
        An int number
        Since:
        0.9.0
      • iterator

        public java.util.Iterator<StructField> iterator()
        Creates an Iterator of StructFields.
        Specified by:
        iterator in interface java.lang.Iterable<StructField>
        Returns:
        An Iterator of StructField
        Since:
        0.9.0
      • get

        public StructField get​(int index)
        Retrieves the StructField object from the given index.
        Parameters:
        index - An int number representing the index of StructField
        Returns:
        The StructField object at the given index.
        Since:
        0.9.0
      • toString

        public java.lang.String toString()
        Generates a String value to represent this StructType.
        Overrides:
        toString in class DataType
        Returns:
        A String value in the format of "StructType[StructField('name', 'data type', 'nullable')...]"
        Since:
        0.9.0
      • add

        public StructType add​(StructField field)
        Creates new StructType by appending the given StructField to the end of this StructType. This function doesn't modify this StructType object, but create and return a new one.
        Parameters:
        field - The StructField object being appended.
        Returns:
        A new StructType object
        Since:
        0.9.0
      • add

        public StructType add​(java.lang.String name,
                              DataType dataType,
                              boolean nullable)
        Creates new StructType by appending a new StructField with the given info to the end of this StructType. This function doesn't modify this StructType object, but create or return a new one.
        Parameters:
        name - The name of the StructField object being appended.
        dataType - The data type of the StructField object being appended.
        nullable - Whether the new StructField is nullable or not
        Returns:
        A new StructType object
        Since:
        0.9.0
      • add

        public StructType add​(java.lang.String name,
                              DataType dataType)
        Creates new StructType by appending a new StructField with the given info to the end of this StructType. The new StructField is nullable. This function doesn't modify this StructType object, but create and return a new one.
        Parameters:
        name - The name of the StructField object being appended.
        dataType - The data type of the StructField object being appended.
        Returns:
        A new StructType object
        Since:
        0.9.0
      • nameToField

        public java.util.Optional<StructField> nameToField​(java.lang.String name)
        Retrieves the corresponding StructField object of the given name.
        Parameters:
        name - The name of StructField
        Returns:
        An Optional StructField object.
        Since:
        0.9.0
      • equals

        public boolean equals​(java.lang.Object other)
        Verifies if a StructType equals to this one.
        Overrides:
        equals in class DataType
        Parameters:
        other - A StructType object
        Returns:
        true if these data types are equivalent, false for otherwise.
        Since:
        0.9.0
      • hashCode

        public int hashCode()
        Calculates the hash code of this StructType Object.
        Overrides:
        hashCode in class DataType
        Returns:
        An int number representing the hash code value
        Since:
        0.9.0
      • printTreeString

        public void printTreeString()
        Prints the schema StructType content in a tree structure diagram.
        Since:
        0.9.0