shifluxxc commented on code in PR #19409:
URL: https://github.com/apache/datafusion/pull/19409#discussion_r2639737974


##########
datafusion/functions/src/math/log.rs:
##########
@@ -118,13 +118,18 @@ fn log_decimal32(value: i32, scale: i8, base: f64) -> 
Result<f64, ArrowError> {
         )));
     }
 
-    let unscaled_value = decimal32_to_i32(value, scale)?;
-    if unscaled_value > 0 {
+    // Match f64::log behaviour
+    if value <= 0 {
+        return Ok(f64::NAN);
+    }
+
+    if scale < 0 {
+        let actual_value = (value as f64) * 10.0_f64.powi(-(scale as i32));
+        Ok(actual_value.log(base))
+    } else {
+        let unscaled_value = decimal32_to_i32(value, scale)?;
         let log_value: u32 = unscaled_value.ilog(base as i32);

Review Comment:
   I do think returning NaN is better , I have also added two sqllogic tests to 
check this behavior .  



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