Trait for implementing [`WindowUDF`]. This trait exposes the full API for implementing user defined window functions and can be used to implement any function. While the trait depends on [`DynEq`] and [`DynHash`] traits, these should not be implemented directly. Instead, implement [`Eq`] and [`Hash`] and leverage the blanket implementations of [`DynEq`] and [`DynHash`]. See [`advanced_udwf.rs`]
| 313 | /// .unwrap(); |
| 314 | /// ``` |
| 315 | pub trait WindowUDFImpl: Debug + DynEq + DynHash + Send + Sync + Any { |
| 316 | /// Returns this function's name |
| 317 | fn name(&self) -> &str; |
| 318 | |
| 319 | /// Returns any aliases (alternate names) for this function. |
| 320 | /// |
| 321 | /// Note: `aliases` should only include names other than [`Self::name`]. |
| 322 | /// Defaults to `[]` (no aliases) |
| 323 | fn aliases(&self) -> &[String] { |
| 324 | &[] |
| 325 | } |
| 326 | |
| 327 | /// Returns the function's [`Signature`] for information about what input |
| 328 | /// types are accepted and the function's Volatility. |
| 329 | fn signature(&self) -> &Signature; |
| 330 | |
| 331 | /// Returns the expressions that are passed to the [`PartitionEvaluator`]. |
| 332 | fn expressions(&self, expr_args: ExpressionArgs) -> Vec<Arc<dyn PhysicalExpr>> { |
| 333 | expr_args.input_exprs().into() |
| 334 | } |
| 335 | |
| 336 | /// Invoke the function, returning the [`PartitionEvaluator`] instance |
| 337 | fn partition_evaluator( |
| 338 | &self, |
| 339 | partition_evaluator_args: PartitionEvaluatorArgs, |
| 340 | ) -> Result<Box<dyn PartitionEvaluator>>; |
| 341 | |
| 342 | /// Returns an optional hook for simplifying this user-defined window |
| 343 | /// function. |
| 344 | /// |
| 345 | /// Use this hook to apply function-specific rewrites during optimization. |
| 346 | /// The default implementation returns `None`. |
| 347 | /// |
| 348 | /// DataFusion already simplifies arguments and performs constant folding |
| 349 | /// (for example, `my_add(1, 2) -> 3`), so there is usually no need to |
| 350 | /// implement those optimizations manually for specific UDFs. |
| 351 | /// |
| 352 | /// Example: |
| 353 | /// `advanced_udwf.rs`: <https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/advanced_udwf.rs> |
| 354 | /// |
| 355 | /// # Returns |
| 356 | /// `None` if simplify is not defined. |
| 357 | /// |
| 358 | /// Or, a closure ([`WindowFunctionSimplification`]) invoked with: |
| 359 | /// * `window_function`: [WindowFunction] with already simplified |
| 360 | /// arguments |
| 361 | /// * `info`: [crate::simplify::SimplifyContext] |
| 362 | /// |
| 363 | /// The closure returns a simplified [Expr] or an error. |
| 364 | /// |
| 365 | /// # Notes |
| 366 | /// The returned expression must have the same schema as the original |
| 367 | /// expression, including both the data type and nullability. For example, |
| 368 | /// if the original expression is nullable, the returned expression must |
| 369 | /// also be nullable, otherwise it may lead to schema verification errors |
| 370 | /// later in query planning. |
| 371 | fn simplify(&self) -> Option<WindowFunctionSimplification> { |
| 372 | None |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…