Skip to content
Snippets Groups Projects
Commit b57365a1 authored by Liang-Chi Hsieh's avatar Liang-Chi Hsieh Committed by Michael Armbrust
Browse files

[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.
parent bafee67e
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment