Creates a `StandardWindowFunctionExpr` suitable for a user defined window function
(
fun: &Arc<WindowUDF>,
args: &[Arc<dyn PhysicalExpr>],
input_schema: &Schema,
name: String,
ignore_nulls: bool,
)
| 168 | |
| 169 | /// Creates a `StandardWindowFunctionExpr` suitable for a user defined window function |
| 170 | pub fn create_udwf_window_expr( |
| 171 | fun: &Arc<WindowUDF>, |
| 172 | args: &[Arc<dyn PhysicalExpr>], |
| 173 | input_schema: &Schema, |
| 174 | name: String, |
| 175 | ignore_nulls: bool, |
| 176 | ) -> Result<Arc<dyn StandardWindowFunctionExpr>> { |
| 177 | // need to get the types into an owned vec for some reason |
| 178 | let input_fields: Vec<_> = args |
| 179 | .iter() |
| 180 | .map(|arg| arg.return_field(input_schema)) |
| 181 | .collect::<Result<_>>()?; |
| 182 | |
| 183 | let udwf_expr = Arc::new(WindowUDFExpr { |
| 184 | fun: Arc::clone(fun), |
| 185 | args: args.to_vec(), |
| 186 | input_fields, |
| 187 | name, |
| 188 | is_reversed: false, |
| 189 | ignore_nulls, |
| 190 | }); |
| 191 | |
| 192 | // Early validation of input expressions |
| 193 | // We create a partition evaluator because in the user-defined window |
| 194 | // implementation this is where code for parsing input expressions |
| 195 | // exist. The benefits are: |
| 196 | // - If any of the input expressions are invalid we catch them early |
| 197 | // in the planning phase, rather than during execution. |
| 198 | // - Maintains compatibility with built-in (now removed) window |
| 199 | // functions validation behavior. |
| 200 | // - Predictable and reliable error handling. |
| 201 | // See discussion here: |
| 202 | // https://github.com/apache/datafusion/pull/13201#issuecomment-2454209975 |
| 203 | let _ = udwf_expr.create_evaluator()?; |
| 204 | |
| 205 | Ok(udwf_expr) |
| 206 | } |
| 207 | |
| 208 | /// Implements [`StandardWindowFunctionExpr`] for [`WindowUDF`] |
| 209 | #[derive(Clone, Debug)] |
searching dependent graphs…