filter

Selects rows from a dataset based on a filter predicate.

Syntax

result = filter rows by predicate;

Usage

A predicate is a Boolean expression that uses comparison or logical operators. The predicate is evaluated for every row. If the predicate is true, the row is included in the result. Comparisons on dimensions are lexicographic, and comparisons on measures are numerical.

When a filter is applied to grouped data, the filter is applied to the rows in the group. If all member rows are filtered out, groups are eliminated. You can run a filter statement before or after group to filter out members of the groups.

With results binding, an error may occur if the results from a previous query exceed the values supported by SAQL. For example, if something like filter q by dim1 in {{results(Query_1)}}; produces a filter tree with a depth greater than 10,000 values, SAQL will fail with an error.

Note

Example

The following example returns only rows where the origin is ORD, LAX, or LGA:

a1 = filter a by origin in ["ORD", "LAX", "LGA"];

Example

The following example returns only rows where the destination is LAX or the number of miles is greater than 1,500:

y = filter x by dest == "LAX" || miles > 1500;

Example

When in operates on an empty array in a filter operation, everything is filtered and the results are empty. The second statement filters everything and returns empty results:
a = load "0Fbxx000000002qCAA/0Fcxx000000002WCAQ";
a = filter a by Year in [];
c = group a by ('Year', 'Name');
d = foreach c generate 'Name' as 'group::AName', 'Year' as 'group::Year', sum(accounts::Revenue) as 'sRev';