-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[MINOR][DOCS] The default fractional numeric literal in SQL is a decimal #45003
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
Conversation
|
Merged to master. |
| * **default (no postfix)** | ||
| Indicates `DECIMAL`, same as the `BD` postfix. |
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.
exponential w/o postfix, such as 1.2E3, is a double by default
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.
Ah, ok. I can make another PR to clarify this point, unless you prefer to do it yourself.
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.
Ohh actually let me revert this first. Let's make the proper fix together.
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.
Sure, if you prefer to do that. I will make a new PR to clarify the default type with and without the exponent.
### What changes were proposed in this pull request? Provide examples showing what type literals like `123.456` and `123.456E0` have in SQL. ### Why are the changes needed? In Python (and I think Java too) fractional numeric literals are typically floats. To get decimals, you need to provide an explicit postfix or use an explicit class. In Spark, it's the other way around. I found this surprising and couldn't find documentation about it. I discovered this after reading [SPARK-45786](https://issues.apache.org/jira/browse/SPARK-45786). I did a little searching and came across #10796, which shows that we used to default to floats as the fractional numeric literal, but then switched to decimals. There is an additional wrinkle I discovered in #45003. If the fractional literal has an exponent, then it's a double, not a decimal. The existing syntax documents this, but that alone is not user-friendly. The new examples make this clearer. ### Does this PR introduce _any_ user-facing change? Yes, it clarifies the user-facing documentation about fractional numeric literals. ### How was this patch tested? No testing. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #45027 from nchammas/fractional-literal-take2. Authored-by: Nicholas Chammas <[email protected]> Signed-off-by: Kent Yao <[email protected]>
What changes were proposed in this pull request?
Explain that a number like
123.456, without a postfix but with a decimal point, is a decimal literal.Why are the changes needed?
In Python (and I think Java too) fractional numeric literals are typically floats. To get decimals, you need to provide an explicit postfix or use an explicit class.
In Spark, it's the other way around. I found this surprising and couldn't find documentation about it.
I discovered this after reading SPARK-45786. I did a little searching and came across #10796, which shows that we used to default to floats as the fractional numeric literal, but then switched to decimals.
Does this PR introduce any user-facing change?
Yes, it adds a bit of documentation.
How was this patch tested?
No testing.
Was this patch authored or co-authored using generative AI tooling?
No.