findepi commented on code in PR #16831:
URL: https://github.com/apache/datafusion/pull/16831#discussion_r2221398992


##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -1790,6 +1808,27 @@ impl ScalarValue {
             (Self::Float64(Some(l)), Self::Float64(Some(r))) => {
                 Some((l - r).abs().round() as _)
             }
+            (
+                Self::Decimal128(Some(l), lprecision, lscale),
+                Self::Decimal128(Some(r), rprecision, rscale),
+            ) => {
+                if lprecision == rprecision && lscale == rscale {
+                    l.checked_sub(*r)?.abs().to_usize()
+                } else {
+                    None
+                }
+            }
+            (
+                Self::Decimal256(Some(l), lprecision, lscale),
+                Self::Decimal256(Some(r), rprecision, rscale),
+            ) => {
+                if lprecision == rprecision && lscale == rscale {
+                    // l.checked_sub(*r).and_then( |v| v.checked_abs() 
).and_then(|v| v.to_usize() )

Review Comment:
   remove



##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -1400,6 +1406,12 @@ impl ScalarValue {
             DataType::Float16 => 
ScalarValue::Float16(Some(f16::from_f32(-1.0))),
             DataType::Float32 => ScalarValue::Float32(Some(-1.0)),
             DataType::Float64 => ScalarValue::Float64(Some(-1.0)),
+            DataType::Decimal128(precision, scale) => {
+                ScalarValue::Decimal128(Some(-1), *precision, *scale)

Review Comment:
   same as https://github.com/apache/datafusion/pull/16831/files#r2218150407



##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -1790,6 +1808,27 @@ impl ScalarValue {
             (Self::Float64(Some(l)), Self::Float64(Some(r))) => {
                 Some((l - r).abs().round() as _)
             }
+            (
+                Self::Decimal128(Some(l), lprecision, lscale),
+                Self::Decimal128(Some(r), rprecision, rscale),
+            ) => {
+                if lprecision == rprecision && lscale == rscale {
+                    l.checked_sub(*r)?.abs().to_usize()
+                } else {
+                    None
+                }
+            }
+            (
+                Self::Decimal256(Some(l), lprecision, lscale),
+                Self::Decimal256(Some(r), rprecision, rscale),
+            ) => {
+                if lprecision == rprecision && lscale == rscale {
+                    // l.checked_sub(*r).and_then( |v| v.checked_abs() 
).and_then(|v| v.to_usize() )
+                    l.checked_sub(*r)?.checked_abs()?.to_usize()

Review Comment:
   to_usize returns None on overflow.
   shouldn't we return None when checked_sub or checked_abs overflow too?



##########
datafusion/optimizer/src/simplify_expressions/utils.rs:
##########
@@ -168,10 +133,17 @@ pub fn is_one(s: &Expr) -> bool {
         Expr::Literal(ScalarValue::Float64(Some(v)), _) if *v == 1. => true,
         Expr::Literal(ScalarValue::Decimal128(Some(v), _p, s), _) => {
             *s >= 0
-                && POWS_OF_TEN

Review Comment:
   Why were powers of 10 precomputed?



##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -1790,6 +1808,27 @@ impl ScalarValue {
             (Self::Float64(Some(l)), Self::Float64(Some(r))) => {
                 Some((l - r).abs().round() as _)
             }
+            (
+                Self::Decimal128(Some(l), lprecision, lscale),
+                Self::Decimal128(Some(r), rprecision, rscale),
+            ) => {
+                if lprecision == rprecision && lscale == rscale {
+                    l.checked_sub(*r)?.abs().to_usize()

Review Comment:
   to_usize returns None on overflow.
   shouldn't we return None when checked_sub overflows too?



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to