joroKr21 commented on code in PR #12965:
URL: https://github.com/apache/datafusion/pull/12965#discussion_r1802959651


##########
datafusion/physical-expr/src/scalar_function.rs:
##########
@@ -147,8 +149,19 @@ impl PhysicalExpr for ScalarFunctionExpr {
 
         if let ColumnarValue::Array(array) = &output {
             if array.len() != batch.num_rows() {
-                return internal_err!("UDF returned a different number of rows 
than expected. Expected: {}, Got: {}",
-                        batch.num_rows(), array.len());
+                // If the function is not volatile and all arguments are 
scalars,
+                // we can assume that returning a one-element array is 
equivalent to returning a scalar.
+                let preserve_scalar = array.len() == 1
+                    && self.fun.signature().volatility != Volatility::Volatile

Review Comment:
   A volatile function is supposed to return a different result on every 
invocation so I don't think it's safe to do that. The example we were 
discussing in the earlier PR is a hypothetical `rand(upper_bound: Int64) -> 
Int64` function.



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