feat(query): Array Functions Supporting ARRAY and VARIANT Types #18213
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.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This PR introduces a set of array functions to Databend, designed to enhance compatibility with Snowflake and provide more flexible array manipulation capabilities. These functions are implemented to seamlessly support both native
ARRAY
types andVARIANT
types containing arrays.Functions:
The following functions originally supported the Array type but not the Variant type:
ARRAY_APPEND(array, element)
: Appends an element to the end of an array.ARRAY_CONTAINS(array, element)
: Returns true if the array contains the element.ARRAY_FLATTEN(array)
: Flattens a nested array into a single-dimensional array.ARRAY_INDEXOF(array, element)
: Returns the index of the first occurrence of an element in an array.ARRAY_PREPEND(element, array)
: Prepends an element to the beginning of an array.ARRAY_REMOVE_FIRST(array)
: Removes the first occurrence of an element from an array.ARRAY_REMOVE_LAST(array)
: Removes the last occurrence of an element from an array.ARRAY_SLICE(array, start, end)
: Extract a sub array using slice between start and end argument.ARRAY_UNIQUE(array)
: Returns the number of unqiue elements in the array.The following functions originally supported the Variant type but not the Array type:
ARRAY_EXCEPT(array1, array2)
: Returns a new ARRAY that contains the elements from array1 and not in array2.ARRAY_OVERLAP(array1, array2)
: Compares whether two arrays have at least one element in common.The following functions have been added:
ARRAY_COMPACT(array)
: Removes all NULL values from an array.ARRAY_REMOVE(array, element)
: Removes all occurrences of an element from an array.ARRAY_REVERSE(array)
: Reverses the order of elements in an array.Key Features:
ARRAY
andVARIANT
Support: The functions are designed to work seamlessly with both nativeARRAY
types andVARIANT
types that contain array data. This provides flexibility when dealing with semi-structured data.Tests
Type of change
This change is