From 80d70f0dc1855b00131c941bc28ce0aada395812 Mon Sep 17 00:00:00 2001 From: Kuba Tyszko Date: Fri, 16 Dec 2016 12:58:54 -0800 Subject: [PATCH] returns null when field is empty string on integer, long, and short column types --- .../sql/execution/datasources/csv/CSVInferSchema.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala index c63aae9d83855..526d9196c6803 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala @@ -246,9 +246,9 @@ private[csv] object CSVTypeCast { } else { castType match { case _: ByteType => datum.toByte - case _: ShortType => datum.toShort - case _: IntegerType => datum.toInt - case _: LongType => datum.toLong + case _: ShortType => Try(datum.toShort).getOrElse(null) + case _: IntegerType => Try(datum.toInt).getOrElse(null) + case _: LongType => Try(datum.toLong).getOrElse(null) case _: FloatType => datum match { case options.nanValue => Float.NaN