Skip to content

Commit 1ce01c7

Browse files
committed
Merge pull request apache#56 from liancheng/unapplySeqForRow
Added Row.unapplySeq to extract fields from a Row object.
2 parents 8d5da5e + 70e489d commit 1ce01c7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/package.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,19 @@ package object sql {
3131
protected[sql] type Logging = com.typesafe.scalalogging.slf4j.Logging
3232

3333
type Row = catalyst.expressions.Row
34+
35+
object Row {
36+
/**
37+
* This method can be used to extract fields from a [[Row]] object in a pattern match. Example:
38+
* {{{
39+
* import org.apache.spark.sql._
40+
*
41+
* val pairs = sql("SELECT key, value FROM src").rdd.map {
42+
* case Row(key: Int, value: String) =>
43+
* key -> value
44+
* }
45+
* }}}
46+
*/
47+
def unapplySeq(row: Row): Some[Seq[Any]] = Some(row)
48+
}
3449
}

0 commit comments

Comments
 (0)