pchintar opened a new pull request, #22697:
URL: https://github.com/apache/datafusion/pull/22697
## Which issue does this PR close?
- Closes #22696 .
## Rationale for this change
`round()` should not change integer values when the scale is non-negative,
since no fractional digits need to be rounded.
Currently, core `round()` coerces large `Int64` values through `Float64`,
causing precision loss:
```sql
SELECT round(arrow_cast(9007199254740993, 'Int64'));
````
Before/Current Buggy Output:
```text
9007199254740992.0
```
Expected:
```text
9007199254740993
```
The Spark-compatible `round()` also fails for `UInt64` values above
`i64::MAX` even when the scale is non-negative:
```sql
SELECT round(arrow_cast(18446744073709551615, 'UInt64'));
```
Before/Current Buggy Output:
```text
round: UInt64 value 18446744073709551615 exceeds i64::MAX and cannot be
rounded
```
## What changes are included in this PR?
* Preserve integer inputs in core `round()` for non-negative scales instead
of routing them through `Float64`.
* Preserve `UInt64` values in Spark-compatible `round()` when the scale is
non-negative, avoiding unnecessary `UInt64 -> i64` conversion.
* Add SQLLogicTest coverage for:
* `Int64` values above `2^53` in core `round()`.
* `UInt64::MAX` in Spark-compatible `round()`.
* Both one-argument and two-argument forms.
## Are these changes tested?
Yes.
```bash
cargo fmt --all
git diff --check
cargo test -p datafusion-sqllogictest --test sqllogictests --
spark/math/round.slt
cargo test -p datafusion-functions round
cargo test -p datafusion-spark round
```
I also verified the core regression queries manually:
```sql
SELECT arrow_typeof(round(arrow_cast(9007199254740993, 'Int64'))),
round(arrow_cast(9007199254740993, 'Int64'));
```
After:
```text
Int64 9007199254740993
```
```sql
SELECT arrow_typeof(round(arrow_cast(9007199254740993, 'Int64'), 2)),
round(arrow_cast(9007199254740993, 'Int64'), 2);
```
After:
```text
Int64 9007199254740993
```
## Are there any user-facing changes?
No.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]