All Products
Search
Document Center

MaxCompute:FILTER

Last Updated:Sep 06, 2023

Filters the elements in Array a by using func and returns a new array.

Syntax

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

Parameters

  • a: required. This parameter specifies an array. T in array<T> specifies the data type of the elements in the array. The elements can be of any data type.

  • func: required. This parameter specifies the built-in function, user-defined function, or expression that is used to filter the elements in Array a. The value must be of the same data type as the elements in Array a. The output result of the function or expression is of the BOOLEAN type.

Return value

A value of the ARRAY type is returned.

Examples

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

In this example, the combination of a hyphen and a closing angle bracket (->) is used. For more information about how to use the combination of a hyphen and a closing angle bracket (->) in Lambda functions, see Lambda functions.

Related functions

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