Skip to content

Commit 4ee75e9

Browse files
committed
add test
1 parent ad8c9ef commit 4ee75e9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ case class GetExternalRowField(
729729
val row = child.gen(ctx)
730730

731731
val getField = dataType match {
732-
case ObjectType(x) if x == classOf[Row] => s"""$row.getStruct($index)"""
733-
case _ => s"""(${ctx.boxedType(dataType)}) $row.get($index)"""
732+
case ObjectType(x) if x == classOf[Row] => s"""${row.value}.getStruct($index)"""
733+
case _ => s"""(${ctx.boxedType(dataType)}) ${row.value}.get($index)"""
734734
}
735735

736736
ev.isNull = "false"

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.sql.{Date, Timestamp}
2222

2323
import scala.language.postfixOps
2424

25-
import org.apache.spark.sql.catalyst.encoders.OuterScopes
25+
import org.apache.spark.sql.catalyst.encoders.{OuterScopes, RowEncoder}
2626
import org.apache.spark.sql.execution.streaming.MemoryStream
2727
import org.apache.spark.sql.functions._
2828
import org.apache.spark.sql.test.SharedSQLContext
@@ -626,6 +626,22 @@ class DatasetSuite extends QueryTest with SharedSQLContext {
626626
// Make sure the generated code for this plan can compile and execute.
627627
checkDataset(wideDF.map(_.getLong(0)), 0L until 10 : _*)
628628
}
629+
630+
test("runtime null check for RowEncoder") {
631+
val schema = new StructType().add("i", IntegerType, nullable = false)
632+
val df = sqlContext.range(10).map(l => {
633+
if (l % 5 == 0) {
634+
Row(null)
635+
} else {
636+
Row(l)
637+
}
638+
})(RowEncoder(schema))
639+
640+
val message = intercept[Exception] {
641+
df.collect()
642+
}.getMessage
643+
assert(message.contains("Runtime null check failed"))
644+
}
629645
}
630646

631647
case class OtherTuple(_1: String, _2: Int)

0 commit comments

Comments
 (0)