Skip to content
Snippets Groups Projects
Commit d7b4c095 authored by Josh Rosen's avatar Josh Rosen Committed by Reynold Xin
Browse files

[SPARK-10190] Fix NPE in CatalystTypeConverters Decimal toScala converter

This adds a missing null check to the Decimal `toScala` converter in `CatalystTypeConverters`, fixing an NPE.

Author: Josh Rosen <joshrosen@databricks.com>

Closes #8401 from JoshRosen/SPARK-10190.
parent 13db11cb
No related branches found
No related tags found
No related merge requests found
...@@ -329,7 +329,10 @@ object CatalystTypeConverters { ...@@ -329,7 +329,10 @@ object CatalystTypeConverters {
null null
} }
} }
override def toScala(catalystValue: Decimal): JavaBigDecimal = catalystValue.toJavaBigDecimal override def toScala(catalystValue: Decimal): JavaBigDecimal = {
if (catalystValue == null) null
else catalystValue.toJavaBigDecimal
}
override def toScalaImpl(row: InternalRow, column: Int): JavaBigDecimal = override def toScalaImpl(row: InternalRow, column: Int): JavaBigDecimal =
row.getDecimal(column, dataType.precision, dataType.scale).toJavaBigDecimal row.getDecimal(column, dataType.precision, dataType.scale).toJavaBigDecimal
} }
......
...@@ -32,7 +32,9 @@ class CatalystTypeConvertersSuite extends SparkFunSuite { ...@@ -32,7 +32,9 @@ class CatalystTypeConvertersSuite extends SparkFunSuite {
IntegerType, IntegerType,
LongType, LongType,
FloatType, FloatType,
DoubleType) DoubleType,
DecimalType.SYSTEM_DEFAULT,
DecimalType.USER_DEFAULT)
test("null handling in rows") { test("null handling in rows") {
val schema = StructType(simpleTypes.map(t => StructField(t.getClass.getName, t))) val schema = StructType(simpleTypes.map(t => StructField(t.getClass.getName, t)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment