org.apache.spark.sql
Interface Row

All Superinterfaces:
java.io.Serializable

public interface Row
extends scala.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
 }
 


Method Summary
 boolean anyNull()
          Returns true if there are any NULL values in this row.
 Object apply(int i)
          Returns the value at position i.
 Row copy()
          Make a copy of the current Row object.
 boolean equals(Object that)
           
 int fieldIndex(String name)
          Returns the index of a given field name.
 Object get(int i)
          Returns the value at position i.
<T> T
getAs(int i)
          Returns the value at position i.
<T> T
getAs(String fieldName)
          Returns the value of a given fieldName.
 boolean getBoolean(int i)
          Returns the value at position i as a primitive boolean.
 byte getByte(int i)
          Returns the value at position i as a primitive byte.
 java.sql.Date getDate(int i)
          Returns the value at position i of date type as java.sql.Date.
 java.math.BigDecimal getDecimal(int i)
          Returns the value at position i of decimal type as java.math.BigDecimal.
 double getDouble(int i)
          Returns the value at position i as a primitive double.
 float getFloat(int i)
          Returns the value at position i as a primitive float.
 int getInt(int i)
          Returns the value at position i as a primitive int.
<K,V> java.util.Map<K,V>
getJavaMap(int i)
          Returns the value at position i of array type as a Map.
<T> java.util.List<T>
getList(int i)
          Returns the value at position i of array type as List.
 long getLong(int i)
          Returns the value at position i as a primitive long.
<K,V> scala.collection.Map<K,V>
getMap(int i)
          Returns the value at position i of map type as a Scala Map.
<T> scala.collection.Seq<T>
getSeq(int i)
          Returns the value at position i of array type as a Scala Seq.
 short getShort(int i)
          Returns the value at position i as a primitive short.
 String getString(int i)
          Returns the value at position i as a String object.
 Row getStruct(int i)
          Returns the value at position i of struct type as an Row object.
<T> scala.collection.immutable.Map<String,T>
getValuesMap(scala.collection.Seq<String> fieldNames)
          Returns a Map(name -> value) for the requested fieldNames
 int hashCode()
           
 boolean isNullAt(int i)
          Checks whether the value at position i is null.
 int length()
          Number of elements in the Row.
 String mkString()
          Displays all elements of this sequence in a string (without a separator).
 String mkString(String sep)
          Displays all elements of this sequence in a string using a separator string.
 String mkString(String start, String sep, String end)
          Displays all elements of this traversable or iterator in a string using start, end, and separator strings.
 StructType schema()
          Schema for the row.
 int size()
          Number of elements in the Row.
 scala.collection.Seq<Object> toSeq()
          Return a Scala Seq representing the row.
 String toString()
           
 

Method Detail

size

int size()
Number of elements in the Row.


length

int length()
Number of elements in the Row.


schema

StructType schema()
Schema for the row.

Returns:
(undocumented)

apply

Object apply(int 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
   FloatType -> java.lang.Float
   DoubleType -> java.lang.Double
   StringType -> String
   DecimalType -> java.math.BigDecimal

   DateType -> java.sql.Date
   TimestampType -> java.sql.Timestamp

   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
 

Parameters:
i - (undocumented)
Returns:
(undocumented)

get

Object get(int 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
   FloatType -> java.lang.Float
   DoubleType -> java.lang.Double
   StringType -> String
   DecimalType -> java.math.BigDecimal

   DateType -> java.sql.Date
   TimestampType -> java.sql.Timestamp

   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
 

Parameters:
i - (undocumented)
Returns:
(undocumented)

isNullAt

boolean isNullAt(int i)
Checks whether the value at position i is null.


getBoolean

boolean getBoolean(int i)
Returns the value at position i as a primitive boolean.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getByte

byte getByte(int i)
Returns the value at position i as a primitive byte.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getShort

short getShort(int i)
Returns the value at position i as a primitive short.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getInt

int getInt(int i)
Returns the value at position i as a primitive int.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getLong

long getLong(int i)
Returns the value at position i as a primitive long.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getFloat

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

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getDouble

double getDouble(int i)
Returns the value at position i as a primitive double.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getString

String getString(int i)
Returns the value at position i as a String object.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.
NullPointerException - when value is null.

getDecimal

java.math.BigDecimal getDecimal(int i)
Returns the value at position i of decimal type as java.math.BigDecimal.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getDate

java.sql.Date getDate(int i)
Returns the value at position i of date type as java.sql.Date.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getSeq

<T> scala.collection.Seq<T> getSeq(int i)
Returns the value at position i of array type as a Scala Seq.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getList

<T> java.util.List<T> getList(int i)
Returns the value at position i of array type as List.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getMap

<K,V> scala.collection.Map<K,V> getMap(int i)
Returns the value at position i of map type as a Scala Map.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getJavaMap

<K,V> java.util.Map<K,V> getJavaMap(int i)
Returns the value at position i of array type as a Map.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getStruct

Row getStruct(int i)
Returns the value at position i of struct type as an Row object.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getAs

<T> T getAs(int i)
Returns the value at position i.

Parameters:
i - (undocumented)
Returns:
(undocumented)
Throws:
ClassCastException - when data type does not match.

getAs

<T> T getAs(String fieldName)
Returns the value of a given fieldName.

Parameters:
fieldName - (undocumented)
Returns:
(undocumented)
Throws:
UnsupportedOperationException - when schema is not defined.
IllegalArgumentException - when fieldName do not exist.
ClassCastException - when data type does not match.

fieldIndex

int fieldIndex(String name)
Returns the index of a given field name.

Parameters:
name - (undocumented)
Returns:
(undocumented)
Throws:
UnsupportedOperationException - when schema is not defined.
IllegalArgumentException - when fieldName do not exist.

getValuesMap

<T> scala.collection.immutable.Map<String,T> getValuesMap(scala.collection.Seq<String> fieldNames)
Returns a Map(name -> value) for the requested fieldNames

Parameters:
fieldNames - (undocumented)
Returns:
(undocumented)
Throws:
UnsupportedOperationException - when schema is not defined.
IllegalArgumentException - when fieldName do not exist.
ClassCastException - when data type does not match.

toString

String toString()
Overrides:
toString in class Object

copy

Row copy()
Make a copy of the current Row object.

Returns:
(undocumented)

anyNull

boolean anyNull()
Returns true if there are any NULL values in this row.


equals

boolean equals(Object that)
Overrides:
equals in class Object

hashCode

int hashCode()
Overrides:
hashCode in class Object

toSeq

scala.collection.Seq<Object> toSeq()
Return a Scala Seq representing the row. ELements are placed in the same order in the Seq.

Returns:
(undocumented)

mkString

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


mkString

String mkString(String sep)
Displays all elements of this sequence in a string using a separator string.


mkString

String mkString(String start,
                String sep,
                String end)
Displays all elements of this traversable or iterator in a string using start, end, and separator strings.

Parameters:
start - (undocumented)
sep - (undocumented)
end - (undocumented)
Returns:
(undocumented)