Skip to content

fix negative array subscripts should not index from the end#22302

Open
xiedeyantu wants to merge 1 commit into
apache:mainfrom
xiedeyantu:negative
Open

fix negative array subscripts should not index from the end#22302
xiedeyantu wants to merge 1 commit into
apache:mainfrom
xiedeyantu:negative

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

PostgreSQL treats negative array subscripts as out of bounds and returns NULL. DataFusion was incorrectly interpreting negative subscripts as indexing from the end of the array, which caused behavioral mismatch.

What changes are included in this PR?

  • Updated array_element / array subscript evaluation to treat non-positive indexes as out of bounds and return NULL.
  • Updated sqllogictest coverage for array subscript and array_element behavior, including the [-1] case.

Are these changes tested?

Yes.

Validated with:

  • cargo test -p datafusion-functions-nested test_array_element_non_positive_indexes_return_null
  • cargo test -p datafusion-sqllogictest --test sqllogictests array_index
  • cargo test -p datafusion-sqllogictest --test sqllogictests expr

Are there any user-facing changes?

Yes. Array subscripts with negative indexes now return NULL instead of indexing from the end, aligning DataFusion behavior with PostgreSQL.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 17, 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.

PostgreSQL compatibility: negative array subscripts should not index from the end

1 participant