You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2014/09/10 03:39:37 UTC

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

Repository: spark
Updated Branches:
  refs/heads/master 07ee4a28c -> c110614b3


[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 <li...@gmail.com>

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

9366c44 [Cheng Lian] Check for null in SpecificMutableRow.update


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/c110614b
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/c110614b
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/c110614b

Branch: refs/heads/master
Commit: c110614b33a690a3db6ccb1a920fb6a3795aa5a0
Parents: 07ee4a2
Author: Cheng Lian <li...@gmail.com>
Authored: Tue Sep 9 18:39:33 2014 -0700
Committer: Michael Armbrust <mi...@databricks.com>
Committed: Tue Sep 9 18:39:33 2014 -0700

----------------------------------------------------------------------
 .../apache/spark/sql/catalyst/expressions/SpecificRow.scala  | 4 +++-
 sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala  | 8 +++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/c110614b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SpecificRow.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SpecificRow.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SpecificRow.scala
index 75ea0e8..088f11e 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SpecificRow.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SpecificRow.scala
@@ -227,7 +227,9 @@ final class SpecificMutableRow(val values: Array[MutableValue]) extends MutableR
     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
 

http://git-wip-us.apache.org/repos/asf/spark/blob/c110614b/sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala
index 651cb73..811319e 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/RowSuite.scala
@@ -19,7 +19,7 @@ package org.apache.spark.sql
 
 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 {
 
@@ -43,4 +43,10 @@ class RowSuite extends FunSuite {
     assert(expected.getBoolean(2) === actual2.getBoolean(2))
     assert(expected(3) === actual2(3))
   }
+
+  test("SpecificMutableRow.update with null") {
+    val row = new SpecificMutableRow(Seq(IntegerType))
+    row(0) = null
+    assert(row.isNullAt(0))
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org