Skip to content

Conversation

@kosiew
Copy link
Contributor

@kosiew kosiew commented Jun 24, 2025

Which issue does this PR close?

Rationale for this change

The array_has function incorrectly returns null for empty arrays, which should logically return false since an empty array cannot contain any element. This leads to inconsistencies and incorrect query results. The change ensures that array_has returns the correct boolean outcome when applied to empty arrays.

What changes are included in this PR?

  • Updated the array_has_dispatch_for_scalar function to check the array validity buffer and differentiate between null and empty arrays.
  • Ensured that empty arrays now return false and null arrays continue to return null.
  • Added SQL logic tests (array_has_table_empty) to verify the updated behavior.

Are these changes tested?

Yes, new test cases were added to the SQL logic test file array.slt to verify that:

  • Non-empty arrays with the target value return true.
  • Empty arrays return false.
  • Null arrays return null.

Are there any user-facing changes?

Yes:

  • array_has([], value) now returns false instead of null, improving correctness and predictability for users.

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jun 24, 2025
Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

thanks @kosiew that makes sense to me

@comphead comphead merged commit 678c25d into apache:main Jun 24, 2025
27 checks passed
@kosiew kosiew deleted the array-16474 branch August 9, 2025 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_has function returns null for an empty list ([]) instead of false

2 participants