Class Row

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class Row
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Represents a row returned by the evaluation of a DataFrame.
    Since:
    0.9.0
    See Also:
    DataFram, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Row​(java.lang.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​(java.lang.Object... values)
      Creates a Row based on the given values.
      boolean equals​(java.lang.Object other)
      Verifies the equality of two Row objects.
      int fieldIndex​(java.lang.String fieldName)
      Returns the index of the field with the specified name.
      java.lang.Object get​(int index)
      Retrieves the value of column in the Row at the given index.
      <T> T getAs​(int index, java.lang.Class<T> clazz)
      Returns the value at the specified column index and casts it to the desired type T.
      <T> T getAs​(java.lang.String fieldName, java.lang.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.
      java.sql.Date getDate​(int index)
      Retrieves the value of the column at the given index as a Date value.
      java.math.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.
      java.util.List<?> getList​(int index)
      Retrieves the value of the column at the given index as a list of Object.
      java.util.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.
      java.util.Map<?,​?> getMap​(int index)
      Retrieves the value of the column at the given index as a Java Map
      java.util.Map<java.lang.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.
      java.lang.String getString​(int index)
      Retrieves the value of the column at the given index as a String value.
      java.sql.Time getTime​(int index)
      Retrieves the value of the column at the given index as a Time value.
      java.sql.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.
      java.lang.String mkString()
      Creates a string representation of all elements in this Row without any separators.
      java.lang.String mkString​(java.lang.String sep)
      Creates a string representation of all elements in this Row using the specified separator.
      java.lang.String mkString​(java.lang.String start, java.lang.String sep, java.lang.String end)
      Creates a string representation of all elements in this Row using the specified start string, separator, and end string.
      int size()
      Counts the number of column in this Row.
      java.util.List<java.lang.Object> toList()
      Converts this Row to a List of Object.
      java.lang.String toString()
      Generates a string value to represent the content of this row.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Row

        public Row​(java.lang.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 java.util.List<java.lang.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 java.lang.Object
        Returns:
        A new Row object containing same elements as this Row
        Since:
        0.9.0
      • equals

        public boolean equals​(java.lang.Object other)
        Verifies the equality of two Row objects.
        Overrides:
        equals in class java.lang.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 java.lang.Object
        Returns:
        An int number representing the hash code
        Since:
        0.9.0
      • get

        public java.lang.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 java.lang.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 java.sql.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 java.sql.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 java.sql.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 java.math.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 java.util.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 java.util.Map<java.lang.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 java.util.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 java.util.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​(java.lang.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:
        java.lang.UnsupportedOperationException - if schema information is not available.
        Since:
        1.15.0
      • getAs

        public <T> T getAs​(int index,
                           java.lang.Class<T> clazz)
                    throws java.lang.ClassCastException,
                           java.lang.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:
        java.lang.ClassCastException - if the value at the given index cannot be cast to type T.
        java.lang.ArrayIndexOutOfBoundsException - if the column index is out of bounds.
        Since:
        1.15.0
      • getAs

        public <T> T getAs​(java.lang.String fieldName,
                           java.lang.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:
        java.lang.ClassCastException - if the value of the field cannot be cast to type T.
        java.lang.IllegalArgumentException - if the name of the field is not part of the row schema.
        java.lang.UnsupportedOperationException - if the schema information is not available.
        Since:
        1.15.0
      • mkString

        public java.lang.String mkString()
        Creates a string representation of all elements in this Row without any separators.

        Example:

        
         Row row = Row.create(1, "hello", 3.14, null);
         row.mkString();
         // res: String = "1hello3.14null"
         
        Returns:
        a string containing all field values concatenated together
        Since:
        1.17.0
      • mkString

        public java.lang.String mkString​(java.lang.String sep)
        Creates a string representation of all elements in this Row using the specified separator.

        Example:

        
         Row row = Row.create(1, "hello", 3.14, null);
         row.mkString(", ");
         // res: String = "1, hello, 3.14, null"
        
         row.mkString(" | ");
         // res: String = "1 | hello | 3.14 | null"
        
         row.mkString("");
         // res: String = "1hello3.14null"
         
        Parameters:
        sep - the separator string to insert between field values
        Returns:
        a string containing all field values separated by the given separator
        Since:
        1.17.0
      • mkString

        public java.lang.String mkString​(java.lang.String start,
                                         java.lang.String sep,
                                         java.lang.String end)
        Creates a string representation of all elements in this Row using the specified start string, separator, and end string.

        Example:

        
         Row row = Row.create(1, "hello", 3.14, null);
         row.mkString("[", " | ", "]");
         // res: String = "[1 | hello | 3.14 | null]"
        
         Row emptyRow = Row.create();
         emptyRow.mkString("(", ", ", ")");
         // res: String = "()"
         
        Parameters:
        start - the string to prepend to the result
        sep - the separator string to insert between field values
        end - the string to append to the result
        Returns:
        a string containing all field values formatted with the specified start, separator, and end
        Since:
        1.17.0
      • toString

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

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