Packages

trait Row extends Serializable

Represents one row of output from a relational operator. Allows both generic access by ordinal, which will incur boxing overhead for primitives, as well as native primitive access.

It is invalid to use the native primitive interface to retrieve a value that is null, instead a user must check isNullAt before attempting to retrieve a value that might be null.

To create a new Row, use RowFactory.create() in Java or Row.apply() in Scala.

A Row object can be constructed by providing field values. Example:

import org.apache.spark.sql._

// Create a Row from values.
Row(value1, value2, value3, ...)
// Create a Row from a Seq of values.
Row.fromSeq(Seq(value1, value2, ...))

A value of a row can be accessed through both generic access by ordinal, which will incur boxing overhead for primitives, as well as native primitive access. An example of generic access by ordinal:

import org.apache.spark.sql._

val row = Row(1, true, "a string", null)
// row: Row = [1,true,a string,null]
val firstValue = row(0)
// firstValue: Any = 1
val fourthValue = row(3)
// fourthValue: Any = null

For native primitive access, it is invalid to use the native primitive interface to retrieve a value that is null, instead a user must check isNullAt before attempting to retrieve a value that might be null. An example of native primitive access:

// using the row from the previous example.
val firstValue = row.getInt(0)
// firstValue: Int = 1
val isNull = row.isNullAt(3)
// isNull: Boolean = true

In Scala, fields in a Row object can be extracted in a pattern match. Example:

import org.apache.spark.sql._

val pairs = sql("SELECT key, value FROM src").rdd.map {
  case Row(key: Int, value: String) =>
    key -> value
}
Annotations
@Stable()
Source
Row.scala
Since

1.3.0

