You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2024/11/20 22:44:39 UTC

[PR] ScalarUDFImpl invoke improvements [datafusion]

alamb opened a new pull request, #13507:
URL: https://github.com/apache/datafusion/pull/13507

   Builds on https://github.com/apache/datafusion/pull/13290 from @joseph-isaacs
   
   ## Which issue does this PR close?
   
   Follow on to 
   - https://github.com/apache/datafusion/pull/13290
   
   ## Rationale for this change
   
   If we are going to change the signature of `invoke` I would to make it possible in the future to reuse allocations -- at the moment the API requires creating new arrays even when the input array is not used because the functions get the input as `&[ColumnarValues]` meaning they don't own them (the caller retains a reference)
   
   ## What changes are included in this PR?
   
   Change ScalarFunctionArgs to pass by value
   
   1, 
   ## 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
   2. 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.
   -->
   
   <!--
   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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] ScalarUDFImpl invoke improvements [datafusion]

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

   > > * Closes [Perf: Allow User defined functions to potentially reuse their argument arrays (to avoid new allocations) #13516](https://github.com/apache/datafusion/issues/13516)
   > 
   > Can we have one example function doing that, with some tests proving this indeed works?
   
   Just OCD following up here, there is an example / tests in this PR:
   - https://github.com/apache/datafusion/pull/13637


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] ScalarUDFImpl invoke improvements [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 closed pull request #13507: ScalarUDFImpl invoke improvements
URL: https://github.com/apache/datafusion/pull/13507


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] ScalarUDFImpl invoke improvements [datafusion]

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

   > * Closes [Perf: Allow User defined functions to potentially reuse their argument arrays (to avoid new allocations) #13516](https://github.com/apache/datafusion/issues/13516)
   
   Can we have one example function doing that, with some tests proving this indeed works?


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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] ScalarUDFImpl invoke improvements [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13507:
URL: https://github.com/apache/datafusion/pull/13507#discussion_r1851080564


##########
datafusion/physical-expr/src/scalar_function.rs:
##########
@@ -140,18 +140,23 @@ impl PhysicalExpr for ScalarFunctionExpr {
             .map(|e| e.evaluate(batch))
             .collect::<Result<Vec<_>>>()?;
 
+        let inputs_all_scalars = !inputs.is_empty() && inputs
+            .iter()
+            .all(|arg| matches!(arg, ColumnarValue::Scalar(_)));
+
         // evaluate the function
-        let output = self.fun.invoke_batch(&inputs, batch.num_rows())?;
+        let output = self.fun.invoke_with_args(ScalarFunctionArgs {
+            args: inputs,

Review Comment:
   Eventually we should probably consider doing the same thing for `evaluate` 🤔 



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] ScalarUDFImpl invoke improvements [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13507:
URL: https://github.com/apache/datafusion/pull/13507#discussion_r1851080094


##########
datafusion/physical-expr/src/scalar_function.rs:
##########
@@ -140,18 +140,23 @@ impl PhysicalExpr for ScalarFunctionExpr {
             .map(|e| e.evaluate(batch))
             .collect::<Result<Vec<_>>>()?;
 
+        let inputs_all_scalars = !inputs.is_empty() && inputs
+            .iter()
+            .all(|arg| matches!(arg, ColumnarValue::Scalar(_)));
+
         // evaluate the function
-        let output = self.fun.invoke_batch(&inputs, batch.num_rows())?;
+        let output = self.fun.invoke_with_args(ScalarFunctionArgs {
+            args: inputs,

Review Comment:
   the whole point of this PR is to pass in `inputs` here rather than inputs.as_ref



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org