-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(core): Correctly handle nested async UDF execution #20039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tushar7012
wants to merge
5
commits into
apache:main
Choose a base branch
from
Tushar7012:fix/nested-async-udfs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a8e2e8
fix(core): Correctly handle nested async UDF execution
Tushar7012 82424ad
fix(core): Add regression test for nested async UDFs
Tushar7012 b6ef125
fix(checker): Resolve clippy::useless_vec in async scalar function tests
Tushar7012 cfdd6ba
fix: resolve clippy warnings in async scalar functions test
Tushar7012 d9928f1
chore: run cargo fmt
Tushar7012 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,10 @@ use std::sync::Arc; | |
| use arrow::array::{Int32Array, RecordBatch, StringArray}; | ||
| use arrow::datatypes::{DataType, Field, Schema}; | ||
| use async_trait::async_trait; | ||
| use datafusion::prelude::*; | ||
| use datafusion::dataframe::DataFrame; | ||
| use datafusion::execution::context::SessionContext; | ||
| use datafusion_common::Result; | ||
| use datafusion_common::test_util::format_batches; | ||
| use datafusion_common::{Result, assert_batches_eq}; | ||
| use datafusion_expr::async_udf::{AsyncScalarUDF, AsyncScalarUDFImpl}; | ||
| use datafusion_expr::{ | ||
| ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility, | ||
|
|
@@ -66,24 +67,24 @@ fn register_table_and_udf() -> Result<SessionContext> { | |
| async fn test_async_udf_with_non_modular_batch_size() -> Result<()> { | ||
| let ctx = register_table_and_udf()?; | ||
|
|
||
| let df = ctx | ||
| let df: DataFrame = ctx | ||
| .sql("SELECT id, test_async_udf(prompt) as result FROM test_table") | ||
| .await?; | ||
|
|
||
| let result = df.collect().await?; | ||
|
|
||
| assert_batches_eq!( | ||
| &[ | ||
| "+----+---------+", | ||
| "| id | result |", | ||
| "+----+---------+", | ||
| "| 0 | prompt0 |", | ||
| "| 1 | prompt1 |", | ||
| "| 2 | prompt2 |", | ||
| "+----+---------+" | ||
| ], | ||
| &result | ||
| ); | ||
| let result: Vec<RecordBatch> = df.collect().await?; | ||
|
|
||
| let result_str = format_batches(&result)?.to_string(); | ||
| let expected = [ | ||
| "+----+---------+", | ||
| "| id | result |", | ||
| "+----+---------+", | ||
| "| 0 | prompt0 |", | ||
| "| 1 | prompt1 |", | ||
| "| 2 | prompt2 |", | ||
| "+----+---------+", | ||
| ] | ||
| .join("\n"); | ||
| assert_eq!(result_str.trim(), expected.trim()); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
@@ -93,13 +94,13 @@ async fn test_async_udf_with_non_modular_batch_size() -> Result<()> { | |
| async fn test_async_udf_metrics() -> Result<()> { | ||
| let ctx = register_table_and_udf()?; | ||
|
|
||
| let df = ctx | ||
| let df: DataFrame = ctx | ||
| .sql( | ||
| "EXPLAIN ANALYZE SELECT id, test_async_udf(prompt) as result FROM test_table", | ||
| ) | ||
| .await?; | ||
|
|
||
| let result = df.collect().await?; | ||
| let result: Vec<RecordBatch> = df.collect().await?; | ||
|
|
||
| let explain_analyze_str = format_batches(&result)?.to_string(); | ||
| let async_func_exec_without_metrics = | ||
|
|
@@ -113,6 +114,43 @@ async fn test_async_udf_metrics() -> Result<()> { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_nested_async_udf() -> Result<()> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably omit the changes to this file; SLT is sufficient for testing purposes |
||
| let ctx = register_table_and_udf()?; | ||
|
|
||
| let df: DataFrame = ctx | ||
| .sql( | ||
| "SELECT id, test_async_udf(test_async_udf(prompt)) as result FROM test_table", | ||
| ) | ||
| .await?; | ||
|
|
||
| let result: Result<Vec<RecordBatch>> = df.collect().await; | ||
|
|
||
| // This is expected to succeed now | ||
| match &result { | ||
| Ok(batches) => { | ||
| // Check results | ||
| let result_str = format_batches(batches)?.to_string(); | ||
| let expected = [ | ||
| "+----+---------+", | ||
| "| id | result |", | ||
| "+----+---------+", | ||
| "| 0 | prompt0 |", | ||
| "| 1 | prompt1 |", | ||
| "| 2 | prompt2 |", | ||
| "+----+---------+", | ||
| ] | ||
| .join("\n"); | ||
| assert_eq!(result_str.trim(), expected.trim()); | ||
| } | ||
| Err(e) => { | ||
| panic!("Nested async UDF failed: {e}"); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[derive(Debug, PartialEq, Eq, Hash, Clone)] | ||
| struct TestAsyncUDFImpl { | ||
| batch_size: usize, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using
into_iterto avoid the clone, for example: