Skip to content

Commit

Permalink
[SPARK-10190] Fix NPE in CatalystTypeConverters Decimal toScala conve…
Browse files Browse the repository at this point in the history
…rter

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.

(cherry picked from commit d7b4c09)
Signed-off-by: Reynold Xin <rxin@databricks.com>
  • Loading branch information
JoshRosen authored and rxin committed Aug 24, 2015
1 parent aadb9de commit a4bad5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ object CatalystTypeConverters {
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 =
row.getDecimal(column, dataType.precision, dataType.scale).toJavaBigDecimal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class CatalystTypeConvertersSuite extends SparkFunSuite {
IntegerType,
LongType,
FloatType,
DoubleType)
DoubleType,
DecimalType.SYSTEM_DEFAULT,
DecimalType.USER_DEFAULT)

test("null handling in rows") {
val schema = StructType(simpleTypes.map(t => StructField(t.getClass.getName, t)))
Expand Down

0 comments on commit a4bad5f

Please sign in to comment.