Skip to content
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

[SQL] implement ARRAY_CONTAINS function #1499

Merged
merged 3 commits into from
Mar 8, 2024
Merged

[SQL] implement ARRAY_CONTAINS function #1499

merged 3 commits into from
Mar 8, 2024

Conversation

abhizer
Copy link
Contributor

@abhizer abhizer commented Mar 5, 2024

Is this a user-visible change (yes/no): yes

@@ -40,6 +40,7 @@ as `CREATE TABLE data AS (CITIES VARCHAR ARRAY, COUNTRY VARCHAR)`.
|----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| _array_`[`_index_`]` | where _index_ is an expression that evaluates to an integer, and _array_ is an expression that evaluates to an array. Returns the element at the specified position. If the index is out of bounds, the result is `NULL`. | `ARRAY[2,3][2]` => 3 |
| `ARRAY_APPEND(` _array_ `, ` _element_ `)` | Appends an element to the end of the array and returns the result. If the array is `NULL`, the function will return `NULL`. If the _element_ is `NULL`, the `NULL` element will be added to the end of the array. | `ARRAY_APPEND(ARRAY [1, 2], 3)` => `[1, 2, 3]` |
| `ARRAY_CONTAINS(` _array_ `, ` _element_ `)` | Returns true if the _array_ contains the _element_ | `ARRAY_CONTAINS(ARRAY [1, 2, 3], 2)` => true |
Copy link
Collaborator

Choose a reason for hiding this comment

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

this also behaves strange for nulls

Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>

update changelog.md

Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>

update docs

Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
@@ -41,6 +41,7 @@ as `CREATE TABLE data AS (CITIES VARCHAR ARRAY, COUNTRY VARCHAR)`.
| _array_`[`_index_`]` | where _index_ is an expression that evaluates to an integer, and _array_ is an expression that evaluates to an array. Returns the element at the specified position. If the index is out of bounds, the result is `NULL`. | `ARRAY[2,3][2]` => 3 |
| `ARRAY_APPEND(` _array_ `, ` _element_ `)` | Appends an element to the end of the array and returns the result. If the array is `NULL`, the function will return `NULL`. If the _element_ is `NULL`, the `NULL` element will be added to the end of the array. | `ARRAY_APPEND(ARRAY [1, 2], 3)` => `[1, 2, 3]` |
| `ARRAY_COMPACT(` _array_ `)` | Returns a new array by removing all the `NULL` values from the _array_ | `ARRAY_COMPACT(ARRAY [1, 2, 3, NULL])` => `[1, 2, 3]` |
| `ARRAY_CONTAINS(` _array_ `, ` _element_ `)` | Returns true if the _array_ contains the _element_. If _element_ is `NULL`, `NULL` is returned. | `ARRAY_CONTAINS(ARRAY [1, 2, 3], 2)` => true |
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would swap these two in the description, because the second one takes priority.

Copy link
Collaborator

Choose a reason for hiding this comment

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

btw, please review the other descriptions to see if this change should be applied to them as well.

Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
Signed-off-by: Mihai Budiu <mbudiu@gmail.com>
@mihaibudiu mihaibudiu merged commit 5aec54a into main Mar 8, 2024
3 checks passed
@mihaibudiu mihaibudiu deleted the array_contains branch March 8, 2024 23:57
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.

None yet

2 participants