Skip to content
Snippets Groups Projects
Commit c110614b authored by Cheng Lian's avatar Cheng Lian Committed by Michael Armbrust
Browse files

[SPARK-3448][SQL] Check for null in SpecificMutableRow.update

`SpecificMutableRow.update` doesn't check for null, and breaks existing `MutableRow` contract.

The tricky part here is that for performance considerations, the `update` method of all subclasses of `MutableValue` doesn't check for null and sets the null bit to false.

Author: Cheng Lian <lian.cs.zju@gmail.com>

Closes #2325 from liancheng/check-for-null and squashes the following commits:

9366c44 [Cheng Lian] Check for null in SpecificMutableRow.update
parent 07ee4a28
No related branches found
No related tags found
No related merge requests found
...@@ -227,7 +227,9 @@ final class SpecificMutableRow(val values: Array[MutableValue]) extends MutableR ...@@ -227,7 +227,9 @@ final class SpecificMutableRow(val values: Array[MutableValue]) extends MutableR
new SpecificMutableRow(newValues) new SpecificMutableRow(newValues)
} }
override def update(ordinal: Int, value: Any): Unit = values(ordinal).update(value) override def update(ordinal: Int, value: Any): Unit = {
if (value == null) setNullAt(ordinal) else values(ordinal).update(value)
}
override def iterator: Iterator[Any] = values.map(_.boxed).iterator override def iterator: Iterator[Any] = values.map(_.boxed).iterator
......
...@@ -19,7 +19,7 @@ package org.apache.spark.sql ...@@ -19,7 +19,7 @@ package org.apache.spark.sql
import org.scalatest.FunSuite import org.scalatest.FunSuite
import org.apache.spark.sql.catalyst.expressions.GenericMutableRow import org.apache.spark.sql.catalyst.expressions.{GenericMutableRow, SpecificMutableRow}
class RowSuite extends FunSuite { class RowSuite extends FunSuite {
...@@ -43,4 +43,10 @@ class RowSuite extends FunSuite { ...@@ -43,4 +43,10 @@ class RowSuite extends FunSuite {
assert(expected.getBoolean(2) === actual2.getBoolean(2)) assert(expected.getBoolean(2) === actual2.getBoolean(2))
assert(expected(3) === actual2(3)) assert(expected(3) === actual2(3))
} }
test("SpecificMutableRow.update with null") {
val row = new SpecificMutableRow(Seq(IntegerType))
row(0) = null
assert(row.isNullAt(0))
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment