alamb commented on code in PR #9114:
URL: https://github.com/apache/arrow-datafusion/pull/9114#discussion_r1477046476
##########
datafusion/expr/src/columnar_value.rs:
##########
@@ -75,4 +75,166 @@ impl ColumnarValue {
pub fn create_null_array(num_rows: usize) -> Self {
ColumnarValue::Array(Arc::new(NullArray::new(num_rows)))
}
+
+ /// Converts [`ColumnarValue`]s to [`ArrayRef`]s with the same length.
+ ///
+ /// # Performance Note
+ ///
+ /// This function expands any [`ScalarValue`] to an array. This expansion
+ /// permits using a single function in terms of arrays, but it can be
+ /// inefficient compared to handling the scalar value directly.
+ ///
+ /// Thus, It is recommended to provide specialized implementations for
+ /// scalar values if performance is a concern.
+ ///
+ /// # Errors
+ ///
+ /// If there are multiple array arguments that have different lengths
+ pub fn values_to_arrays(args: &[ColumnarValue]) -> Result<Vec<ArrayRef>> {
+ if args.is_empty() {
+ return Ok(vec![]);
+ }
+
+ let mut array_len = None;
+ for arg in args {
+ array_len = match (arg, array_len) {
+ (ColumnarValue::Array(a), None) => Some(a.len()),
+ (ColumnarValue::Array(a), Some(array_len)) => {
+ if array_len == a.len() {
+ Some(array_len)
+ } else {
+ return internal_err!(
+ "Arguments has mixed length. Expected length:
{array_len}, found length: {}",a.len()
+ );
Review Comment:
That is strange fmt didn't pick that one up 🤔
--
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]