From 7ced9b05a603f80f709a567f3abdc07ed0a60f9b Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Thu, 4 Jun 2015 23:54:49 +0800 Subject: [PATCH] Use java.math.BigDecimal for casting String to Decimal instead of using toDouble. --- .../scala/org/apache/spark/sql/catalyst/expressions/Cast.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala index 21adac144112e..10d9ffee407db 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala @@ -323,7 +323,7 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w private[this] def castToDecimal(from: DataType, target: DecimalType): Any => Any = from match { case StringType => buildCast[UTF8String](_, s => try { - changePrecision(Decimal(s.toString.toDouble), target) + changePrecision(Decimal(new java.math.BigDecimal(s.toString)), target) } catch { case _: NumberFormatException => null })