Skip to content

Fix ARRAYS_OVERLAP function bug#23845

Merged
yingsu00 merged 1 commit into
prestodb:masterfrom
infvg:PRESTO_23730
Apr 30, 2025
Merged

Fix ARRAYS_OVERLAP function bug#23845
yingsu00 merged 1 commit into
prestodb:masterfrom
infvg:PRESTO_23730

Conversation

@infvg

@infvg infvg commented Oct 16, 2024

Copy link
Copy Markdown
Contributor

Description

In some arrays containing arrays that contain null values, arrays_overlap was not properly comparing values. Switch array_overlap to set based implementation.

Motivation and Context

Fixes #23730

Impact

None

Test Plan

Added the failing functions to unit tests and ran testArraysOverlap to confirm the functionality for the other queries remains the same.

Screenshot 2024-10-16 at 5 12 35 PM

== RELEASE NOTES ==

General Changes
* Fix a bug where a mirrored :func:`arrays_overlap(x, y) -> boolean` function does not return the correct value.

@infvg infvg marked this pull request as ready for review October 16, 2024 14:13
@infvg infvg requested review from a team and elharo as code owners October 16, 2024 14:13
@infvg infvg requested a review from presto-oss October 16, 2024 14:13
@tdcmeehan tdcmeehan self-assigned this Oct 16, 2024
@infvg infvg force-pushed the PRESTO_23730 branch 2 times, most recently from 29f4c0c to 25c73bc Compare October 24, 2024 13:36
@kewang1024 kewang1024 requested a review from rschlussel October 25, 2024 19:49

@kewang1024 kewang1024 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @infvg for the fix, this makes sense to me, @rschlussel was looking at this issue before, let's have her review this PR as well

Comment thread presto-main/src/test/java/com/facebook/presto/type/TestArrayOperators.java Outdated
@infvg infvg force-pushed the PRESTO_23730 branch 2 times, most recently from 4ef0f7a to bad00d9 Compare October 27, 2024 14:34
@infvg infvg requested a review from kewang1024 October 27, 2024 19:46
}
}
else {
checkElementNotNull(leftArray.isNull(i), ARRAY_NULL_ELEMENT_MSG);

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.

this is not right. we intentionally throw for equals comparison with nulls for arrays and maps (and if we did change it, we would want to return false rather than throw).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

if (elementType.equalTo(leftArray, i, rightArray, j)) {
return true;
try {
if (elementType.equalTo(leftArray, i, rightArray, j)) {

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.

equalTo should be throwing on null input. Instead we should pass the IS_DISTINCT_FROM method handle and call that instead of equal to (and additionally pass it to the TypedSet for the set based implementation). You can look at TypedSet.isContainedAt for how it calls the distinct from method handle. Additionally, you can look at ArrayIntersectFunction for how the method handle gets passed in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the implementation

@steveburnett

Copy link
Copy Markdown
Contributor

@infvg , are you available to work on this?

@infvg infvg force-pushed the PRESTO_23730 branch 3 times, most recently from fe6a8a5 to 66af0c0 Compare April 7, 2025 12:28
@infvg infvg requested a review from rschlussel April 8, 2025 06:51
@steveburnett

Copy link
Copy Markdown
Contributor

The linking of the release note entry to the PR has been automated and the manual addition of the PR link is no longer needed. Also, you can link directly to the documentation of the function, as shown.

== RELEASE NOTES ==

General Changes
* Fix a bug where a mirrored :func:`arrays_overlap(x, y) -> boolean` function does not return the correct value.

In some arrays containing arrays that contain null values, arrays_overlap
was not properly comparing values. Switch to array_overlap to set based
implementation.

Resolves: prestodb#23730
@yingsu00 yingsu00 merged commit 54ff0a1 into prestodb:master Apr 30, 2025
@ZacBlanco ZacBlanco mentioned this pull request May 29, 2025
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arrays_overlap return different results after swapping parameters for array types

6 participants