1919
2020use arrow:: compute:: SortOptions ;
2121use std:: cmp:: Ordering ;
22- use std:: hash:: { DefaultHasher , Hash , Hasher } ;
22+ use std:: hash:: { Hash , Hasher } ;
2323use std:: {
2424 any:: Any ,
2525 fmt:: { self , Debug , Display , Formatter } ,
@@ -31,11 +31,11 @@ use arrow::datatypes::{DataType, FieldRef};
3131use crate :: expr:: WindowFunction ;
3232use crate :: udf_eq:: UdfEq ;
3333use crate :: {
34- function:: WindowFunctionSimplification , udf_equals_hash, Expr , PartitionEvaluator ,
35- Signature ,
34+ function:: WindowFunctionSimplification , Expr , PartitionEvaluator , Signature ,
3635} ;
3736use datafusion_common:: { not_impl_err, Result } ;
3837use datafusion_doc:: Documentation ;
38+ use datafusion_expr_common:: dyn_eq:: { DynEq , DynHash } ;
3939use datafusion_functions_window_common:: expr:: ExpressionArgs ;
4040use datafusion_functions_window_common:: field:: WindowUDFFieldArgs ;
4141use datafusion_functions_window_common:: partition:: PartitionEvaluatorArgs ;
@@ -82,15 +82,15 @@ impl Display for WindowUDF {
8282
8383impl PartialEq for WindowUDF {
8484 fn eq ( & self , other : & Self ) -> bool {
85- self . inner . equals ( other. inner . as_ref ( ) )
85+ self . inner . dyn_eq ( & other. inner )
8686 }
8787}
8888
8989impl Eq for WindowUDF { }
9090
9191impl Hash for WindowUDF {
9292 fn hash < H : Hasher > ( & self , state : & mut H ) {
93- self . inner . hash_value ( ) . hash ( state)
93+ self . inner . dyn_hash ( state)
9494 }
9595}
9696
@@ -246,7 +246,7 @@ where
246246/// # use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
247247/// # use datafusion_expr::window_doc_sections::DOC_SECTION_ANALYTICAL;
248248///
249- /// #[derive(Debug, Clone)]
249+ /// #[derive(Debug, Clone, PartialEq, Eq, Hash )]
250250/// struct SmoothIt {
251251/// signature: Signature,
252252/// }
@@ -305,7 +305,7 @@ where
305305/// .build()
306306/// .unwrap();
307307/// ```
308- pub trait WindowUDFImpl : Debug + Send + Sync {
308+ pub trait WindowUDFImpl : Debug + DynEq + DynHash + Send + Sync {
309309 /// Returns this object as an [`Any`] trait object
310310 fn as_any ( & self ) -> & dyn Any ;
311311
@@ -358,41 +358,6 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
358358 None
359359 }
360360
361- /// Return true if this window UDF is equal to the other.
362- ///
363- /// Allows customizing the equality of window UDFs.
364- /// *Must* be implemented explicitly if the UDF type has internal state.
365- /// Must be consistent with [`Self::hash_value`] and follow the same rules as [`Eq`]:
366- ///
367- /// - reflexive: `a.equals(a)`;
368- /// - symmetric: `a.equals(b)` implies `b.equals(a)`;
369- /// - transitive: `a.equals(b)` and `b.equals(c)` implies `a.equals(c)`.
370- ///
371- /// By default, compares type, [`Self::name`], [`Self::aliases`] and [`Self::signature`].
372- fn equals ( & self , other : & dyn WindowUDFImpl ) -> bool {
373- self . as_any ( ) . type_id ( ) == other. as_any ( ) . type_id ( )
374- && self . name ( ) == other. name ( )
375- && self . aliases ( ) == other. aliases ( )
376- && self . signature ( ) == other. signature ( )
377- }
378-
379- /// Returns a hash value for this window UDF.
380- ///
381- /// Allows customizing the hash code of window UDFs.
382- /// *Must* be implemented explicitly whenever [`Self::equals`] is implemented.
383- ///
384- /// Similarly to [`Hash`] and [`Eq`], if [`Self::equals`] returns true for two UDFs,
385- /// their `hash_value`s must be the same.
386- ///
387- /// By default, it only hashes the type. The other fields are not hashed, as usually the
388- /// name, signature, and aliases are implied by the UDF type. Recall that UDFs with state
389- /// (and thus possibly changing fields) must override [`Self::equals`] and [`Self::hash_value`].
390- fn hash_value ( & self ) -> u64 {
391- let hasher = & mut DefaultHasher :: new ( ) ;
392- self . as_any ( ) . type_id ( ) . hash ( hasher) ;
393- hasher. finish ( )
394- }
395-
396361 /// The [`FieldRef`] of the final result of evaluating this window function.
397362 ///
398363 /// Call `field_args.name()` to get the fully qualified name for defining
@@ -461,7 +426,7 @@ pub enum ReversedUDWF {
461426
462427impl PartialEq for dyn WindowUDFImpl {
463428 fn eq ( & self , other : & Self ) -> bool {
464- self . equals ( other)
429+ self . dyn_eq ( other. as_any ( ) )
465430 }
466431}
467432
@@ -533,8 +498,6 @@ impl WindowUDFImpl for AliasedWindowUDFImpl {
533498 self . inner . simplify ( )
534499 }
535500
536- udf_equals_hash ! ( WindowUDFImpl ) ;
537-
538501 fn field ( & self , field_args : WindowUDFFieldArgs ) -> Result < FieldRef > {
539502 self . inner . field ( field_args)
540503 }
@@ -598,7 +561,7 @@ mod test {
598561 use std:: any:: Any ;
599562 use std:: cmp:: Ordering ;
600563
601- #[ derive( Debug , Clone ) ]
564+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
602565 struct AWindowUDF {
603566 signature : Signature ,
604567 }
@@ -637,7 +600,7 @@ mod test {
637600 }
638601 }
639602
640- #[ derive( Debug , Clone ) ]
603+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
641604 struct BWindowUDF {
642605 signature : Signature ,
643606 }
0 commit comments