shinzoxD commented on code in PR #24399:
URL: https://github.com/apache/datafusion/pull/24399#discussion_r3815259754


##########
datafusion/functions/src/math/log.rs:
##########
@@ -1213,4 +1243,135 @@ mod tests {
             }
         }
     }
+
+    fn invoke_log(
+        args: Vec<ColumnarValue>,
+        data_types: Vec<DataType>,
+    ) -> Result<ColumnarValue> {
+        let number_rows = args
+            .iter()
+            .map(|a| match a {
+                ColumnarValue::Array(arr) => arr.len(),
+                ColumnarValue::Scalar(_) => 1,
+            })
+            .max()
+            .unwrap_or(1);
+        let arg_fields = data_types
+            .into_iter()
+            .map(|dt| Field::new("a", dt, false).into())
+            .collect();
+        let args = ScalarFunctionArgs {
+            args,
+            arg_fields,
+            number_rows,
+            return_field: Field::new("f", DataType::Float64, true).into(),
+            config_options: Arc::new(ConfigOptions::default()),
+        };
+        LogFunc::new().invoke_with_args(args)
+    }
+
+    fn assert_log_of_zero(err: datafusion_common::DataFusionError) {
+        let message = err.to_string();
+        assert!(
+            message.contains(LOG_OF_ZERO_ERROR),
+            "expected '{LOG_OF_ZERO_ERROR}' in error, got {message}"
+        );
+    }
+
+    #[test]
+    fn test_log_zero_float64_unary_errors() {
+        let err = invoke_log(
+            vec![ColumnarValue::Scalar(ScalarValue::Float64(Some(0.0)))],
+            vec![DataType::Float64],
+        )
+        .expect_err("log(0.0) should be a domain error");
+        assert_log_of_zero(err);
+    }
+
+    #[test]
+    fn test_log_negative_zero_float64_errors() {
+        let err = invoke_log(
+            vec![ColumnarValue::Scalar(ScalarValue::Float64(Some(-0.0)))],
+            vec![DataType::Float64],
+        )
+        .expect_err("log(-0.0) should be a domain error");
+        assert_log_of_zero(err);
+    }
+
+    #[test]
+    fn test_log_zero_float32_unary_errors() {
+        let err = invoke_log(
+            vec![ColumnarValue::Scalar(ScalarValue::Float32(Some(0.0)))],
+            vec![DataType::Float32],
+        )
+        .expect_err("log(0.0f32) should be a domain error");
+        assert_log_of_zero(err);
+    }
+
+    #[test]
+    fn test_log_zero_float64_binary_errors() {
+        let err = invoke_log(
+            vec![
+                ColumnarValue::Scalar(ScalarValue::Float64(Some(10.0))),
+                ColumnarValue::Scalar(ScalarValue::Float64(Some(0.0))),
+            ],
+            vec![DataType::Float64, DataType::Float64],
+        )
+        .expect_err("log(10, 0.0) should be a domain error");
+        assert_log_of_zero(err);
+    }
+
+    #[test]
+    fn test_log_zero_array_errors() {
+        let err = invoke_log(
+            vec![ColumnarValue::Array(Arc::new(Float64Array::from(vec![
+                10.0, 0.0, 100.0,
+            ])))],
+            vec![DataType::Float64],
+        )
+        .expect_err("log() of an array containing 0 should be a domain error");
+        assert_log_of_zero(err);
+    }
+
+    #[test]
+    fn test_log_zero_decimal128_errors() {
+        let err = invoke_log(

Review Comment:
   Addressed in c383b0714d7f112b61779c2c2e6bb4d00118d071: added 
`test_log_zero_every_physical_type` in log.rs covering Float16, Float32, 
Float64, Decimal32, Decimal64, Decimal128, and Decimal256.



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