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>,
)
| 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(¤t_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 | ); |
no test coverage detected