aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/test
diff options
context:
space:
mode:
authorHerman van Hovell <hvanhovell@databricks.com>2016-08-26 13:29:22 -0700
committerReynold Xin <rxin@databricks.com>2016-08-26 13:29:22 -0700
commita11d10f1826b578ff721c4738224eef2b3c3b9f3 (patch)
treef8d4bf7abf2dda4b78655db707eb4d4b8624196a /sql/catalyst/src/test
parent8e5475be3c9a620f18f6712631b093464a7d0ee7 (diff)
downloadspark-a11d10f1826b578ff721c4738224eef2b3c3b9f3.tar.gz
spark-a11d10f1826b578ff721c4738224eef2b3c3b9f3.tar.bz2
spark-a11d10f1826b578ff721c4738224eef2b3c3b9f3.zip
[SPARK-17246][SQL] Add BigDecimal literal
## What changes were proposed in this pull request? This PR adds parser support for `BigDecimal` literals. If you append the suffix `BD` to a valid number then this will be interpreted as a `BigDecimal`, for example `12.0E10BD` will interpreted into a BigDecimal with scale -9 and precision 3. This is useful in situations where you need exact values. ## How was this patch tested? Added tests to `ExpressionParserSuite`, `ExpressionSQLBuilderSuite` and `SQLQueryTestSuite`. Author: Herman van Hovell <hvanhovell@databricks.com> Closes #14819 from hvanhovell/SPARK-17246.
Diffstat (limited to 'sql/catalyst/src/test')
-rw-r--r--sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala7
1 files changed, 7 insertions, 0 deletions
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala
index 401d9cd9d2..dbc5db39ae 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala
@@ -392,6 +392,13 @@ class ExpressionParserSuite extends PlanTest {
intercept("1.8E308D", s"does not fit in range")
// TODO we need to figure out if we should throw an exception here!
assertEqual("1E309", Literal(Double.PositiveInfinity))
+
+ // BigDecimal Literal
+ assertEqual("90912830918230182310293801923652346786BD",
+ Literal(BigDecimal("90912830918230182310293801923652346786").underlying()))
+ assertEqual("123.0E-28BD", Literal(BigDecimal("123.0E-28").underlying()))
+ assertEqual("123.08BD", Literal(BigDecimal("123.08").underlying()))
+ intercept("1.20E-38BD", "DecimalType can only support precision up to 38")
}
test("strings") {