You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "2010YOUY01 (via GitHub)" <gi...@apache.org> on 2023/11/14 23:44:48 UTC

[PR] Draft: Extend `Expr::ScalarFunction` to support `Expr` for `ScalarUDF` [arrow-datafusion]

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

   ## 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.
   -->
   
   POC for 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.  
   -->
   Based on discussion in #8157 , there are two ways to implement `Expr` creation for `ScalarUDF`:
   1. Reuse `Expr::ScalarUDF`
   2. Extend `Expr::ScalarFunction`
   
   This draft wants to show how approach 2 will look like
   pro: This way can encapsulate the execution path for `BuitlinScalarFunction` and `ScalarUDF` together (but actually is a slight cleanup instead of unification), which can make future work toward #8045 a little bit easier (when debugging core during migration)
   con: Larger modifications to the core code (see comments)
   
   I don't have a strong preference between 1 and 2 for the above reasons, is there any other concerns for approach 1? @alamb 
   
   ## 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.
   -->
   
   ## Are these changes tested?
   
   <!--
   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?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   Yes, see comments
   <!--
   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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Draft: Extend `Expr::ScalarFunction` to support `Expr` for `ScalarUDF` [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8180:
URL: https://github.com/apache/arrow-datafusion/pull/8180#issuecomment-1813059404

   This looks pretty neat @2010YOUY01 
   
   > I don't have a strong preference between 1 and 2 for the above reasons, is there any other concerns for approach 1? @alamb
   
   I am not sure of other concerns -- perhaps it is worth doing a quick prototype / POC, similar to this PR,  of what approach 1 would  look like?
   
   


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


Re: [PR] Draft: Extend `Expr::ScalarFunction` to support `Expr` for `ScalarUDF` [arrow-datafusion]

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #8180:
URL: https://github.com/apache/arrow-datafusion/pull/8180#discussion_r1393450192


##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -89,25 +89,39 @@ impl ExprSchemable for Expr {
                     .collect::<Result<Vec<_>>>()?;
                 Ok((fun.return_type)(&data_types)?.as_ref().clone())
             }
-            Expr::ScalarFunction(ScalarFunction { fun, args }) => {
-                let arg_data_types = args
-                    .iter()
-                    .map(|e| e.get_type(schema))
-                    .collect::<Result<Vec<_>>>()?;
-
-                // verify that input data types is consistent with function's `TypeSignature`
-                data_types(&arg_data_types, &fun.signature()).map_err(|_| {
-                    plan_datafusion_err!(
-                        "{}",
-                        utils::generate_signature_error_msg(
-                            &format!("{fun}"),
-                            fun.signature(),
-                            &arg_data_types,
-                        )
-                    )
-                })?;
-
-                fun.return_type(&arg_data_types)
+            Expr::ScalarFunction(ScalarFunction { func_def, args }) => {

Review Comment:
   There might have ~10 similar changes like this one during optimization/planning.
   `Expr::ScalarUDF` branch above will be moved inside



##########
datafusion/expr/src/expr.rs:
##########
@@ -338,19 +338,33 @@ impl Between {
     }
 }
 
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+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(crate::ScalarUDF),
+    /// A scalar function that will be called by name
+    Name(Arc<str>),
+}
+
 /// ScalarFunction expression
 #[derive(Clone, PartialEq, Eq, Hash, Debug)]
 pub struct ScalarFunction {
     /// The function
-    pub fun: built_in_function::BuiltinScalarFunction,
+    pub func_def: ScalarFunctionDefinition,

Review Comment:
   This is the API change



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


Re: [PR] Draft: Extend `Expr::ScalarFunction` to support `Expr` for `ScalarUDF` [arrow-datafusion]

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 closed pull request #8180: Draft: Extend `Expr::ScalarFunction` to support `Expr` for `ScalarUDF`
URL: https://github.com/apache/arrow-datafusion/pull/8180


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