You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2014/05/15 20:21:36 UTC

git commit: [SPARK-1819] [SQL] Fix GetField.nullable.

Repository: spark
Updated Branches:
  refs/heads/master db8cc6f28 -> 94c9d6f59


[SPARK-1819] [SQL] Fix GetField.nullable.

`GetField.nullable` should be `true` not only when `field.nullable` is `true` but also when `child.nullable` is `true`.

Author: Takuya UESHIN <ue...@happy-camper.st>

Closes #757 from ueshin/issues/SPARK-1819 and squashes the following commits:

8781a11 [Takuya UESHIN] Modify a test to use named parameters.
5bfc77d [Takuya UESHIN] Fix GetField.nullable.


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

Branch: refs/heads/master
Commit: 94c9d6f59859ebc77fae112c2c42c64b7a4d7f83
Parents: db8cc6f
Author: Takuya UESHIN <ue...@happy-camper.st>
Authored: Thu May 15 11:21:33 2014 -0700
Committer: Reynold Xin <rx...@apache.org>
Committed: Thu May 15 11:21:33 2014 -0700

----------------------------------------------------------------------
 .../spark/sql/catalyst/expressions/complexTypes.scala  |  2 +-
 .../expressions/ExpressionEvaluationSuite.scala        | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/94c9d6f5/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala
index 195ca2e..b6aeae9 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala
@@ -74,7 +74,7 @@ case class GetField(child: Expression, fieldName: String) extends UnaryExpressio
   type EvaluatedType = Any
 
   def dataType = field.dataType
-  override def nullable = field.nullable
+  override def nullable = child.nullable || field.nullable
   override def foldable = child.foldable
 
   protected def structType = child.dataType match {

http://git-wip-us.apache.org/repos/asf/spark/blob/94c9d6f5/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
index 344d8a3..1132a30 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala
@@ -364,6 +364,19 @@ class ExpressionEvaluationSuite extends FunSuite {
 
     checkEvaluation(GetField(BoundReference(2, AttributeReference("c", typeS)()), "a"), "aa", row)
     checkEvaluation(GetField(Literal(null, typeS), "a"), null, row)
+
+    val typeS_notNullable = StructType(
+      StructField("a", StringType, nullable = false)
+        :: StructField("b", StringType, nullable = false) :: Nil
+    )
+
+    assert(GetField(BoundReference(2,
+      AttributeReference("c", typeS)()), "a").nullable === true)
+    assert(GetField(BoundReference(2,
+      AttributeReference("c", typeS_notNullable, nullable = false)()), "a").nullable === false)
+
+    assert(GetField(Literal(null, typeS), "a").nullable === true)
+    assert(GetField(Literal(null, typeS_notNullable), "a").nullable === true)
   }
 
   test("arithmetic") {