goldmedal opened a new pull request, #14837: URL: https://github.com/apache/datafusion/pull/14837
## 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. --> - Closes #6518. ## Rationale for this change I have been working with @alamb to implement the functional for the async UDF. - https://github.com/goldmedal/datafusion-llm-function/pull/1 It introduces the following trait: ```rust #[async_trait] pub trait AsyncScalarUDFImpl: Debug + Send + Sync { /// the function cast as any fn as_any(&self) -> &dyn Any; /// The name of the function fn name(&self) -> &str; /// The signature of the function fn signature(&self) -> &Signature; /// The return type of the function fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType>; /// The ideal batch size for this function. /// /// This is used to determine what size of data to be evaluated at once. /// If None, the whole batch will be evaluated at once. fn ideal_batch_size(&self) -> Option<usize> { None } /// Invoke the function asynchronously with the async arguments async fn invoke_async_with_args( &self, args: AsyncScalarFunctionArgs, option: &ConfigOptions, ) -> Result<ArrayRef>; } ``` It allows the user to implement the UDF for invoking some external remote function in the query. Given an async udf `async_equal`, the plan would look like: ``` > explain select async_equal(a.id, 1) from animal a +---------------+----------------------------------------------------------------------------------------+ | plan_type | plan | +---------------+----------------------------------------------------------------------------------------+ | logical_plan | Projection: async_equal(a.id, Int64(1)) | | | SubqueryAlias: a | | | TableScan: animal projection=[id] | | physical_plan | ProjectionExec: expr=[__async_fn_0@1 as async_equal(a.id,Int64(1))] | | | AsyncFuncExec: async_expr=[async_expr(name=__async_fn_0, expr=async_equal(id@0, 1))] | | | CoalesceBatchesExec: target_batch_size=8192 | | | DataSourceExec: partitions=1, partition_sizes=[1] | | | | +---------------+----------------------------------------------------------------------------------------+ ``` To reduce the number of invoking the async function, `CoalesceAsyncExecInput` rule is used for coalescing the input batch of `AsyncFuncExec`. See the details usages in the example. <!-- 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. --> ## What changes are included in this PR? ### Remaining Work - [x] Support for ProjectExec - [x] Support for FilterExec - [ ] Support for Join Expression ### Maybe implement in the follow-up PR - [ ] Async aggregation function - [ ] Async window function - [ ] Async table function (? <!-- 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 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-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org