Interface Row
- All Superinterfaces:
- Serializable
- All Known Implementing Classes:
- MutableAggregationBuffer
 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
 }
 - Since:
- 1.3.0
- 
Method SummaryModifier and TypeMethodDescriptionbooleananyNull()Returns true if there are any NULL values in this row.apply(int i) Returns the value at position i.copy()Make a copy of the currentRowobject.booleanintfieldIndex(String name) Returns the index of a given field name.get(int i) Returns the value at position i.<T> TgetAnyValAs(int i) Returns the value at position i.<T> TgetAs(int i) Returns the value at position i.<T> TReturns the value of a given fieldName.booleangetBoolean(int i) Returns the value at position i as a primitive boolean.bytegetByte(int i) Returns the value at position i as a primitive byte.getDate(int i) Returns the value at position i of date type as java.sql.Date.getDecimal(int i) Returns the value at position i of decimal type as java.math.BigDecimal.doublegetDouble(int i) Returns the value at position i as a primitive double.floatgetFloat(int i) Returns the value at position i as a primitive float.getInstant(int i) Returns the value at position i of date type as java.time.Instant.intgetInt(int i) Returns the value at position i as a primitive int.<K,V> Map<K, V> getJavaMap(int i) Returns the value at position i of array type as ajava.util.Map.<T> List<T>getList(int i) Returns the value at position i of array type asjava.util.List.getLocalDate(int i) Returns the value at position i of date type as java.time.LocalDate.longgetLong(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.immutable.Seq<T>getSeq(int i) Returns the value at position i of array type as a Scala Seq.shortgetShort(int i) Returns the value at position i as a primitive short.getString(int i) Returns the value at position i as a String object.getStruct(int i) Returns the value at position i of struct type as aRowobject.getTimestamp(int i) Returns the value at position i of date type as java.sql.Timestamp.<T> scala.collection.immutable.Map<String,T> getValuesMap(scala.collection.immutable.Seq<String> fieldNames) 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.inthashCode()booleanisNullAt(int i) Checks whether the value at position i is null.json()The compact JSON representation of this row.org.json4s.JValueJSON representation of the row.intlength()Number of elements in the Row.mkString()Displays all elements of this sequence in a string (without a separator).Displays all elements of this sequence in a string using a separator string.Displays all elements of this traversable or iterator in a string using start, end, and separator strings.The pretty (i.e.schema()Schema for the row.intsize()Number of elements in the Row.scala.collection.immutable.Seq<Object>toSeq()Return a Scala Seq representing the row.toString()
- 
Method Details- 
sizeint size()Number of elements in the Row.
- 
lengthint length()Number of elements in the Row.
- 
schemaStructType schema()Schema for the row.- Returns:
- (undocumented)
 
- 
applyReturns 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- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
 
- 
getReturns 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- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
 
- 
isNullAtboolean isNullAt(int i) Checks whether the value at position i is null.
- 
getBooleanboolean 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getBytebyte 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getShortshort 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getIntint 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getLonglong 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getFloatfloat 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getDoubledouble 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.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
getStringReturns the value at position i as a String object.- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- ClassCastException- when data type does not match.
 
- 
getDecimalReturns 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.
 
- 
getDateReturns 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.
 
- 
getLocalDateReturns the value at position i of date type as java.time.LocalDate.- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- ClassCastException- when data type does not match.
 
- 
getTimestampReturns the value at position i of date type as java.sql.Timestamp.- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- ClassCastException- when data type does not match.
 
- 
getInstantReturns the value at position i of date type as java.time.Instant.- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- ClassCastException- when data type does not match.
 
- 
getSeq<T> scala.collection.immutable.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.
 
- 
getListReturns the value at position i of array type asjava.util.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.
 
- 
getJavaMapReturns the value at position i of array type as ajava.util.Map.- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- ClassCastException- when data type does not match.
 
- 
getStructReturns the value at position i of struct type as aRowobject.- 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. 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- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- ClassCastException- when data type does not match.
 
- 
getAsReturns 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- 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.
 
- 
fieldIndexReturns the index of a given field name.- Parameters:
- name- (undocumented)
- Returns:
- (undocumented)
- Throws:
- UnsupportedOperationException- when schema is not defined.
- IllegalArgumentException- when a field- namedoes not exist.
 
- 
getValuesMap<T> scala.collection.immutable.Map<String,T> getValuesMap(scala.collection.immutable.Seq<String> fieldNames) 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- 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.
 
- 
toStringString toString()
- 
copyRow copy()Make a copy of the currentRowobject.- Returns:
- (undocumented)
 
- 
anyNullboolean anyNull()Returns true if there are any NULL values in this row.
- 
equals
- 
hashCodeint hashCode()
- 
toSeqscala.collection.immutable.Seq<Object> toSeq()Return a Scala Seq representing the row. Elements are placed in the same order in the Seq.- Returns:
- (undocumented)
 
- 
mkStringString mkString()Displays all elements of this sequence in a string (without a separator).
- 
mkStringDisplays all elements of this sequence in a string using a separator string.
- 
mkStringDisplays 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)
 
- 
getAnyValAs<T> T getAnyValAs(int i) Returns the value at position i.- Parameters:
- i- (undocumented)
- Returns:
- (undocumented)
- Throws:
- UnsupportedOperationException- when schema is not defined.
- ClassCastException- when data type does not match.
- org.apache.spark.SparkRuntimeException- when value is null.
 
- 
jsonString json()The compact JSON representation of this row.- Returns:
- (undocumented)
- Since:
- 3.0
 
- 
prettyJsonString prettyJson()The pretty (i.e. indented) JSON representation of this row.- Returns:
- (undocumented)
- Since:
- 3.0
 
- 
jsonValueorg.json4s.JValue jsonValue()JSON representation of the row.Note that this only supports the data types that are also supported by RowEncoder.- Returns:
- the JSON representation of the row.
 
 
-