filter function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Filters the array in expr using the function func.


filter(expr, func)


  • expr: An ARRAY expression.

  • func: A lambda function.


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.


> SELECT filter(array(1, 2, 3), x -> x % 2 == 1);
> SELECT filter(array(0, 2, 3), (x, i) -> x > i);
> SELECT filter(array(0, null, 2, 3, null), x -> x IS NOT NULL);