All Products
Search
Document Center

MaxCompute:FILTER

Last Updated:Mar 26, 2026

Filters elements in an array using a predicate function and returns the matching elements as a new array.

Syntax

array<T> filter(array<T> <a>, function<T,boolean> <func>)

Parameters

  • a: Required. The input array. T in array<T> specifies the data type of elements. Elements can be of any data type.

  • func: Required. A built-in function, user-defined function (UDF), or expression used to filter elements in the array. The input type must match the element type T, and the output must be of the BOOLEAN type.

Return value

Returns a value of the ARRAY type.

Examples

-- The return value is [2, 3].
select filter(array(1, 2, 3), x -> x > 1);
Note

This example uses -> (hyphen followed by a closing angle bracket) in a lambda expression. For more information, see Lambda functions.

Related functions

FILTER is a mathematical function. For more information about functions related to data computing and conversion, see Mathematical functions.