nuno-faria commented on code in PR #22174:
URL: https://github.com/apache/datafusion/pull/22174#discussion_r3243564877


##########
datafusion/sqllogictest/test_files/window.slt:
##########
@@ -6431,6 +6431,119 @@ FROM (
 2 2
 3 3
 
+############################################################################
+# RANGE frame with DECIMAL ORDER BY: decimal arithmetic widens the result
+# precision (e.g. Decimal(10,0) ± Decimal(10,0) → Decimal(11,0)), which
+# previously left the boundary target incomparable with the ORDER BY
+# column and failed with "Internal error: Uncomparable values".
+############################################################################
+
+# Original reporter query.

Review Comment:
   nit: reported?



##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -592,38 +592,39 @@ impl PartialOrd for ScalarValue {
         // any newly added enum variant will require editing this list
         // or else face a compile error
         match (self, other) {
-            (Decimal32(v1, p1, s1), Decimal32(v2, p2, s2)) => {
-                if p1.eq(p2) && s1.eq(s2) {
+            (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

Review Comment:
   I wonder if it would be desirable to also compare decimals of different 
scales.



-- 
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]

Reply via email to