Skip to content

Fix array_position on empty list #16292

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Blizzara
Copy link
Contributor

@Blizzara Blizzara commented Jun 6, 2025

Which issue does this PR close?

array_position would fail if its input is an empty list.

1. query failed: DataFusion error: Internal error: start_from index out of bounds.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker
[SQL] select array_position([], 1);

Rationale for this change

Empty list shouldn't be any different from any other list not containing the looked-for element.

What changes are included in this PR?

Fix the empty list case. Also document that return value is NULL if element is not found, and that the start-index is 1-based (since that was confusing me for a while).

Are these changes tested?

New SLT tests

Are there any user-facing changes?

Less crashing and more info in docs 😄

@Blizzara Blizzara force-pushed the avo/array-position-empty-array branch from 6fec731 to e0772b2 Compare June 6, 2025 16:02
@github-actions github-actions bot added documentation Improvements or additions to documentation sqllogictest SQL Logic Tests (.slt) labels Jun 6, 2025
@Blizzara Blizzara force-pushed the avo/array-position-empty-array branch from e0772b2 to a32363a Compare June 6, 2025 16:05
@Blizzara Blizzara changed the title add a failing example test for array_position on empty list Fix array_position on empty list Jun 6, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Off by one error -- classic.

Thank you @Blizzara

@alamb alamb marked this pull request as ready for review June 6, 2025 16:36
@alamb alamb changed the title Fix array_position on empty list Fix array_position on empty list Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants