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


##########
datafusion/expr-common/src/columnar_value.rs:
##########
@@ -218,6 +217,17 @@ impl ColumnarValue {
             }
         }
     }
+
+    /// Converts an [`ArrayRef`] to a [`ColumnarValue`] based on the supplied 
arguments.
+    /// This is useful for scalar UDF implementations to fulfil their contract:
+    /// if all arguments are scalar values, the result should also be a scalar 
value.
+    pub fn from_args_and_result(args: &[Self], result: ArrayRef) -> 
Result<Self> {
+        if result.len() == 1 && args.iter().all(|arg| matches!(arg, 
Self::Scalar(_))) {
+            Ok(Self::Scalar(ScalarValue::try_from_array(&result, 0)?))
+        } else {
+            Ok(Self::Array(result))

Review Comment:
   It's not the only place where it matters. If for some reason the expression 
is not constant folded, you will get an error that the array lengths of 
different columns don't match.



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