Class Row

    • Constructor Summary

      Constructors 
      Constructor Description
      Row​(Object[] values)
      Creates a Row based on the values in the given array.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Row clone()
      Creates a clone of this Row object.
      static Row create​(Object... values)
      Creates a Row based on the given values.
      boolean equals​(Object other)
      Verifies the equality of two Row objects.
      int fieldIndex​(String fieldName)
      Returns the index of the field with the specified name.
      Object get​(int index)
      Retrieves the value of column in the Row at the given index.
      <T> T getAs​(int index, Class<T> clazz)
      Returns the value at the specified column index and casts it to the desired type T.
      <T> T getAs​(String fieldName, Class<T> clazz)
      Returns the field value for the specified field name and casts it to the desired type T.
      byte[] getBinary​(int index)
      Retrieves the value of the column at the given index as an array of byte.
      boolean getBoolean​(int index)
      Retrieves the value of the column at the given index as a boolean value.
      byte getByte​(int index)
      Retrieves the value of the column at the given index as a byte value.
      Date getDate​(int index)
      Retrieves the value of the column at the given index as a Date value.
      BigDecimal getDecimal​(int index)
      Retrieves the value of the column at the given index as a BigDecimal value.
      double getDouble​(int index)
      Retrieves the value of the column at the given index as a double value.
      float getFloat​(int index)
      Retrieves the value of the column at the given index as a float value.
      Geography getGeography​(int index)
      Retrieves the value of the column at the given index as a Geography value.
      Geometry getGeometry​(int index)
      Retrieves the value of the column at the given index as a Geometry value.
      int getInt​(int index)
      Retrieves the value of the column at the given index as a int value.
      List<?> getList​(int index)
      Retrieves the value of the column at the given index as a list of Object.
      List<Variant> getListOfVariant​(int index)
      Retrieves the value of the column at the given index as a list of Variant.
      long getLong​(int index)
      Retrieves the value of the column at the given index as a long value.
      Map<?,​?> getMap​(int index)
      Retrieves the value of the column at the given index as a Java Map
      Map<String,​Variant> getMapOfVariant​(int index)
      Retrieves the value of the column at the given index as a map of Variant
      Row getObject​(int index)
      Retrieves the value of the column at the given index as a Row
      short getShort​(int index)
      Retrieves the value of the column at the given index as a short value.
      String getString​(int index)
      Retrieves the value of the column at the given index as a String value.
      Time getTime​(int index)
      Retrieves the value of the column at the given index as a Time value.
      Timestamp getTimestamp​(int index)
      Retrieves the value of the column at the given index as a Timestamp value.
      Variant getVariant​(int index)
      Retrieves the value of the column at the given index as a Variant value.
      int hashCode()
      Calculates the hash code of this Row object
      boolean isNullAt​(int index)
      Verifies if the value of the column at the given index is null.
      int size()
      Counts the number of column in this Row.
      List<Object> toList()
      Converts this Row to a List of Object.
      String toString()
      Generates a string value to represent the content of this row.
    • Constructor Detail

      • Row

        public Row​(Object[] values)
        Creates a Row based on the values in the given array.
        Parameters:
        values - Row elements
        Since:
        0.9.0
    • Method Detail

      • toList

        public List<Object> toList()
        Converts this Row to a List of Object.
        Returns:
        A List contains Row elements.
        Since:
        0.9.0
      • size

        public int size()
        Counts the number of column in this Row.
        Returns:
        An integer number represents the size of this Row
        Since:
        0.9.0
      • clone

        public Row clone()
        Creates a clone of this Row object.
        Overrides:
        clone in class Object
        Returns:
        A new Row object containing same elements as this Row
        Since:
        0.9.0
      • equals

        public boolean equals​(Object other)
        Verifies the equality of two Row objects.
        Overrides:
        equals in class Object
        Parameters:
        other - The Row object to be compared to
        Returns:
        true if the given row equals this row.
        Since:
        0.9.0
      • hashCode

        public int hashCode()
        Calculates the hash code of this Row object
        Overrides:
        hashCode in class Object
        Returns:
        An int number representing the hash code
        Since:
        0.9.0
      • get

        public Object get​(int index)
        Retrieves the value of column in the Row at the given index.
        Parameters:
        index - The index of the target column
        Returns:
        The value of the column at the given index
      • isNullAt

        public boolean isNullAt​(int index)
        Verifies if the value of the column at the given index is null.
        Parameters:
        index - The index of target column
        Returns:
        true if the value is null at the given index
        Since:
        0.9.0
      • getBoolean

        public boolean getBoolean​(int index)
        Retrieves the value of the column at the given index as a boolean value.
        Parameters:
        index - The index of target column
        Returns:
        The boolean value of the column at the given index
        Since:
        0.9.0
      • getByte

        public byte getByte​(int index)
        Retrieves the value of the column at the given index as a byte value.
        Parameters:
        index - The index of target column
        Returns:
        The byte value of the column at the given index
        Since:
        0.9.0
      • getShort

        public short getShort​(int index)
        Retrieves the value of the column at the given index as a short value.
        Parameters:
        index - The index of target column
        Returns:
        The short value of the column at the given index
        Since:
        0.9.0
      • getInt

        public int getInt​(int index)
        Retrieves the value of the column at the given index as a int value.
        Parameters:
        index - The index of target column
        Returns:
        The int value of the column at the given index
        Since:
        0.9.0
      • getLong

        public long getLong​(int index)
        Retrieves the value of the column at the given index as a long value.
        Parameters:
        index - The index of target column
        Returns:
        The long value of the column at the given index
        Since:
        0.9.0
      • getFloat

        public float getFloat​(int index)
        Retrieves the value of the column at the given index as a float value.
        Parameters:
        index - The index of target column
        Returns:
        The float value of the column at the given index
        Since:
        0.9.0
      • getDouble

        public double getDouble​(int index)
        Retrieves the value of the column at the given index as a double value.
        Parameters:
        index - The index of target column
        Returns:
        The double value of the column at the given index
        Since:
        0.9.0
      • getString

        public String getString​(int index)
        Retrieves the value of the column at the given index as a String value.
        Parameters:
        index - The index of target column
        Returns:
        The String value of the column at the given index
        Since:
        0.9.0
      • getBinary

        public byte[] getBinary​(int index)
        Retrieves the value of the column at the given index as an array of byte.
        Parameters:
        index - The index of target column
        Returns:
        An array of byte representing the binary value
        Since:
        0.9.0
      • getDate

        public Date getDate​(int index)
        Retrieves the value of the column at the given index as a Date value.
        Parameters:
        index - The index of target column
        Returns:
        The Date value of the column at the given index
        Since:
        0.9.0
      • getTime

        public Time getTime​(int index)
        Retrieves the value of the column at the given index as a Time value.
        Parameters:
        index - The index of target column
        Returns:
        The Time value of the column at the given index
        Since:
        0.9.0
      • getTimestamp

        public Timestamp getTimestamp​(int index)
        Retrieves the value of the column at the given index as a Timestamp value.
        Parameters:
        index - The index of target column
        Returns:
        The Timestamp value of the column at the given index
        Since:
        0.9.0
      • getDecimal

        public BigDecimal getDecimal​(int index)
        Retrieves the value of the column at the given index as a BigDecimal value.
        Parameters:
        index - The index of target column
        Returns:
        The BigDecimal value of the column at the given index
        Since:
        0.9.0
      • getVariant

        public Variant getVariant​(int index)
        Retrieves the value of the column at the given index as a Variant value.
        Parameters:
        index - The index of target column
        Returns:
        The Variant value of the column at the given index
        Since:
        0.9.0
      • getGeography

        public Geography getGeography​(int index)
        Retrieves the value of the column at the given index as a Geography value.
        Parameters:
        index - The index of target column
        Returns:
        The Geography value of the column at the given index
        Since:
        0.9.0
      • getGeometry

        public Geometry getGeometry​(int index)
        Retrieves the value of the column at the given index as a Geometry value.
        Parameters:
        index - The index of target column
        Returns:
        The Geometry value of the column at the given index
        Since:
        1.12.0
      • getListOfVariant

        public List<Variant> getListOfVariant​(int index)
        Retrieves the value of the column at the given index as a list of Variant.
        Parameters:
        index - The index of target column
        Returns:
        A list of Variant
        Since:
        0.9.0
      • getMapOfVariant

        public Map<String,​Variant> getMapOfVariant​(int index)
        Retrieves the value of the column at the given index as a map of Variant
        Parameters:
        index - The index of target column
        Returns:
        A map from String to Variant
        Since:
        0.9.0
      • getList

        public List<?> getList​(int index)
        Retrieves the value of the column at the given index as a list of Object.
        Parameters:
        index - The index of target column
        Returns:
        A list of Object
        Since:
        1.13.0
      • getMap

        public Map<?,​?> getMap​(int index)
        Retrieves the value of the column at the given index as a Java Map
        Parameters:
        index - The index of target column
        Returns:
        A Java Map
        Since:
        1.13.0
      • getObject

        public Row getObject​(int index)
        Retrieves the value of the column at the given index as a Row
        Parameters:
        index - The index of target column
        Returns:
        A Row
        Since:
        1.13.0
      • fieldIndex

        public int fieldIndex​(String fieldName)
        Returns the index of the field with the specified name.
        Parameters:
        fieldName - the name of the field.
        Returns:
        the index of the specified field.
        Throws:
        UnsupportedOperationException - if schema information is not available.
        Since:
        1.15.0
      • getAs

        public <T> T getAs​(int index,
                           Class<T> clazz)
                    throws ClassCastException,
                           ArrayIndexOutOfBoundsException
        Returns the value at the specified column index and casts it to the desired type T.

        Example:

        
         Row row = Row.create(1, "Alice", 95.5);
         row.getAs(0, Integer.class); // Returns 1 as an Int
         row.getAs(1, String.class); // Returns "Alice" as a String
         row.getAs(2, Double.class); // Returns 95.5 as a Double
         
        Type Parameters:
        T - the expected type of the value at the specified column index.
        Parameters:
        index - the zero-based column index within the row.
        clazz - the Class object representing the type T.
        Returns:
        the value at the specified column index cast to type T.
        Throws:
        ClassCastException - if the value at the given index cannot be cast to type T.
        ArrayIndexOutOfBoundsException - if the column index is out of bounds.
        Since:
        1.15.0
      • getAs

        public <T> T getAs​(String fieldName,
                           Class<T> clazz)
        Returns the field value for the specified field name and casts it to the desired type T.

        Example:

        
         StructType schema =
             StructType.create(
                new StructField("name", DataTypes.StringType),
                new StructField("val", DataTypes.IntegerType));
         Row[] data = { Row.create("Alice", 1) };
         DataFrame df = session.createDataFrame(data, schema);
         Row row = df.collect()[0];
        
         row.getAs("name", String.class); // Returns "Alice" as a String
         row.getAs("val", Integer.class); // Returns 1 as an Int
         
        Type Parameters:
        T - the expected type of the value for the specified field name.
        Parameters:
        fieldName - the name of the field within the row.
        clazz - the Class object representing the type T.
        Returns:
        the field value for the specified field name cast to type T.
        Throws:
        ClassCastException - if the value of the field cannot be cast to type T.
        IllegalArgumentException - if the name of the field is not part of the row schema.
        UnsupportedOperationException - if the schema information is not available.
        Since:
        1.15.0
      • toString

        public String toString()
        Generates a string value to represent the content of this row.
        Overrides:
        toString in class Object
        Returns:
        A String value representing the content of this row
        Since:
        0.9.0
      • create

        public static Row create​(Object... values)
        Creates a Row based on the given values.
        Parameters:
        values - Row elements.
        Returns:
        A Row object.
        Since:
        0.9.0