DISTINCT
- DISTINCT(array)[source]
Returns an array containing only the distinct values from the input array.
This function removes duplicates from the provided array, preserving the order of first occurrences. It works on any scalar or object array type.
- Parameters:
array (
Operand) – The array from which duplicates will be removed.- Return type:
- Returns:
A formula object representing the array of distinct values.
- Raises:
ValueError – If the input is not an array type or is a MAP type.
Examples
Removing duplicates from numbers:
DISTINCT([1, 2, 2, 3, 1]) # Returns [1, 2, 3]
Removing duplicates from strings:
DISTINCT(["apple", "banana", "apple", "cherry"]) # Returns ["apple", "banana", "cherry"]
``array`` — accepted types
BOOLEAN_ARRAY
DATETIME_ARRAY
DATE_ARRAY
DECIMAL_ARRAY
INTEGER_ARRAY
OBJECT_ARRAY
STRING_ARRAY
TIME_ARRAY
Return types
BOOLEAN_ARRAY
DATETIME_ARRAY
DATE_ARRAY
DECIMAL_ARRAY
INTEGER_ARRAY
OBJECT_ARRAY
STRING_ARRAY
TIME_ARRAY