Skip to content

Commit 21e021b

Browse files
ueshinpdeyhim
authored andcommitted
[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 apache#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.
1 parent e598084 commit 21e021b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ case class GetField(child: Expression, fieldName: String) extends UnaryExpressio
7474
type EvaluatedType = Any
7575

7676
def dataType = field.dataType
77-
override def nullable = field.nullable
77+
override def nullable = child.nullable || field.nullable
7878
override def foldable = child.foldable
7979

8080
protected def structType = child.dataType match {

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ class ExpressionEvaluationSuite extends FunSuite {
364364

365365
checkEvaluation(GetField(BoundReference(2, AttributeReference("c", typeS)()), "a"), "aa", row)
366366
checkEvaluation(GetField(Literal(null, typeS), "a"), null, row)
367+
368+
val typeS_notNullable = StructType(
369+
StructField("a", StringType, nullable = false)
370+
:: StructField("b", StringType, nullable = false) :: Nil
371+
)
372+
373+
assert(GetField(BoundReference(2,
374+
AttributeReference("c", typeS)()), "a").nullable === true)
375+
assert(GetField(BoundReference(2,
376+
AttributeReference("c", typeS_notNullable, nullable = false)()), "a").nullable === false)
377+
378+
assert(GetField(Literal(null, typeS), "a").nullable === true)
379+
assert(GetField(Literal(null, typeS_notNullable), "a").nullable === true)
367380
}
368381

369382
test("arithmetic") {

0 commit comments

Comments
 (0)