You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2015/06/14 01:40:31 UTC
spark git commit: [SPARK-8052] [SQL] Use java.math.BigDecimal for
casting String to Decimal instead of using toDouble
Repository: spark
Updated Branches:
refs/heads/master af31335ad -> ddec45279
[SPARK-8052] [SQL] Use java.math.BigDecimal for casting String to Decimal instead of using toDouble
JIRA: https://issues.apache.org/jira/browse/SPARK-8052
Author: Liang-Chi Hsieh <vi...@gmail.com>
Closes #6645 from viirya/cast_string_integraltype and squashes the following commits:
e19c6a3 [Liang-Chi Hsieh] For comment.
c3e472a [Liang-Chi Hsieh] Add test.
7ced9b0 [Liang-Chi Hsieh] Use java.math.BigDecimal for casting String to Decimal instead of using toDouble.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/ddec4527
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/ddec4527
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/ddec4527
Branch: refs/heads/master
Commit: ddec45279ed1061f4c05fd0760309a53581d03f5
Parents: af31335
Author: Liang-Chi Hsieh <vi...@gmail.com>
Authored: Sat Jun 13 16:39:52 2015 -0700
Committer: Michael Armbrust <mi...@databricks.com>
Committed: Sat Jun 13 16:39:52 2015 -0700
----------------------------------------------------------------------
.../scala/org/apache/spark/sql/catalyst/expressions/Cast.scala | 3 ++-
.../org/apache/spark/sql/hive/execution/SQLQuerySuite.scala | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/ddec4527/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
----------------------------------------------------------------------
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 05a04bd..b20086b 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
@@ -17,6 +17,7 @@
package org.apache.spark.sql.catalyst.expressions
+import java.math.{BigDecimal => JavaBigDecimal}
import java.sql.{Date, Timestamp}
import java.text.{DateFormat, SimpleDateFormat}
@@ -320,7 +321,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 JavaBigDecimal(s.toString)), target)
} catch {
case _: NumberFormatException => null
})
http://git-wip-us.apache.org/repos/asf/spark/blob/ddec4527/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index c8e5e24..f890876 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -875,6 +875,10 @@ class SQLQuerySuite extends QueryTest {
}
}
+ test("Cast STRING to BIGINT") {
+ checkAnswer(sql("SELECT CAST('775983671874188101' as BIGINT)"), Row(775983671874188101L))
+ }
+
// `Math.exp(1.0)` has different result for different jdk version, so not use createQueryTest
test("udf_java_method") {
checkAnswer(sql(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org