Skip to main content

datafusion_expr/
udwf.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! [`WindowUDF`]: User Defined Window Functions
6
7use arrow::compute::SortOptions;
8use std::cmp::Ordering;
9use std::hash::{Hash, Hasher};
10use std::{
11    any::Any,
12    fmt::{self, Debug, Display, Formatter},
13    sync::Arc,
14};
15
16use arrow::datatypes::{DataType, FieldRef};
17
18use crate::expr::WindowFunction;
19use crate::udf_eq::UdfEq;
20use crate::{
21    Expr, PartitionEvaluator, Signature, function::WindowFunctionSimplification,
22};
23use datafusion_common::{Result, not_impl_err};
24use datafusion_doc::Documentation;
25use datafusion_expr_common::dyn_eq::{DynEq, DynHash};
26use datafusion_functions_window_common::expr::ExpressionArgs;
27use datafusion_functions_window_common::field::WindowUDFFieldArgs;
28use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
29use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
30
31/// Logical representation of a user-defined window function (UDWF).
32///
33/// A Window Function is called via the SQL `OVER` clause:
34///
35/// ```sql
36/// SELECT first_value(col) OVER (PARTITION BY a, b ORDER BY c) FROM foo;
37/// ```
38///
39/// A UDWF is different from a user defined function (UDF) in that it is
40/// stateful across batches.
41///
42/// See the documentation on [`PartitionEvaluator`] for more details
43///
44/// 1. For simple use cases, use [`create_udwf`] (examples in
45///    [`simple_udwf.rs`]).
46///
47/// 2. For advanced use cases, use [`WindowUDFImpl`] which provides full API
48///    access (examples in [`advanced_udwf.rs`]).
49///
50/// # API Note
51/// This is a separate struct from `WindowUDFImpl` to maintain backwards
52/// compatibility with the older API.
53///
54/// [`PartitionEvaluator`]: crate::PartitionEvaluator
55/// [`create_udwf`]: crate::expr_fn::create_udwf
56/// [`simple_udwf.rs`]: https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/simple_udwf.rs
57/// [`advanced_udwf.rs`]: https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/advanced_udwf.rs
58#[derive(Debug, Clone, PartialOrd)]
59pub struct WindowUDF {
60    inner: Arc<dyn WindowUDFImpl>,
61}
62
63/// Defines how the WindowUDF is shown to users
64impl Display for WindowUDF {
65    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
66        write!(f, "{}", self.name())
67    }
68}
69
70impl PartialEq for WindowUDF {
71    fn eq(&self, other: &Self) -> bool {
72        self.inner.dyn_eq(other.inner.as_ref() as &dyn Any)
73    }
74}
75
76impl Eq for WindowUDF {}
77
78impl Hash for WindowUDF {
79    fn hash<H: Hasher>(&self, state: &mut H) {
80        self.inner.dyn_hash(state)
81    }
82}
83
84impl WindowUDF {
85    /// Create a new `WindowUDF` from a `[WindowUDFImpl]` trait object
86    ///
87    /// Note this is the same as using the `From` impl (`WindowUDF::from`)
88    pub fn new_from_impl<F>(fun: F) -> WindowUDF
89    where
90        F: WindowUDFImpl + 'static,
91    {
92        Self::new_from_shared_impl(Arc::new(fun))
93    }
94
95    /// Create a new `WindowUDF` from a `[WindowUDFImpl]` trait object
96    pub fn new_from_shared_impl(fun: Arc<dyn WindowUDFImpl>) -> WindowUDF {
97        Self { inner: fun }
98    }
99
100    /// Return the underlying [`WindowUDFImpl`] trait object for this function
101    pub fn inner(&self) -> &Arc<dyn WindowUDFImpl> {
102        &self.inner
103    }
104
105    /// Adds additional names that can be used to invoke this function, in
106    /// addition to `name`
107    ///
108    /// If you implement [`WindowUDFImpl`] directly you should return aliases directly.
109    pub fn with_aliases(self, aliases: impl IntoIterator<Item = &'static str>) -> Self {
110        Self::new_from_impl(AliasedWindowUDFImpl::new(Arc::clone(&self.inner), aliases))
111    }
112
113    /// creates a [`Expr`] that calls the window function with default
114    /// values for `order_by`, `partition_by`, `window_frame`.
115    ///
116    /// See [`ExprFunctionExt`] for details on setting these values.
117    ///
118    /// This utility allows using a user defined window function without
119    /// requiring access to the registry, such as with the DataFrame API.
120    ///
121    /// [`ExprFunctionExt`]: crate::expr_fn::ExprFunctionExt
122    pub fn call(&self, args: Vec<Expr>) -> Expr {
123        let fun = crate::WindowFunctionDefinition::WindowUDF(Arc::new(self.clone()));
124
125        Expr::from(WindowFunction::new(fun, args))
126    }
127
128    /// Returns this function's name
129    ///
130    /// See [`WindowUDFImpl::name`] for more details.
131    pub fn name(&self) -> &str {
132        self.inner.name()
133    }
134
135    /// Returns the aliases for this function.
136    pub fn aliases(&self) -> &[String] {
137        self.inner.aliases()
138    }
139
140    /// Returns this function's signature (what input types are accepted)
141    ///
142    /// See [`WindowUDFImpl::signature`] for more details.
143    pub fn signature(&self) -> &Signature {
144        self.inner.signature()
145    }
146
147    /// Returns this window function's simplification hook, if any.
148    ///
149    /// See [`WindowUDFImpl::simplify`] for more details.
150    pub fn simplify(&self) -> Option<WindowFunctionSimplification> {
151        self.inner.simplify()
152    }
153
154    /// Expressions that are passed to the [`PartitionEvaluator`].
155    ///
156    /// See [`WindowUDFImpl::expressions`] for more details.
157    pub fn expressions(&self, expr_args: ExpressionArgs) -> Vec<Arc<dyn PhysicalExpr>> {
158        self.inner.expressions(expr_args)
159    }
160    /// Return a `PartitionEvaluator` for evaluating this window function
161    pub fn partition_evaluator_factory(
162        &self,
163        partition_evaluator_args: PartitionEvaluatorArgs,
164    ) -> Result<Box<dyn PartitionEvaluator>> {
165        self.inner.partition_evaluator(partition_evaluator_args)
166    }
167
168    /// Returns the field of the final result of evaluating this window function.
169    ///
170    /// See [`WindowUDFImpl::field`] for more details.
171    pub fn field(&self, field_args: WindowUDFFieldArgs) -> Result<FieldRef> {
172        self.inner.field(field_args)
173    }
174
175    /// Returns custom result ordering introduced by this window function
176    /// which is used to update ordering equivalences.
177    ///
178    /// See [`WindowUDFImpl::sort_options`] for more details.
179    pub fn sort_options(&self) -> Option<SortOptions> {
180        self.inner.sort_options()
181    }
182
183    /// See [`WindowUDFImpl::coerce_types`] for more details.
184    pub fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
185        self.inner.coerce_types(arg_types)
186    }
187
188    /// Returns the reversed user-defined window function when the
189    /// order of evaluation is reversed.
190    ///
191    /// See [`WindowUDFImpl::reverse_expr`] for more details.
192    pub fn reverse_expr(&self) -> ReversedUDWF {
193        self.inner.reverse_expr()
194    }
195
196    /// Returns the documentation for this Window UDF.
197    ///
198    /// Documentation can be accessed programmatically as well as
199    /// generating publicly facing documentation.
200    pub fn documentation(&self) -> Option<&Documentation> {
201        self.inner.documentation()
202    }
203}
204
205impl<F> From<F> for WindowUDF
206where
207    F: WindowUDFImpl + Send + Sync + 'static,
208{
209    fn from(fun: F) -> Self {
210        Self::new_from_impl(fun)
211    }
212}
213
214/// Trait for implementing [`WindowUDF`].
215///
216/// This trait exposes the full API for implementing user defined window functions and
217/// can be used to implement any function.
218///
219/// While the trait depends on [`DynEq`] and [`DynHash`] traits, these should not be
220/// implemented directly. Instead, implement [`Eq`] and [`Hash`] and leverage the
221/// blanket implementations of [`DynEq`] and [`DynHash`].
222///
223/// See [`advanced_udwf.rs`] for a full example with complete implementation and
224/// [`WindowUDF`] for other available options.
225///
226///
227/// [`advanced_udwf.rs`]: https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/advanced_udwf.rs
228/// # Basic Example
229/// ```
230/// # use std::sync::LazyLock;
231/// # use arrow::datatypes::{DataType, Field, FieldRef};
232/// # use datafusion_common::{DataFusionError, plan_err, Result};
233/// # use datafusion_expr::{col, Signature, Volatility, PartitionEvaluator, WindowFrame, ExprFunctionExt, Documentation, LimitEffect};
234/// # use datafusion_expr::{WindowUDFImpl, WindowUDF};
235/// # use datafusion_functions_window_common::field::WindowUDFFieldArgs;
236/// # use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
237/// # use datafusion_expr::window_doc_sections::DOC_SECTION_ANALYTICAL;
238/// # use datafusion_physical_expr_common::physical_expr;
239/// # use std::sync::Arc;
240///
241/// #[derive(Debug, Clone, PartialEq, Eq, Hash)]
242/// struct SmoothIt {
243///   signature: Signature,
244/// }
245///
246/// impl SmoothIt {
247///   fn new() -> Self {
248///     Self {
249///       signature: Signature::uniform(1, vec![DataType::Int32], Volatility::Immutable),
250///      }
251///   }
252/// }
253///
254/// static DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
255///     Documentation::builder(DOC_SECTION_ANALYTICAL, "smooths the windows", "smooth_it(2)")
256///         .with_argument("arg1", "The int32 number to smooth by")
257///         .build()
258/// });
259///
260/// fn get_doc() -> &'static Documentation {
261///     &DOCUMENTATION
262/// }
263///
264/// /// Implement the WindowUDFImpl trait for SmoothIt
265/// impl WindowUDFImpl for SmoothIt {
266///    fn name(&self) -> &str { "smooth_it" }
267///    fn signature(&self) -> &Signature { &self.signature }
268///    // The actual implementation would smooth the window
269///    fn partition_evaluator(
270///        &self,
271///        _partition_evaluator_args: PartitionEvaluatorArgs,
272///    ) -> Result<Box<dyn PartitionEvaluator>> {
273///        unimplemented!()
274///    }
275///    fn field(&self, field_args: WindowUDFFieldArgs) -> Result<FieldRef> {
276///      if let Some(DataType::Int32) = field_args.get_input_field(0).map(|f| f.data_type().clone()) {
277///        Ok(Field::new(field_args.name(), DataType::Int32, false).into())
278///      } else {
279///        plan_err!("smooth_it only accepts Int32 arguments")
280///      }
281///    }
282///    fn documentation(&self) -> Option<&Documentation> {
283///      Some(get_doc())
284///    }
285///     fn limit_effect(&self, _args: &[Arc<dyn physical_expr::PhysicalExpr>]) -> LimitEffect {
286///         LimitEffect::Unknown
287///     }
288/// }
289///
290/// // Create a new WindowUDF from the implementation
291/// let smooth_it = WindowUDF::from(SmoothIt::new());
292///
293/// // Call the function `add_one(col)`
294/// // smooth_it(speed) OVER (PARTITION BY car ORDER BY time ASC)
295/// let expr = smooth_it.call(vec![col("speed")])
296///     .partition_by(vec![col("car")])
297///     .order_by(vec![col("time").sort(true, true)])
298///     .window_frame(WindowFrame::new(None))
299///     .build()
300///     .unwrap();
301/// ```
302pub trait WindowUDFImpl: Debug + DynEq + DynHash + Send + Sync + Any {
303    /// Returns this function's name
304    fn name(&self) -> &str;
305
306    /// Returns any aliases (alternate names) for this function.
307    ///
308    /// Note: `aliases` should only include names other than [`Self::name`].
309    /// Defaults to `[]` (no aliases)
310    fn aliases(&self) -> &[String] {
311        &[]
312    }
313
314    /// Returns the function's [`Signature`] for information about what input
315    /// types are accepted and the function's Volatility.
316    fn signature(&self) -> &Signature;
317
318    /// Returns the expressions that are passed to the [`PartitionEvaluator`].
319    fn expressions(&self, expr_args: ExpressionArgs) -> Vec<Arc<dyn PhysicalExpr>> {
320        expr_args.input_exprs().into()
321    }
322
323    /// Invoke the function, returning the [`PartitionEvaluator`] instance
324    fn partition_evaluator(
325        &self,
326        partition_evaluator_args: PartitionEvaluatorArgs,
327    ) -> Result<Box<dyn PartitionEvaluator>>;
328
329    /// Returns an optional hook for simplifying this user-defined window
330    /// function.
331    ///
332    /// Use this hook to apply function-specific rewrites during optimization.
333    /// The default implementation returns `None`.
334    ///
335    /// DataFusion already simplifies arguments and performs constant folding
336    /// (for example, `my_add(1, 2) -> 3`), so there is usually no need to
337    /// implement those optimizations manually for specific UDFs.
338    ///
339    /// Example:
340    /// `advanced_udwf.rs`: <https://github.com/apache/datafusion/blob/main/datafusion-examples/examples/udf/advanced_udwf.rs>
341    ///
342    /// # Returns
343    /// `None` if simplify is not defined.
344    ///
345    /// Or, a closure ([`WindowFunctionSimplification`]) invoked with:
346    /// * `window_function`: [WindowFunction] with already simplified
347    ///   arguments
348    /// * `info`: [crate::simplify::SimplifyContext]
349    ///
350    /// The closure returns a simplified [Expr] or an error.
351    ///
352    /// # Notes
353    /// The returned expression must have the same schema as the original
354    /// expression, including both the data type and nullability. For example,
355    /// if the original expression is nullable, the returned expression must
356    /// also be nullable, otherwise it may lead to schema verification errors
357    /// later in query planning.
358    fn simplify(&self) -> Option<WindowFunctionSimplification> {
359        None
360    }
361
362    /// The [`FieldRef`] of the final result of evaluating this window function.
363    ///
364    /// Call `field_args.name()` to get the fully qualified name for defining
365    /// the [`FieldRef`]. For a complete example see the implementation in the
366    /// [Basic Example](WindowUDFImpl#basic-example) section.
367    fn field(&self, field_args: WindowUDFFieldArgs) -> Result<FieldRef>;
368
369    /// Allows the window UDF to define a custom result ordering.
370    ///
371    /// By default, a window UDF doesn't introduce an ordering.
372    /// But when specified by a window UDF this is used to update
373    /// ordering equivalences.
374    fn sort_options(&self) -> Option<SortOptions> {
375        None
376    }
377
378    /// Coerce arguments of a function call to types that the function can evaluate.
379    ///
380    /// This function is only called if [`WindowUDFImpl::signature`] returns [`crate::TypeSignature::UserDefined`]. Most
381    /// UDWFs should return one of the other variants of `TypeSignature` which handle common
382    /// cases
383    ///
384    /// See the [type coercion module](crate::type_coercion)
385    /// documentation for more details on type coercion
386    ///
387    /// For example, if your function requires a floating point arguments, but the user calls
388    /// it like `my_func(1::int)` (aka with `1` as an integer), coerce_types could return `[DataType::Float64]`
389    /// to ensure the argument was cast to `1::double`
390    ///
391    /// # Parameters
392    /// * `arg_types`: The argument types of the arguments  this function with
393    ///
394    /// # Return value
395    /// A Vec the same length as `arg_types`. DataFusion will `CAST` the function call
396    /// arguments to these specific types.
397    fn coerce_types(&self, _arg_types: &[DataType]) -> Result<Vec<DataType>> {
398        not_impl_err!("Function {} does not implement coerce_types", self.name())
399    }
400
401    /// Allows customizing the behavior of the user-defined window
402    /// function when it is evaluated in reverse order.
403    fn reverse_expr(&self) -> ReversedUDWF {
404        ReversedUDWF::NotSupported
405    }
406
407    /// Returns the documentation for this Window UDF.
408    ///
409    /// Documentation can be accessed programmatically as well as
410    /// generating publicly facing documentation.
411    fn documentation(&self) -> Option<&Documentation> {
412        None
413    }
414
415    /// If not causal, returns the effect this function will have on the window
416    fn limit_effect(&self, _args: &[Arc<dyn PhysicalExpr>]) -> LimitEffect {
417        LimitEffect::Unknown
418    }
419}
420
421impl dyn WindowUDFImpl {
422    /// Returns `true` if the implementation is of type `T`.
423    ///
424    /// Works correctly when called on `Arc<dyn WindowUDFImpl>` via auto-deref.
425    pub fn is<T: WindowUDFImpl>(&self) -> bool {
426        (self as &dyn Any).is::<T>()
427    }
428
429    /// Attempts to downcast to a concrete type `T`, returning `None` if the
430    /// implementation is not of that type.
431    ///
432    /// Works correctly when called on `Arc<dyn WindowUDFImpl>` via auto-deref,
433    /// unlike `(&arc as &dyn Any).downcast_ref::<T>()` which would attempt to
434    /// downcast the `Arc` itself.
435    pub fn downcast_ref<T: WindowUDFImpl>(&self) -> Option<&T> {
436        (self as &dyn Any).downcast_ref()
437    }
438}
439
440/// the effect this function will have on the limit pushdown
441pub enum LimitEffect {
442    /// Does not affect the limit (i.e. this is causal)
443    None,
444    /// Either undeclared, or dynamic (only evaluatable at run time)
445    Unknown,
446    /// Grow the limit by N rows
447    Relative(usize),
448    /// Limit needs to be at least N rows
449    Absolute(usize),
450}
451
452pub enum ReversedUDWF {
453    /// The result of evaluating the user-defined window function
454    /// remains identical when reversed.
455    Identical,
456    /// A window function which does not support evaluating the result
457    /// in reverse order.
458    NotSupported,
459    /// Customize the user-defined window function for evaluating the
460    /// result in reverse order.
461    Reversed(Arc<WindowUDF>),
462}
463
464impl PartialEq for dyn WindowUDFImpl {
465    fn eq(&self, other: &Self) -> bool {
466        self.dyn_eq(other as &dyn Any)
467    }
468}
469
470impl PartialOrd for dyn WindowUDFImpl {
471    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
472        match self.name().partial_cmp(other.name()) {
473            Some(Ordering::Equal) => self.signature().partial_cmp(other.signature()),
474            cmp => cmp,
475        }
476        // TODO (https://github.com/apache/datafusion/issues/17477) avoid recomparing all fields
477        .filter(|cmp| *cmp != Ordering::Equal || self == other)
478    }
479}
480
481/// WindowUDF that adds an alias to the underlying function. It is better to
482/// implement [`WindowUDFImpl`], which supports aliases, directly if possible.
483#[derive(Debug, PartialEq, Eq, Hash)]
484struct AliasedWindowUDFImpl {
485    inner: UdfEq<Arc<dyn WindowUDFImpl>>,
486    aliases: Vec<String>,
487}
488
489impl AliasedWindowUDFImpl {
490    pub fn new(
491        inner: Arc<dyn WindowUDFImpl>,
492        new_aliases: impl IntoIterator<Item = &'static str>,
493    ) -> Self {
494        let mut aliases = inner.aliases().to_vec();
495        aliases.extend(new_aliases.into_iter().map(|s| s.to_string()));
496
497        Self {
498            inner: inner.into(),
499            aliases,
500        }
501    }
502}
503
504#[warn(clippy::missing_trait_methods)] // Delegates, so it should implement every single trait method
505impl WindowUDFImpl for AliasedWindowUDFImpl {
506    fn name(&self) -> &str {
507        self.inner.name()
508    }
509
510    fn signature(&self) -> &Signature {
511        self.inner.signature()
512    }
513
514    fn expressions(&self, expr_args: ExpressionArgs) -> Vec<Arc<dyn PhysicalExpr>> {
515        expr_args
516            .input_exprs()
517            .first()
518            .map_or(vec![], |expr| vec![Arc::clone(expr)])
519    }
520
521    fn partition_evaluator(
522        &self,
523        partition_evaluator_args: PartitionEvaluatorArgs,
524    ) -> Result<Box<dyn PartitionEvaluator>> {
525        self.inner.partition_evaluator(partition_evaluator_args)
526    }
527
528    fn aliases(&self) -> &[String] {
529        &self.aliases
530    }
531
532    fn simplify(&self) -> Option<WindowFunctionSimplification> {
533        self.inner.simplify()
534    }
535
536    fn field(&self, field_args: WindowUDFFieldArgs) -> Result<FieldRef> {
537        self.inner.field(field_args)
538    }
539
540    fn sort_options(&self) -> Option<SortOptions> {
541        self.inner.sort_options()
542    }
543
544    fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
545        self.inner.coerce_types(arg_types)
546    }
547
548    fn reverse_expr(&self) -> ReversedUDWF {
549        self.inner.reverse_expr()
550    }
551
552    fn documentation(&self) -> Option<&Documentation> {
553        self.inner.documentation()
554    }
555
556    fn limit_effect(&self, args: &[Arc<dyn PhysicalExpr>]) -> LimitEffect {
557        self.inner.limit_effect(args)
558    }
559}
560
561#[cfg(test)]
562mod test {
563    use crate::{LimitEffect, PartitionEvaluator, WindowUDF, WindowUDFImpl};
564    use arrow::datatypes::{DataType, FieldRef};
565    use datafusion_common::Result;
566    use datafusion_expr_common::signature::{Signature, Volatility};
567    use datafusion_functions_window_common::field::WindowUDFFieldArgs;
568    use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
569    use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
570    use std::cmp::Ordering;
571    use std::hash::{DefaultHasher, Hash, Hasher};
572    use std::sync::Arc;
573
574    #[derive(Debug, Clone, PartialEq, Eq, Hash)]
575    struct AWindowUDF {
576        signature: Signature,
577    }
578
579    impl AWindowUDF {
580        fn new() -> Self {
581            Self {
582                signature: Signature::uniform(
583                    1,
584                    vec![DataType::Int32],
585                    Volatility::Immutable,
586                ),
587            }
588        }
589    }
590
591    /// Implement the WindowUDFImpl trait for AddOne
592    impl WindowUDFImpl for AWindowUDF {
593        fn name(&self) -> &str {
594            "a"
595        }
596        fn signature(&self) -> &Signature {
597            &self.signature
598        }
599        fn partition_evaluator(
600            &self,
601            _partition_evaluator_args: PartitionEvaluatorArgs,
602        ) -> Result<Box<dyn PartitionEvaluator>> {
603            unimplemented!()
604        }
605        fn field(&self, _field_args: WindowUDFFieldArgs) -> Result<FieldRef> {
606            unimplemented!()
607        }
608
609        fn limit_effect(&self, _args: &[Arc<dyn PhysicalExpr>]) -> LimitEffect {
610            LimitEffect::Unknown
611        }
612    }
613
614    #[derive(Debug, Clone, PartialEq, Eq, Hash)]
615    struct BWindowUDF {
616        signature: Signature,
617    }
618
619    impl BWindowUDF {
620        fn new() -> Self {
621            Self {
622                signature: Signature::uniform(
623                    1,
624                    vec![DataType::Int32],
625                    Volatility::Immutable,
626                ),
627            }
628        }
629    }
630
631    /// Implement the WindowUDFImpl trait for AddOne
632    impl WindowUDFImpl for BWindowUDF {
633        fn name(&self) -> &str {
634            "b"
635        }
636        fn signature(&self) -> &Signature {
637            &self.signature
638        }
639        fn partition_evaluator(
640            &self,
641            _partition_evaluator_args: PartitionEvaluatorArgs,
642        ) -> Result<Box<dyn PartitionEvaluator>> {
643            unimplemented!()
644        }
645        fn field(&self, _field_args: WindowUDFFieldArgs) -> Result<FieldRef> {
646            unimplemented!()
647        }
648
649        fn limit_effect(&self, _args: &[Arc<dyn PhysicalExpr>]) -> LimitEffect {
650            LimitEffect::Unknown
651        }
652    }
653
654    #[test]
655    fn test_partial_eq() {
656        let a1 = WindowUDF::from(AWindowUDF::new());
657        let a2 = WindowUDF::from(AWindowUDF::new());
658        let eq = a1 == a2;
659        assert!(eq);
660        assert_eq!(a1, a2);
661        assert_eq!(hash(a1), hash(a2));
662    }
663
664    #[test]
665    fn test_partial_ord() {
666        let a1 = WindowUDF::from(AWindowUDF::new());
667        let a2 = WindowUDF::from(AWindowUDF::new());
668        assert_eq!(a1.partial_cmp(&a2), Some(Ordering::Equal));
669
670        let b1 = WindowUDF::from(BWindowUDF::new());
671        assert!(a1 < b1);
672        assert!(!(a1 == b1));
673    }
674
675    fn hash<T: Hash>(value: T) -> u64 {
676        let hasher = &mut DefaultHasher::new();
677        value.hash(hasher);
678        hasher.finish()
679    }
680}