alamb commented on code in PR #22559:
URL: https://github.com/apache/datafusion/pull/22559#discussion_r3312514274


##########
datafusion/physical-plan/src/execution_plan.rs:
##########
@@ -115,6 +115,26 @@ pub trait ExecutionPlan: Any + Debug + DisplayAs + Send + 
Sync {
         }
     }
 
+    /// Returns the plan that provides this plan's public
+    /// [`ExecutionPlan`] downcast identity.
+    ///
+    /// This hook is for wrapper nodes that delegate their public downcast
+    /// identity to another plan while adding cross-cutting behavior such as
+    /// instrumentation. The default implementation returns `None`, meaning 
this
+    /// plan's concrete type is used for type introspection.
+    ///
+    /// The `is` and `downcast_ref` helpers follow the returned delegate 
instead

Review Comment:
   It might be good to add a specific example here (like a wrapper node that 
wants to observe changes but still be treated as the underlying node when 
DataFusion checks for patterns using `downcast` 🤔 
   
   



##########
datafusion/physical-plan/src/execution_plan.rs:
##########
@@ -718,20 +738,32 @@ pub trait ExecutionPlan: Any + Debug + DisplayAs + Send + 
Sync {
 impl dyn ExecutionPlan {
     /// Returns `true` if the plan is of type `T`.
     ///
+    /// If this plan provides a [`ExecutionPlan::downcast_delegate`], delegates
+    /// to it.
+    ///
     /// Prefer this over `downcast_ref::<T>().is_some()`. Works correctly when
     /// called on `Arc<dyn ExecutionPlan>` via auto-deref.
     pub fn is<T: ExecutionPlan>(&self) -> bool {
-        (self as &dyn Any).is::<T>()
+        match self.downcast_delegate() {
+            Some(delegate) => delegate.is::<T>(),
+            None => (self as &dyn Any).is::<T>(),
+        }

Review Comment:
   Should we revert the hew `:Any` instead? I think it was just supposed to be 
a cleanup but we didn't realize it would have downstream impacts 🤔 



##########
datafusion/physical-plan/src/execution_plan.rs:
##########
@@ -718,20 +738,32 @@ pub trait ExecutionPlan: Any + Debug + DisplayAs + Send + 
Sync {
 impl dyn ExecutionPlan {
     /// Returns `true` if the plan is of type `T`.
     ///
+    /// If this plan provides a [`ExecutionPlan::downcast_delegate`], delegates
+    /// to it.
+    ///
     /// Prefer this over `downcast_ref::<T>().is_some()`. Works correctly when
     /// called on `Arc<dyn ExecutionPlan>` via auto-deref.
     pub fn is<T: ExecutionPlan>(&self) -> bool {
-        (self as &dyn Any).is::<T>()
+        match self.downcast_delegate() {
+            Some(delegate) => delegate.is::<T>(),
+            None => (self as &dyn Any).is::<T>(),
+        }

Review Comment:
   Also I wonder if there is some way to avoid using `as_any` / delegating 
logic at all ... But to do that we would have to remove all uses of `as_any` / 
`downcasting` I suspect



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to