adriangb commented on code in PR #18446:
URL: https://github.com/apache/datafusion/pull/18446#discussion_r2499561951


##########
datafusion/physical-expr-common/src/utils.rs:
##########
@@ -91,6 +92,26 @@ pub fn scatter(mask: &BooleanArray, truthy: &dyn Array) -> 
Result<ArrayRef> {
     Ok(make_array(data))
 }
 
+/// Evaluates expressions against a record batch.
+/// This will convert the resulting ColumnarValues to ArrayRefs,
+/// duplicating any ScalarValues that may have been returned.
+/// This function does not perform any checks that the resulting arrays
+/// have the same length as the record batch.
+// NOTE: This means that this should not be called on expressions that may 
return
+// arrays of different lengths (e.g. filtering/flattening etc).
+// Also, consider avoiding this if your code can use optimizations for 
ScalarValues.
+#[inline]
+pub fn evaluate_expressions_to_arrays(
+    exprs: &[Arc<dyn PhysicalExpr>],
+    batch: &RecordBatch,
+) -> Result<Vec<ArrayRef>> {
+    let num_rows = batch.num_rows();
+    exprs
+        .iter()
+        .map(|e| e.evaluate(batch).and_then(|col| col.into_array(num_rows)))
+        .collect::<Result<Vec<ArrayRef>>>()
+}

Review Comment:
   Agreed I think `into_array` should be returning an error and checking for 
this, but that might be too big of a breaking change -> might just need to be a 
new function and document the foot gun or deprecate `into_array`.



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