Jefffrey commented on code in PR #19369:
URL: https://github.com/apache/datafusion/pull/19369#discussion_r2658749526


##########
datafusion/functions/src/math/power.rs:
##########
@@ -112,26 +114,31 @@ impl PowerFunc {
 ///   2.5 is represented as 25 with scale 1
 ///   The unscaled result is 25^4 = 390625
 ///   Scale it back to 1: 390625 / 10^4 = 39
-///
-/// Returns error if base is invalid
 fn pow_decimal_int<T>(base: T, scale: i8, exp: i64) -> Result<T, ArrowError>
 where
-    T: From<i32> + ArrowNativeTypeOp,
+    T: From<i32> + ArrowNativeTypeOp + ToPrimitive + NumCast + Copy,
 {
+    // Negative exponent: fall back to float computation
+    if exp < 0 {
+        return pow_decimal_float(base, scale, exp as f64);
+    }
+
     let exp: u32 = exp.try_into().map_err(|_| {
         ArrowError::ArithmeticOverflow(format!("Unsupported exp value: {exp}"))
     })?;
     // Handle edge case for exp == 0
     // If scale < 0, 10^scale (e.g., 10^-2 = 0.01) becomes 0 in integer 
arithmetic.
     if exp == 0 {
         return if scale >= 0 {
-            T::from(10).pow_checked(scale as u32).map_err(|_| {
-                ArrowError::ArithmeticOverflow(format!(
-                    "Cannot make unscale factor for {scale} and {exp}"
-                ))
-            })
+            <T as From<i32>>::from(10)

Review Comment:
   This looks a little ugly, I recommend checking the existing traits to see if 
they have what we already need.
   
   See:
   
   - https://docs.rs/arrow/latest/arrow/array/trait.ArrowNativeTypeOp.html
   - https://docs.rs/arrow/latest/arrow/datatypes/trait.ArrowNativeType.html



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