Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ trait Row extends Serializable {
*
* @throws ClassCastException when data type does not match.
*/
def getSeq[T](i: Int): Seq[T] = getAs[scala.collection.Seq[T]](i).toSeq
def getSeq[T](i: Int): Seq[T] = {
val res = getAs[scala.collection.Seq[T]](i)
if (res != null) res.toSeq else null
}

/**
* Returns the value at position i of array type as `java.util.List`.
Expand Down
6 changes: 6 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ class RowSuite extends SparkFunSuite with SharedSparkSession {
val empty = Row()
assert(empty.toString == "[]")
}

test("SPARK-37654: row contains a null at the requested index should return null") {
assert(Row(Seq("value")).getSeq(0) === List("value"))
assert(Row(Seq()).getSeq(0) === List())
assert(Row(null).getSeq(0) === null)
}
}