Skip to content

Conversation

@nchammas
Copy link
Contributor

@nchammas nchammas commented Feb 2, 2024

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.

@github-actions github-actions bot added the DOCS label Feb 2, 2024
@nchammas nchammas changed the title [MINOR][DOCS] Explain that the default fractional numeric literal is a decimal [MINOR][DOCS] Explain that the default fractional numeric literal in SQL is a decimal Feb 2, 2024
@nchammas nchammas changed the title [MINOR][DOCS] Explain that the default fractional numeric literal in SQL is a decimal [MINOR][DOCS] The default fractional numeric literal in SQL is a decimal Feb 2, 2024
@HyukjinKwon
Copy link
Member

Merged to master.

@nchammas nchammas deleted the decimal-literal branch February 5, 2024 06:41
* **default (no postfix)**
Indicates `DECIMAL`, same as the `BD` postfix.
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

yaooqinn pushed a commit that referenced this pull request Feb 6, 2024
### 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants