fix: Fix bug in array_has scalar path with sliced arrays#20677
Open
neilconway wants to merge 3 commits intoapache:mainfrom
Open
fix: Fix bug in array_has scalar path with sliced arrays#20677neilconway wants to merge 3 commits intoapache:mainfrom
array_has scalar path with sliced arrays#20677neilconway wants to merge 3 commits intoapache:mainfrom
Conversation
array_has scalar path with sliced arrays
comphead
reviewed
Mar 3, 2026
comphead
approved these changes
Mar 3, 2026
Contributor
comphead
left a comment
There was a problem hiding this comment.
Thanks @neilconway, good job as usual!
| } | ||
|
|
||
| #[test] | ||
| fn test_array_has_sliced_list() -> Result<(), DataFusionError> { |
Contributor
There was a problem hiding this comment.
double checked it is failing in main, this fix would be nice backporting to #19692
Contributor
Author
There was a problem hiding this comment.
Sure. I haven't done a backport before, but I'd guess we should wait for this to land in main, then I'll open a new PR to backport to the 53 branch?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
N/A
Rationale for this change
In #20374,
array_haswith a scalar needle was optimized to reconstruct matches more efficiently. Unfortunately, that code was incorrect for sliced arrays:values()returns the entire value buffer (including elements outside the visible slice), so we need to skip the corresponding indexes in the result bitmap.We could fix this by just skipping indexes, but it seems more robust and efficient to arrange to not compare the needle against elements outside the visible range in the first place.
array_positionhas a similar behavior (introduced in #20532): it didn't have the buggy behavior, but it still did extra work for sliced arrays by comparing against elements outside the visible range.Benchmarking the revised code, there is no performance regression for unsliced arrays.
What changes are included in this PR?
array_hasbug for sliced arrays with scalar needlearray_hasandarray_positionto not compare against elements outside the visible range of a sliced arrayarray_hasbugarray_positionbehavior for sliced arraysAre these changes tested?
Yes.
Are there any user-facing changes?
No.