2010YOUY01 opened a new pull request, #8258:
URL: https://github.com/apache/arrow-datafusion/pull/8258

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   Part of https://github.com/apache/arrow-datafusion/issues/8157
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.  
   -->
   See #8157 for the rationale:
   Creation of `Expr`s for `BuiltinScalarFunctions` can be done statelessly
   ```rust
   let expr1 = abs(lit(-1));
   let expr2 = call_fn("abs", vec![lit(-1)]);
   ```
   However, we can't do that for ScalarUDFs because they are registered within 
`SessionState`, it's only possible to do
   ```rust
   let ctx = create_context()?;
   ctx.register_udf(abs_impl);
   let expr2 = ctx.call_fn("abs", vec![lit(-1)]);
   ```
   For the ongoing plan to migrate functions from `BuiltinScalarFunction` to 
`ScalarUDF` based implementation (ref #8045 ), we would like the `ScalarUDF` 
based functions to continue to support the original `Expr` construction API, so 
the `Expr` struct should have a variant for unresolved name, and then we can 
add a `AnalyzerRule` to resolve the function.
   This PR only include refactor preparation for UDF `Expr` support.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   1. Change `Expr::ScalarFunction` 
   ```rust
   // before
   pub struct ScalarFunction {
       /// The function
       pub fun: built_in_function::BuiltinScalarFunction,
       /// List of expressions to feed to the functions as arguments
       pub args: Vec<Expr>,
   }
   // This PR
   #[derive(Debug, Clone, PartialEq, Eq, Hash)]
   pub enum ScalarFunctionDefinition {
       /// Resolved to a `BuiltinScalarFunction`
       /// There is plan to migrate `BuiltinScalarFunction` to UDF-based 
implementation (issue#8045)
       /// This variant is planned to be removed in long term
       BuiltIn(built_in_function::BuiltinScalarFunction),
       /// Resolved to a user defined function
       UDF(Arc<crate::ScalarUDF>),
       /// A scalar function constructed with name, could be resolved with 
registered functions during
       /// analyzing.
       Name(Arc<str>),
   }
   
   /// ScalarFunction expression invokes a built-in scalar function
   #[derive(Clone, PartialEq, Eq, Hash, Debug)]
   pub struct ScalarFunction {
       /// The function
       pub func_def: ScalarFunctionDefinition,
       /// List of expressions to feed to the functions as arguments
       pub args: Vec<Expr>,
   }
   ```
   2. Remove `Expr::ScalarUDF`
   
   This way we can support unresolved function name variant.
   Also, merge the execution path for `BuiltinScalarFunction`/`ScalarUDF`, to 
make future work towards #8045 a bit easier
   
   ## Are these changes tested?
   Covered by existing tests.
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   4. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   Yes, see comments for API changes
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


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

Reply via email to