aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorTakuya UESHIN <ueshin@happy-camper.st>2014-05-15 11:21:33 -0700
committerReynold Xin <rxin@apache.org>2014-05-15 11:21:33 -0700
commit94c9d6f59859ebc77fae112c2c42c64b7a4d7f83 (patch)
treede9e8daff750d79f0591ed363651e1514138ad12 /sql
parentdb8cc6f28abe4326cea6f53feb604920e4867a27 (diff)
downloadspark-94c9d6f59859ebc77fae112c2c42c64b7a4d7f83.tar.gz
spark-94c9d6f59859ebc77fae112c2c42c64b7a4d7f83.tar.bz2
spark-94c9d6f59859ebc77fae112c2c42c64b7a4d7f83.zip
[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 <ueshin@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.
Diffstat (limited to 'sql')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala2
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala13
2 files changed, 14 insertions, 1 deletions
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 195ca2eb3d..b6aeae92f8 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 {
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 344d8a304f..1132a30b42 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") {