array_distinct¶
Description¶
Returns a new array that contains only the distinct elements from the input array after removing duplicate elements.
The function is not guaranteed to return the elements in the array in a specific order.
The function is NULL-safe, which means that it treats NULLs as values and multiple NULLS will be de-duplicated into a single NULL.
Return type¶
input_array
Domain¶
This is a scalar function (calculates a single output value for a single input row.)
Categories¶
Usage¶
array_distinct(input_array)
Argument |
Type |
Optional |
Repeatable |
Restrictions |
---|---|---|---|---|
input_array |
array |
no |
no |
none |
Examples¶
make_col foo:array_distinct(make_array(1, 2, 3, 2, int64_null(), 5, 1, 2, string_null()))
Make the column ‘foo’ with the array [1, 2, 3, 5, null]
(not necessarily in this order) after removing duplicate values.
make_col foo:array_distinct(array_null())
Returns null
when the input passed is null
.
make_col foo:array_distinct(make_array(make_object('apple':'fruit', 'tea':'drink'), make_object('tea':'drink', 'apple':'fruit')))
Make the column ‘foo’ with an array containing a single object {"apple":"fruit","tea":"drink"}
.