Skip to content

Prevent array_position panic for minimum start positions - #24838

Open
1fanwang wants to merge 2 commits into
apache:mainfrom
1fanwang:fix-array-position-min-start
Open

Prevent array_position panic for minimum start positions#24838
1fanwang wants to merge 2 commits into
apache:mainfrom
1fanwang:fix-array-position-min-start

Conversation

@1fanwang

@1fanwang 1fanwang commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

array_position accepts an optional one-based start position. Passing -9223372036854775808 currently aborts evaluation with:

datafusion/functions-nested/src/position.rs:210:21:
attempt to subtract with overflow

It now returns the normal execution error start_from out of bounds: -9223372036854775808.

What changes are included in this PR?

The one-based-to-zero-based conversion now uses checked subtraction in both optimized and generic execution paths.

What is the testing strategy for this PR?

SQL regressions exercise a scalar start position, a column start position with a scalar needle, and column start and needle values.

Raw results
$ git checkout upstream/main -- datafusion/functions-nested/src/position.rs
$ cargo test -p datafusion-sqllogictest --test sqllogictests -- array_position
thread 'tokio-rt-worker' panicked at datafusion/functions-nested/src/position.rs:210:21:
attempt to subtract with overflow
Error: Execution("1 failures")

$ git checkout HEAD -- datafusion/functions-nested/src/position.rs
$ cargo test -p datafusion-sqllogictest --test sqllogictests -- array_position
Running with 12 test threads (available parallelism: 12)
Progress: 1/1 files completed (100%)

$ RUST_BACKTRACE=1 cargo test --profile ci \
    --exclude datafusion-examples --exclude datafusion-benchmarks --exclude datafusion-cli \
    --workspace --lib --tests --bins \
    --features avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption
passed=10997 ignored=8

Are there any user-facing changes?

Yes. An invalid minimum Int64 start position returns an execution error instead of panicking.

The one-based start offset accepts any Int64 input. Subtracting one from i64::MIN currently panics in debug builds instead of returning a normal execution error.

Generated-by: GitHub Copilot CLI (GPT-5.6 Sol)
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Sep 1, 2026
Comment thread datafusion/functions-nested/src/position.rs Outdated
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.58%. Comparing base (17547e2) to head (c120f4d).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/functions-nested/src/position.rs 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24838   +/-   ##
=======================================
  Coverage   81.58%   81.58%           
=======================================
  Files        1123     1123           
  Lines      406743   406751    +8     
  Branches   406743   406751    +8     
=======================================
+ Hits       331840   331848    +8     
- Misses      55464    55465    +1     
+ Partials    19439    19438    -1     

☔ 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.

The overflow error named the rejected value but not what the function
would have accepted, so a reader could not tell which inputs are valid.

Generated-by: GitHub Copilot CLI (Claude Opus 5)
Signed-off-by: 1fanwang <1fannnw@gmail.com>

@jayzhan211 jayzhan211 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.

Thanks @1fanwang , LGTM

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: array_position underflows start_from at i64::MIN

4 participants