Skip to content

Expand scalar async UDF results to the batch row count - #25828

Merged
Jefffrey merged 2 commits into
apache:mainfrom
hareshkh:hareshkh/async-udf-batch-size
Sep 30, 2026
Merged

Jefffrey merged 2 commits into
apache:mainfrom
hareshkh:hareshkh/async-udf-batch-size

Conversation

@hareshkh

@hareshkh hareshkh commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

When an async UDF returns a ColumnarValue::Scalar (e.g. all arguments are literals), queries on more than one row fail with all columns in a record batch must have the same length.

What changes are included in this PR?

AsyncFuncExpr::invoke_with_args expands each result to its chunk's row count via into_array_of_size, instead of turning a scalar into a 1-row array.

What is the testing strategy for this PR?

Added test_async_udf_with_scalar_result in user_defined_async_scalar_functions.rs. It fails without the fix.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates core Core DataFusion crate labels Sep 28, 2026
// scalar applies to every row, so it must be expanded to the number of rows in
// each chunk rather than to a single row.
#[tokio::test]
async fn test_async_udf_with_scalar_result() -> Result<()> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix fails with:

Error: ArrowError(InvalidArgumentError("all columns in a record batch must have the same length"), Some(""))

@codecov-commenter

codecov-commenter commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.59%. Comparing base (dd1d709) to head (5c19827).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...afusion/physical-expr/src/async_scalar_function.rs 20.00% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25828      +/-   ##
==========================================
- Coverage   82.59%   82.59%   -0.01%     
==========================================
  Files        1144     1144              
  Lines      441854   441849       -5     
  Branches   441854   441849       -5     
==========================================
- Hits       364965   364951      -14     
- Misses      54809    54815       +6     
- Partials    22080    22083       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hareshkh
hareshkh marked this pull request as ready for review September 28, 2026 13:30

@xanderbailey xanderbailey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified that the test fails before the fix. Thanks @hareshkh great find!

@hareshkh

Copy link
Copy Markdown
Contributor Author

@alamb @Jefffrey: Sorry for the direct tag, but I saw that you have reviewed code in these files before. Can you please take a look?

@Jefffrey Jefffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its unfortunate that we cant exactly reap the benefits of ColumnarValue::Scalar here and are always forced to expand to arrays, though with how this code is structured (compared to its sync counterpart) i suppose it might be hard to do without a wider refactor

fix makes sense, thanks for the ping 👍

@Jefffrey
Jefffrey enabled auto-merge September 30, 2026 13:42
@Jefffrey

Copy link
Copy Markdown
Contributor

thanks @hareshkh & @xanderbailey

@Jefffrey
Jefffrey added this pull request to the merge queue Sep 30, 2026
Merged via the queue into apache:main with commit 1aed7dc Sep 30, 2026
42 checks passed
Omega359 pushed a commit to Omega359/arrow-datafusion that referenced this pull request Oct 11, 2026
## Which issue does this PR close?

- Closes apache#25875

## Rationale for this change

When an async UDF returns a `ColumnarValue::Scalar` (e.g. all arguments
are literals), queries on more than one row fail with `all columns in a
record batch must have the same length`.

## What changes are included in this PR?

`AsyncFuncExpr::invoke_with_args` expands each result to its chunk's row
count via `into_array_of_size`, instead of turning a scalar into a 1-row
array.

## What is the testing strategy for this PR?

Added `test_async_udf_with_scalar_result` in
`user_defined_async_scalar_functions.rs`. It fails without the fix.

## Are there any user-facing changes?

No.
alamb pushed a commit that referenced this pull request Nov 12, 2026
…25828) (#27372)

- Backport of #25828 to `branch-54`
- Part of #23805

Co-authored-by: Haresh Khanna <[email protected]>
alamb pushed a commit that referenced this pull request Nov 12, 2026
…25828) (#27373)

- Backport of #25828 to `branch-55`
- Part of #26868

Co-authored-by: Haresh Khanna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-expr Changes to the physical-expr crates v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Async UDF returning a scalar fails with "all columns in a record batch must have the same length"

4 participants