diff options
author | Liang-Chi Hsieh <viirya@gmail.com> | 2014-12-01 13:17:56 -0800 |
---|---|---|
committer | Michael Armbrust <michael@databricks.com> | 2014-12-01 13:18:59 -0800 |
commit | f2bb90a29defab0b9c8ad795c0cb786de275145b (patch) | |
tree | a4271054c805981428c5c09618028eeff0a4b9fc | |
parent | e0a6d36bc96df63fb8cc5c3b4e516ef1011849ef (diff) | |
download | spark-f2bb90a29defab0b9c8ad795c0cb786de275145b.tar.gz spark-f2bb90a29defab0b9c8ad795c0cb786de275145b.tar.bz2 spark-f2bb90a29defab0b9c8ad795c0cb786de275145b.zip |
[SPARK-4358][SQL] Let BigDecimal do checking type compatibility
Remove hardcoding max and min values for types. Let BigDecimal do checking type compatibility.
Author: Liang-Chi Hsieh <viirya@gmail.com>
Closes #3208 from viirya/more_numericLit and squashes the following commits:
e9834b4 [Liang-Chi Hsieh] Remove byte and short types for number literal.
1bd1825 [Liang-Chi Hsieh] Fix Indentation and make the modification clearer.
cf1a997 [Liang-Chi Hsieh] Modified for comment to add a rule of analysis that adds a cast.
91fe489 [Liang-Chi Hsieh] add Byte and Short.
1bdc69d [Liang-Chi Hsieh] Let BigDecimal do checking type compatibility.
(cherry picked from commit b57365a1ec89e31470f424ff37d5ebc7c90a39d8)
Signed-off-by: Michael Armbrust <michael@databricks.com>
-rwxr-xr-x | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala index dc1d349f10..a9ff10f2d5 100755 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala @@ -340,18 +340,13 @@ class SqlParser extends AbstractSparkSQLParser { | floatLit ^^ { f => Literal(f.toDouble) } ) - private val longMax = BigDecimal(s"${Long.MaxValue}") - private val longMin = BigDecimal(s"${Long.MinValue}") - private val intMax = BigDecimal(s"${Int.MaxValue}") - private val intMin = BigDecimal(s"${Int.MinValue}") - private def toNarrowestIntegerType(value: String) = { val bigIntValue = BigDecimal(value) bigIntValue match { - case v if v < longMin || v > longMax => v - case v if v < intMin || v > intMax => v.toLong - case v => v.toInt + case v if bigIntValue.isValidInt => v.toIntExact + case v if bigIntValue.isValidLong => v.toLongExact + case v => v } } |