feat: fix windows decimal casting frame#22174
Open
comphead wants to merge 1 commit into
Open
Conversation
nuno-faria
approved these changes
May 14, 2026
Contributor
nuno-faria
left a comment
There was a problem hiding this comment.
Thanks @comphead, LGTM.
Comment on lines
+595
to
604
| (Decimal32(v1, _, s1), Decimal32(v2, _, s2)) => { | ||
| if s1.eq(s2) { | ||
| // Same scale means the underlying integer values share | ||
| // a common interpretation regardless of declared | ||
| // precision (arithmetic such as `add_checked` widens | ||
| // precision by 1 but does not change the numeric | ||
| // meaning). | ||
| v1.partial_cmp(v2) | ||
| } else { | ||
| // Two decimal values can be compared if they have the same precision and scale. | ||
| None |
Contributor
There was a problem hiding this comment.
I wonder if it would be desirable to also compare decimals of different scales.
| # column and failed with "Internal error: Uncomparable values". | ||
| ############################################################################ | ||
|
|
||
| # Original reporter query. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
RANGEwindow frames with aDECIMALORDER BYcolumn crash at runtime:Frame-bound arithmetic (
value ± delta) widens the decimal result precision by 1 (Decimal(10,0) ± Decimal(10,0) → Decimal(11,0)).search_in_slicethen compares the widened target against theoriginal
ORDER BYcolumn, andScalarValue::partial_cmprejects 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) 1andDEC(20,0) 1represent the same number and should compare equal.What changes are included in this PR?
datafusion/common/src/scalar/mod.rsScalarValue::partial_cmpforDecimal32/Decimal64/Decimal128/Decimal256: compare underlying values whenever scales match, regardless of declared precision. Different scales stillreturn
None(rescaling would be required).datafusion/sqllogictest/test_files/window.sltASC/DESC×PRECEDING/FOLLOWING, symmetricN PRECEDING AND N FOLLOWING, and a non-zero-scaleDECIMAL(10,2)case over multi-rowpartitions.