-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-17013][SQL] handle corner case for negative integral literal #14599
Conversation
@cloud-fan I have a small patch that is a little bit more comprehensive (it makes it very consistent for all the data types). https://github.com/apache/spark/compare/master...petermaxlee:SPARK-17013?expand=1 I have no submitted it because it depends on #14598 |
@petermaxlee , your fix looks good, but should we make them consistent? I checked with postgres and mysql, they don't have the type suffix, e.g. |
That's a good question. I would expect this is not a "precedence" thing, but simply a numeric literal though, since there are no operators involved here. For example, in Scala (or Java), you can do I suspect this is actually a bug in Hive? |
cc @yhuai for the hive part. |
Test build #63601 has finished for PR 14599 at commit
|
@@ -627,6 +627,7 @@ quotedIdentifier | |||
number | |||
: DECIMAL_VALUE #decimalLiteral | |||
| SCIENTIFIC_DECIMAL_VALUE #scientificDecimalLiteral | |||
| MINUS INTEGER_VALUE #negativeIntegerLiteral | |||
| INTEGER_VALUE #integerLiteral |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add change this case into: MINUS? INTEGER_LITERAL #integerLiteral
. That also works and this would save quite a bit of code in the AstBuilder
.
The The fix that is proposed by @petermaxlee has a potential problem when we try parse something like This PR does not have this problem because it uses a parser rule, and we can set presence there by ordering the rules (the sequence in which they are defined). Here binary minus takes precedence over unary minus. We could add this rule for the other dataTypes, but that is IMO merely a matter of aesthetics. |
Thanks. How about this one? #14608 It takes the approach here but applies to all types for consistency. |
closing in favor of #14608 |
What changes were proposed in this pull request?
Spark 2.0 parses negative numeric literals as the unary minus of positive literals. This introduces problems for the edge cases such as -9223372036854775809 being parsed as decimal instead of bigint.
This PR fixes it by make negative integral a direct literal in parser.
How was this patch tested?
number-format.sql