MCPcopy Create free account
hub / github.com/apache/datafusion / invoke_with_args

Method invoke_with_args

datafusion/physical-expr/src/async_scalar_function.rs:112–206  ·  view source on GitHub ↗

This (async) function is called for each record batch to evaluate the LLM expressions The output is the output of evaluating the async expression and the input record batch

(
        &self,
        batch: &RecordBatch,
        config_options: Arc<ConfigOptions>,
    )

Source from the content-addressed store, hash-verified

110 ///
111 /// The output is the output of evaluating the async expression and the input record batch
112 pub async fn invoke_with_args(
113 &self,
114 batch: &RecordBatch,
115 config_options: Arc<ConfigOptions>,
116 ) -> Result<ColumnarValue> {
117 let Some(scalar_function_expr) = self.func.downcast_ref::<ScalarFunctionExpr>()
118 else {
119 return internal_err!(
120 "unexpected function type, expected ScalarFunctionExpr, got: {:?}",
121 self.func
122 );
123 };
124
125 let Some(async_udf) = scalar_function_expr
126 .fun()
127 .inner()
128 .downcast_ref::<AsyncScalarUDF>()
129 else {
130 return not_impl_err!(
131 "Don't know how to evaluate async function: {:?}",
132 scalar_function_expr
133 );
134 };
135
136 let arg_fields = scalar_function_expr
137 .args()
138 .iter()
139 .map(|e| e.return_field(batch.schema_ref()))
140 .collect::<Result<Vec<_>>>()?;
141
142 let mut result_batches = vec![];
143 if let Some(ideal_batch_size) = self.ideal_batch_size()? {
144 let mut remainder = batch.clone();
145 while remainder.num_rows() > 0 {
146 let size = if ideal_batch_size > remainder.num_rows() {
147 remainder.num_rows()
148 } else {
149 ideal_batch_size
150 };
151
152 let current_batch = remainder.slice(0, size); // get next 10 rows
153 remainder = remainder.slice(size, remainder.num_rows() - size);
154 let args = scalar_function_expr
155 .args()
156 .iter()
157 .map(|e| e.evaluate(&current_batch))
158 .collect::<Result<Vec<_>>>()?;
159 result_batches.push(
160 async_udf
161 .invoke_async_with_args(ScalarFunctionArgs {
162 args,
163 arg_fields: arg_fields.clone(),
164 number_rows: current_batch.num_rows(),
165 return_field: Arc::clone(&self.return_field),
166 config_options: Arc::clone(&config_options),
167 })
168 .await?,
169 );

Callers 1

executeMethod · 0.45

Calls 15

sliceMethod · 0.80
to_vecMethod · 0.80
concatFunction · 0.50
innerMethod · 0.45
funMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
argsMethod · 0.45
return_fieldMethod · 0.45
ideal_batch_sizeMethod · 0.45
cloneMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected