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


##########
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:
   That depends how we define "correct".
   IF constant folding is the only party where maintaining 
ColumnarValue::Scalar matters, THEN we can redefine "correct", loosening the 
contract. 



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