kosiew commented on code in PR #17081:
URL: https://github.com/apache/datafusion/pull/17081#discussion_r2266911805


##########
datafusion/expr/src/udwf.rs:
##########
@@ -82,15 +82,15 @@ impl Display for WindowUDF {
 
 impl PartialEq for WindowUDF {
     fn eq(&self, other: &Self) -> bool {
-        self.inner.equals(other.inner.as_ref())
+        self.inner.dyn_eq(&other.inner)
     }

Review Comment:
   should this be 
   ```rust
   self.inner.as_ref().dyn_eq(other.inner.as_ref().as_any())
   ```
   to ensure the implementor’s dyn_eq sees &dyn Any of the concrete type (F), 
making the downcast succeed when appropriate.



##########
datafusion/expr/src/udwf.rs:
##########
@@ -229,6 +229,10 @@ where
 /// 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
+/// blanked implementations of [`DynEq`] and [`DynHash`].

Review Comment:
   ```suggestion
   /// blanket implementations of [`DynEq`] and [`DynHash`].
   ```



##########
datafusion/expr-common/src/dyn_eq.rs:
##########
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::any::Any;
+use std::hash::{Hash, Hasher};
+
+/// A dyn-compatible version of [`Eq`] trait.
+/// The implementation constraints for this trait are the same as for [`Eq`]:
+/// the implementation must be reflexive, symmetric, and transitive.
+/// Additionally, if two values can be compared with [`DynEq`] and 
[`PartialEq`] then
+/// they must be [`DynEq`]-equal if and only if they are [`PartialEq`]-equal.
+/// It is therefore strongly discouraged to implement this trait for types
+/// that implement `PartialEq<Other>` or `Eq<Other>` for any type `Other` 
other than `Self`.
+///
+/// Note: This trait should not be implemented directly. Implement `Eq` and 
`Any` and use
+/// the blanket implementation.
+pub trait DynEq {
+    fn dyn_eq(&self, other: &dyn Any) -> bool;
+
+    fn 
i_did_not_implement_the_trait_directly_but_using_the_blanked_impl_instead()

Review Comment:
   This doesn’t prevent downstream manual impls. Maybe use the sealed-trait 
pattern instead?
   
   ```rust
   /// Sealed traits, not exported outside this module. Only types in this crate
   /// implementing `Eq + Any` (resp. `Hash + Any`) get these impls.
   mod sealed {
       use super::*;
   
       pub trait DynEqSealed {}
       impl<T: Eq + Any> DynEqSealed for T {}
   
       pub trait DynHashSealed {}
       impl<T: Hash + Any> DynHashSealed for T {}
   }
   
   /// A dyn-compatible version of [`Eq`] trait.
   /// Now sealed, so external crates cannot impl this themselves.
   pub trait DynEq: sealed::DynEqSealed {
       fn dyn_eq(&self, other: &dyn Any) -> bool;
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to