comphead opened a new pull request, #22174:
URL: https://github.com/apache/datafusion/pull/22174
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
- Closes #22113 .
## Rationale for this change
`RANGE` window frames with a `DECIMAL` `ORDER BY` column crash at runtime:
```sql
SELECT COUNT(*) OVER (
PARTITION BY 1
ORDER BY cast(1 as decimal(10, 0)) DESC
RANGE BETWEEN CURRENT ROW AND 1 FOLLOWING
) FROM (SELECT 1);
-- Internal error: Uncomparable values: Decimal128(Some(0),11,0),
Decimal128(Some(1),10,0).
```
Frame-bound arithmetic (`value ± delta`) widens the decimal result
precision by 1 (`Decimal(10,0) ± Decimal(10,0) → Decimal(11,0)`).
`search_in_slice` then compares the widened target against the
original `ORDER BY` column, and `ScalarValue::partial_cmp` rejects
decimals whose precision differs — even when the scale matches and the
underlying integer representation is directly comparable.
That precision-equality gate is also inconsistent with SQL semantics:
`DEC(10,0) 1` and `DEC(20,0) 1` represent the same number and should compare
equal.
## What changes are included in this PR?
**`datafusion/common/src/scalar/mod.rs`**
- `ScalarValue::partial_cmp` for `Decimal32` / `Decimal64` / `Decimal128`
/ `Decimal256`: compare underlying values whenever scales match, regardless of
declared precision. Different scales still
return `None` (rescaling would be required).
**`datafusion/sqllogictest/test_files/window.slt`**
- Regression block covering the reporter query verbatim plus `ASC`/`DESC`
× `PRECEDING`/`FOLLOWING`, symmetric `N PRECEDING AND N FOLLOWING`, and a
non-zero-scale `DECIMAL(10,2)` case over multi-row
partitions.
--
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]