[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.
This commit is contained in:
Takuya UESHIN 2014-05-15 11:21:33 -07:00 committed by Reynold Xin
parent db8cc6f28a
commit 94c9d6f598
2 changed files with 14 additions and 1 deletions

View file

@ -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 {

View file

@ -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") {