Skip to content

fix: return error instead of capacity overflow panic in generate_series#22323

Queued
sweb wants to merge 2 commits into
apache:mainfrom
sweb:fix-generate-series-capacity-overflow-panic
Queued

fix: return error instead of capacity overflow panic in generate_series#22323
sweb wants to merge 2 commits into
apache:mainfrom
sweb:fix-generate-series-capacity-overflow-panic

Conversation

@sweb
Copy link
Copy Markdown
Contributor

@sweb sweb commented May 18, 2026

Which issue does this PR close?

Rationale for this change

Captured in issue description

What changes are included in this PR?

Bounds the element count at isize:MAX / size_of::<i64>() in generate_range_values and returns a DataFusion execution error when the limit is exceeded, so the function returns a normal DataFusion error instead of panicking inside Vec::reserve.

Only the scalar UDF path path in datafusion/functions-nested/src/range.rs is affected, the table-valued generate_series already streams and is unchanged.

This PR just takes care of the panic and does not attempt a larger refactor towards streaming or introducing a max-elements config value. Happy to follow up on either.

Are these changes tested?

Added sqllogictest to tests in datafusion/sqllogictest/test_files/array/array_range.slt to cover the issues presented in the issue.

Are there any user-facing changes?

Queries that previously crashed the process with capacity overflow now returns Execution error: Range too large to materialize: would produce {count} elements ({MAX_RANGE_ELEMENTS})

Behavior for valid ranges is unchanged.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 18, 2026
@sweb sweb force-pushed the fix-generate-series-capacity-overflow-panic branch from 9f39638 to 62bc4a4 Compare May 18, 2026 07:56
Comment thread datafusion/functions-nested/src/range.rs
Copy link
Copy Markdown
Contributor

@2010YOUY01 2010YOUY01 left a comment

Choose a reason for hiding this comment

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

Thank you!

@Dandandan Dandandan added this pull request to the merge queue May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: capacity overflow in generate_series / range with large i64 arguments

2 participants