aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src
diff options
context:
space:
mode:
authorpetermaxlee <petermaxlee@gmail.com>2016-08-11 23:56:55 -0700
committerReynold Xin <rxin@databricks.com>2016-08-11 23:56:55 -0700
commit00e103a6edd1a1f001a94d41dd1f7acc40a1e30f (patch)
treef20e1036827e7fceb8b512278ad7b1af1f807eb1 /sql/catalyst/src
parentabff92bfdc7d4c9d2308794f0350561fe0ceb4dd (diff)
downloadspark-00e103a6edd1a1f001a94d41dd1f7acc40a1e30f.tar.gz
spark-00e103a6edd1a1f001a94d41dd1f7acc40a1e30f.tar.bz2
spark-00e103a6edd1a1f001a94d41dd1f7acc40a1e30f.zip
[SPARK-17013][SQL] Parse negative numeric literals
## What changes were proposed in this pull request? This patch updates the SQL parser to parse negative numeric literals as numeric literals, instead of unary minus of positive literals. This allows the parser to parse the minimal value for each data type, e.g. "-32768S". ## How was this patch tested? Updated test cases. Author: petermaxlee <petermaxlee@gmail.com> Closes #14608 from petermaxlee/SPARK-17013.
Diffstat (limited to 'sql/catalyst/src')
-rw-r--r--sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g414
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala4
2 files changed, 9 insertions, 9 deletions
diff --git a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
index ba65f2a889..6122bcdef8 100644
--- a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
+++ b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
@@ -625,13 +625,13 @@ quotedIdentifier
;
number
- : DECIMAL_VALUE #decimalLiteral
- | SCIENTIFIC_DECIMAL_VALUE #scientificDecimalLiteral
- | INTEGER_VALUE #integerLiteral
- | BIGINT_LITERAL #bigIntLiteral
- | SMALLINT_LITERAL #smallIntLiteral
- | TINYINT_LITERAL #tinyIntLiteral
- | DOUBLE_LITERAL #doubleLiteral
+ : MINUS? DECIMAL_VALUE #decimalLiteral
+ | MINUS? SCIENTIFIC_DECIMAL_VALUE #scientificDecimalLiteral
+ | MINUS? INTEGER_VALUE #integerLiteral
+ | MINUS? BIGINT_LITERAL #bigIntLiteral
+ | MINUS? SMALLINT_LITERAL #smallIntLiteral
+ | MINUS? TINYINT_LITERAL #tinyIntLiteral
+ | MINUS? DOUBLE_LITERAL #doubleLiteral
;
nonReserved
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
index 4aebef92b9..13e539a223 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
@@ -58,7 +58,7 @@ case class UnaryMinus(child: Expression) extends UnaryExpression
}
}
- override def sql: String = s"(-${child.sql})"
+ override def sql: String = s"(- ${child.sql})"
}
@ExpressionDescription(
@@ -76,7 +76,7 @@ case class UnaryPositive(child: Expression)
protected override def nullSafeEval(input: Any): Any = input
- override def sql: String = s"(+${child.sql})"
+ override def sql: String = s"(+ ${child.sql})"
}
/**