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


##########
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:
   Seems reasonable to me, I do still think this should be inside 
ColumnarValue, I will prob make this PR in the near future



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