You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "edmondop (via GitHub)" <gi...@apache.org> on 2023/12/06 18:07:10 UTC

Re: [I] Support `Expr` creation for `ScalarUDF`: Resolve function calls by name during planning [arrow-datafusion]

edmondop commented on issue #8157:
URL: https://github.com/apache/arrow-datafusion/issues/8157#issuecomment-1843411377

   @alamb I checked out and on main the structs and enums are already written as you recommended
   
   ```rust
   pub enum ScalarFunctionDefinition {
     /// Resolved to a built in scalar function
     /// (will be removed long term)
     BuiltIn(built_in_function::BuiltinScalarFunction),
     /// Resolved to a user defined function
     UDF(ScalarUDF),
     /// A scalar function that will be called by name
     Name(Arc<str>),
   }
   
   #[derive(Clone, PartialEq, Eq, Hash, Debug)]
   pub struct ScalarFunction {
       /// The function
       pub fun: ScalarFunctionDefinition,
       /// List of expressions to feed to the functions as arguments
       pub args: Vec<Expr>,
   }
   ``` 
   
   So I am not sure I understood correctly. I could see that `call_fn` resolves at invocation site rather than at planning site,  and changing the behavior would probably mean changing this code. What is the right type of Expr this code should return?
   ```rust
   /// Calls a named built in function
   /// ```
   /// use datafusion_expr::{col, lit, call_fn};
   ///
   /// // create the expression sin(x) < 0.2
   /// let expr = call_fn("sin", vec![col("x")]).unwrap().lt(lit(0.2));
   /// ```
   pub fn call_fn(name: impl AsRef<str>, args: Vec<Expr>) -> Result<Expr> {
       match name.as_ref().parse::<BuiltinScalarFunction>() {
           Ok(fun) => Ok(Expr::ScalarFunction(ScalarFunction::new(fun, args))),
           Err(e) => Err(e),
       }
   }
   ```


-- 
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-unsubscribe@arrow.apache.org

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