shehabgamin commented on code in PR #17220:
URL: https://github.com/apache/datafusion/pull/17220#discussion_r2567260996


##########
datafusion/expr/src/udf.rs:
##########
@@ -714,6 +774,58 @@ pub trait ScalarUDFImpl: Debug + DynEq + DynHash + Send + 
Sync {
     fn documentation(&self) -> Option<&Documentation> {
         None
     }
+
+    /// Attempts to optimize or transform the function call.
+    ///
+    /// This method allows UDF implementations to provide optimized versions
+    /// of function calls or transform them into different expressions.
+    /// Returns `None` if no optimization is available.
+    ///
+    /// # Arguments
+    /// * `_args` - The function arguments to potentially optimize
+    ///
+    /// # Returns
+    /// An optional optimized expression, or None if no optimization is 
available
+    fn try_call(&self, _args: &[Expr]) -> Result<Option<Expr>> {
+        Ok(None)
+    }
+
+    /// Plans the scalar UDF implementation with lambda function support.
+    ///
+    /// This method enables UDF implementations to work with lambda functions
+    /// by allowing them to plan and prepare lambda expressions for execution.
+    /// Returns a new implementation instance if lambda planning is needed.
+    ///
+    /// # Arguments
+    /// * `_planner` - The lambda planner for converting logical lambdas to 
physical
+    /// * `_args` - The function arguments that may include lambda expressions
+    /// * `_input_dfschema` - The input schema context for lambda planning
+    ///
+    /// # Returns
+    /// An optional new UDF implementation with planned lambdas, or None if no 
planning is needed
+    fn plan(

Review Comment:
   Adding a plan function to the trait feels a bit odd. Are there any potential 
use cases for this outside of lambdas?



##########
datafusion/sql/src/expr/function.rs:
##########
@@ -270,7 +270,7 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
         // User-defined function (UDF) should have precedence
         if let Some(fm) = self.context_provider.get_function_meta(&name) {
             let args = self.function_args_to_expr(args, schema, 
planner_context)?;
-            return Ok(Expr::ScalarFunction(ScalarFunction::new_udf(fm, args)));
+            return fm.try_call(args);

Review Comment:
   The naming here is a bit confusing imo



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