filter
function
Applies to: Databricks SQL Databricks Runtime
Filters the array in expr
using the function func
.
Syntax
filter(expr, func)
Arguments
expr
: An ARRAY expression.func
: A lambda function.
Returns
The result is of the same type as expr
.
The lambda function may use one or two parameters where the first parameter represents the element and the second the index into the array.
Examples
> SELECT filter(array(1, 2, 3), x -> x % 2 == 1);
[1,3]
> SELECT filter(array(0, 2, 3), (x, i) -> x > i);
[2,3]
> SELECT filter(array(0, null, 2, 3, null), x -> x IS NOT NULL);
[0,2,3]
Related functions
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for