findepi commented on code in PR #12922:
URL: https://github.com/apache/datafusion/pull/12922#discussion_r1801330973
##########
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:
If we allow such code to exist, wouldn't it be better to just have it during
constant-folding, rather than inside function implementations?
--
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]