Skip to content

Commit ec6aa50

Browse files
committed
initial commit
1 parent ee36bc1 commit ec6aa50

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ case class BoundReference(ordinal: Int, dataType: DataType, nullable: Boolean)
6363
val value = ctx.getValue(ctx.INPUT_ROW, dataType, ordinal.toString)
6464
if (ctx.currentVars != null && ctx.currentVars(ordinal) != null) {
6565
val oev = ctx.currentVars(ordinal)
66-
ev.isNull = oev.isNull
66+
ev.isNull = if (!nullable || ctx.INPUT_ROW == null) {
67+
oev.isNull
68+
} else {
69+
s"((${oev.isNull}) || ${ctx.INPUT_ROW}.isNullAt($ordinal))"
70+
}
6771
ev.value = oev.value
6872
val code = oev.code
6973
oev.code = ""

sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,4 +1722,15 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
17221722
"Cannot have map type columns in DataFrame which calls set operations"))
17231723
}
17241724
}
1725+
1726+
test("SPARK-19959: df[java.lang.Long].collect includes null throws NullPointerException") {
1727+
val dfInt = sparkContext.parallelize(Seq[java.lang.Integer](0, null, 2), 1).toDF
1728+
assert(dfInt.collect === Array(Row(0), Row(null), Row(2)))
1729+
val dfLong = sparkContext.parallelize(Seq[java.lang.Long](0L, null, 2L), 1).toDF
1730+
assert(dfLong.collect === Array(Row(0L), Row(null), Row(2L)))
1731+
val dfFloat = sparkContext.parallelize(Seq[java.lang.Float](0.0F, null, 2.0F), 1).toDF
1732+
assert(dfFloat.collect === Array(Row(0.0F), Row(null), Row(2.0F)))
1733+
val dfDouble = sparkContext.parallelize(Seq[java.lang.Double](0.0D, null, 2.0D), 1).toDF
1734+
assert(dfDouble.collect === Array(Row(0.0D), Row(null), Row(2.0D)))
1735+
}
17251736
}

0 commit comments

Comments
 (0)