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:17:56 -0800 |
commit | b57365a1ec89e31470f424ff37d5ebc7c90a39d8 (patch) | |
tree | faaff2ef76bca90967c7df86314aea2833c345d9 /sql | |
parent | bafee67ebad01f7aea2cd393a70b57eb8345eeb0 (diff) | |
download | spark-b57365a1ec89e31470f424ff37d5ebc7c90a39d8.tar.gz spark-b57365a1ec89e31470f424ff37d5ebc7c90a39d8.tar.bz2 spark-b57365a1ec89e31470f424ff37d5ebc7c90a39d8.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.
Diffstat (limited to 'sql')
-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 } } |