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


##########
docs/source/library-user-guide/upgrading/54.0.0.md:
##########
@@ -180,29 +180,50 @@ function. The below diffs are examples from the 
associated PRs.
  }
 ```
 
-If you have a function that is downcasting a UDF, you can replace
-the call to `.as_any()` with `.as_ref() as &dyn Any`. For example
+**Execution Plans:**
+
+```diff
+ impl ExecutionPlan for MyExec {
+-    fn as_any(&self) -> &dyn Any {
+-        self
+-    }
+-
+     fn name(&self) -> &'static str {
+         "MyExec"
+     }
+
+     ...
+ }
+```
+
+If you have code that is downcasting, you can use the new `downcast_ref`
+and `is` methods defined directly on each trait object:
 
 **Before:**
 
 ```rust,ignore
-let is_async = func
-                .inner()
-                .as_any()
-                .downcast_ref::<AsyncScalarUDF>()
-                .is_some();
+let exec = plan.as_any().downcast_ref::<MyExec>().unwrap();
+let udf = scalar_udf.as_any().downcast_ref::<MyUdf>().unwrap();
 ```
 
 **After:**
 
 ```rust,ignore
-let is_async = (func
-                .inner()
-                .as_ref() as &dyn Any)
-                .downcast_ref::<AsyncScalarUDF>()
-                .is_some();
+let exec = plan.downcast_ref::<MyExec>().unwrap();
+let udf = scalar_udf.downcast_ref::<MyUdf>().unwrap();
 ```
 
+These methods are available on `dyn ExecutionPlan`, `dyn ScalarUDFImpl`,
+`dyn AggregateUDFImpl`, and `dyn WindowUDFImpl`. They work correctly
+whether the value is a bare reference or behind an `Arc` (Rust
+auto-derefs through the `Arc`).
+
+> **Warning:** Do not cast an `Arc<dyn Trait>` directly to `&dyn Any`.

Review Comment:
   is this meant to have `>` in front of it?



##########
docs/source/library-user-guide/upgrading/54.0.0.md:
##########
@@ -180,29 +180,50 @@ function. The below diffs are examples from the 
associated PRs.
  }
 ```
 
-If you have a function that is downcasting a UDF, you can replace
-the call to `.as_any()` with `.as_ref() as &dyn Any`. For example
+**Execution Plans:**
+
+```diff
+ impl ExecutionPlan for MyExec {
+-    fn as_any(&self) -> &dyn Any {
+-        self
+-    }
+-
+     fn name(&self) -> &'static str {
+         "MyExec"
+     }
+
+     ...
+ }
+```
+
+If you have code that is downcasting, you can use the new `downcast_ref`

Review Comment:
   🎉 



##########
datafusion/expr/src/udf.rs:
##########
@@ -984,6 +984,25 @@ pub trait ScalarUDFImpl: Debug + DynEq + DynHash + Send + 
Sync + Any {
     }
 }
 
+impl dyn ScalarUDFImpl {
+    /// Returns `true` if the implementation is of type `T`.

Review Comment:
   this is nice



-- 
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