Linear Supertypes
Serializable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Row
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def copy(): Row

    Make a copy of the current Row object.

  2. abstract def get(i: Int): Any

    Returns the value at position i.

    Returns the value at position i. If the value is null, null is returned. The following is a mapping between Spark SQL types and return types:

    BooleanType -> java.lang.Boolean
    ByteType -> java.lang.Byte
    ShortType -> java.lang.Short
    IntegerType -> java.lang.Integer
    LongType -> java.lang.Long
    FloatType -> java.lang.Float
    DoubleType -> java.lang.Double
    StringType -> String
    DecimalType -> java.math.BigDecimal
    
    DateType -> java.sql.Date if spark.sql.datetime.java8API.enabled is false
    DateType -> java.time.LocalDate if spark.sql.datetime.java8API.enabled is true
    
    TimestampType -> java.sql.Timestamp if spark.sql.datetime.java8API.enabled is false
    TimestampType -> java.time.Instant if spark.sql.datetime.java8API.enabled is true
    
    BinaryType -> byte array
    ArrayType -> scala.collection.Seq (use getList for java.util.List)
    MapType -> scala.collection.Map (use getJavaMap for java.util.Map)
    StructType -> org.apache.spark.sql.Row
  3. abstract def length: Int

    Number of elements in the Row.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def anyNull: Boolean

    Returns true if there are any NULL values in this row.

  5. def apply(i: Int): Any

    Returns the value at position i.

    Returns the value at position i. If the value is null, null is returned. The following is a mapping between Spark SQL types and return types:

    BooleanType -> java.lang.Boolean
    ByteType -> java.lang.Byte
    ShortType -> java.lang.Short
    IntegerType -> java.lang.Integer
    LongType -> java.lang.Long
    FloatType -> java.lang.Float
    DoubleType -> java.lang.Double
    StringType -> String
    DecimalType -> java.math.BigDecimal
    
    DateType -> java.sql.Date if spark.sql.datetime.java8API.enabled is false
    DateType -> java.time.LocalDate if spark.sql.datetime.java8API.enabled is true
    
    TimestampType -> java.sql.Timestamp if spark.sql.datetime.java8API.enabled is false
    TimestampType -> java.time.Instant if spark.sql.datetime.java8API.enabled is true
    
    BinaryType -> byte array
    ArrayType -> scala.collection.Seq (use getList for java.util.List)
    MapType -> scala.collection.Map (use getJavaMap for java.util.Map)
    StructType -> org.apache.spark.sql.Row
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(o: Any): Boolean
    Definition Classes
    Row → AnyRef → Any
  10. def fieldIndex(name: String): Int

    Returns the index of a given field name.

    Returns the index of a given field name.

    Exceptions thrown

    IllegalArgumentException when a field name does not exist.

    UnsupportedOperationException when schema is not defined.

  11. def getAs[T](fieldName: String): T

    Returns the value of a given fieldName.

    Returns the value of a given fieldName. For primitive types if value is null it returns 'zero value' specific for primitive i.e. 0 for Int - use isNullAt to ensure that value is not null

    Exceptions thrown

    ClassCastException when data type does not match.

    IllegalArgumentException when fieldName do not exist.

    UnsupportedOperationException when schema is not defined.

  12. def getAs[T](i: Int): T

    Returns the value at position i.

    Returns the value at position i. For primitive types if value is null it returns 'zero value' specific for primitive i.e. 0 for Int - use isNullAt to ensure that value is not null

    Exceptions thrown

    ClassCastException when data type does not match.

  13. def getBoolean(i: Int): Boolean

    Returns the value at position i as a primitive boolean.

    Returns the value at position i as a primitive boolean.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  14. def getByte(i: Int): Byte

    Returns the value at position i as a primitive byte.

    Returns the value at position i as a primitive byte.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  15. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  16. def getDate(i: Int): Date

    Returns the value at position i of date type as java.sql.Date.

    Returns the value at position i of date type as java.sql.Date.

    Exceptions thrown

    ClassCastException when data type does not match.

  17. def getDecimal(i: Int): BigDecimal

    Returns the value at position i of decimal type as java.math.BigDecimal.

    Returns the value at position i of decimal type as java.math.BigDecimal.

    Exceptions thrown

    ClassCastException when data type does not match.

  18. def getDouble(i: Int): Double

    Returns the value at position i as a primitive double.

    Returns the value at position i as a primitive double.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  19. def getFloat(i: Int): Float

    Returns the value at position i as a primitive float.

    Returns the value at position i as a primitive float. Throws an exception if the type mismatches or if the value is null.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  20. def getInstant(i: Int): Instant

    Returns the value at position i of date type as java.time.Instant.

    Returns the value at position i of date type as java.time.Instant.

    Exceptions thrown

    ClassCastException when data type does not match.

  21. def getInt(i: Int): Int

    Returns the value at position i as a primitive int.

    Returns the value at position i as a primitive int.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  22. def getJavaMap[K, V](i: Int): Map[K, V]

    Returns the value at position i of array type as a java.util.Map.

    Returns the value at position i of array type as a java.util.Map.

    Exceptions thrown

    ClassCastException when data type does not match.

  23. def getList[T](i: Int): List[T]

    Returns the value at position i of array type as java.util.List.

    Returns the value at position i of array type as java.util.List.

    Exceptions thrown

    ClassCastException when data type does not match.

  24. def getLocalDate(i: Int): LocalDate

    Returns the value at position i of date type as java.time.LocalDate.

    Returns the value at position i of date type as java.time.LocalDate.

    Exceptions thrown

    ClassCastException when data type does not match.

  25. def getLong(i: Int): Long

    Returns the value at position i as a primitive long.

    Returns the value at position i as a primitive long.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  26. def getMap[K, V](i: Int): Map[K, V]

    Returns the value at position i of map type as a Scala Map.

    Returns the value at position i of map type as a Scala Map.

    Exceptions thrown

    ClassCastException when data type does not match.

  27. def getSeq[T](i: Int): Seq[T]

    Returns the value at position i of array type as a Scala Seq.

    Returns the value at position i of array type as a Scala Seq.

    Exceptions thrown

    ClassCastException when data type does not match.

  28. def getShort(i: Int): Short

    Returns the value at position i as a primitive short.

    Returns the value at position i as a primitive short.

    Exceptions thrown

    ClassCastException when data type does not match.

    NullPointerException when value is null.

  29. def getString(i: Int): String

    Returns the value at position i as a String object.

    Returns the value at position i as a String object.

    Exceptions thrown

    ClassCastException when data type does not match.

  30. def getStruct(i: Int): Row

    Returns the value at position i of struct type as a Row object.

    Returns the value at position i of struct type as a Row object.

    Exceptions thrown

    ClassCastException when data type does not match.

  31. def getTimestamp(i: Int): Timestamp

    Returns the value at position i of date type as java.sql.Timestamp.

    Returns the value at position i of date type as java.sql.Timestamp.

    Exceptions thrown

    ClassCastException when data type does not match.

  32. def getValuesMap[T](fieldNames: Seq[String]): Map[String, T]

    Returns a Map consisting of names and values for the requested fieldNames For primitive types if value is null it returns 'zero value' specific for primitive i.e.

    Returns a Map consisting of names and values for the requested fieldNames For primitive types if value is null it returns 'zero value' specific for primitive i.e. 0 for Int - use isNullAt to ensure that value is not null

    Exceptions thrown

    ClassCastException when data type does not match.

    IllegalArgumentException when fieldName do not exist.

    UnsupportedOperationException when schema is not defined.

  33. def hashCode(): Int
    Definition Classes
    Row → AnyRef → Any
  34. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  35. def isNullAt(i: Int): Boolean

    Checks whether the value at position i is null.

  36. def json: String

    The compact JSON representation of this row.

    The compact JSON representation of this row.

    Annotations
    @Unstable()
    Since

    3.0

  37. def mkString(start: String, sep: String, end: String): String

    Displays all elements of this traversable or iterator in a string using start, end, and separator strings.

  38. def mkString(sep: String): String

    Displays all elements of this sequence in a string using a separator string.

  39. def mkString: String

    Displays all elements of this sequence in a string (without a separator).

  40. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  41. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  42. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  43. def prettyJson: String

    The pretty (i.e.

    The pretty (i.e. indented) JSON representation of this row.

    Annotations
    @Unstable()
    Since

    3.0

  44. def schema: StructType

    Schema for the row.

  45. def size: Int

    Number of elements in the Row.

  46. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  47. def toSeq: Seq[Any]

    Return a Scala Seq representing the row.

    Return a Scala Seq representing the row. Elements are placed in the same order in the Seq.

  48. def toString(): String
    Definition Classes
    Row → AnyRef → Any
  49. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  50. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  51. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped