Kater SQL Functions Filters
OPTIONAL_FILTER
Declares a filter that a reader switches on.
Family: Filters
When it is off, the query keeps every row it would keep without it.
Syntax
WHERE OPTIONAL_FILTER('name', condition, label='Label')Arguments
| Argument | Description |
|---|---|
name | The filter’s name, in quotes. Readers and the inputs of kater run turn it on by this name. |
condition | The condition the filter applies, such as KATER__IS_ONE_OF(orders.region, 'AMER', 'EMEA'). It can read a parameter, such as :is_one_of__region. |
label | The name a reader sees, such as 'Region'. |
Returns
Nothing of its own. When it is on, the query keeps only the rows where the condition is TRUE.
Usage notes
- Write it in a workspace root or a query, as a direct
ANDcondition of WHERE. - A parameter that it reads is declared in the file’s
parameters:. See Parameters. - A Sandbox run switches each optional filter on, with each parameter at its default value.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
The Sandbox runs the statement with the filter on, so only AMER and EMEA show.
SELECT orders.region AS "Region", EVAL(orders.count_distinct__order_id) AS "Orders"FROM kater_dataset.orders AS ordersWHERE OPTIONAL_FILTER('is_one_of__region', KATER__IS_ONE_OF(orders.region, 'AMER', 'EMEA'), label='Region')GROUP BY orders.regionORDER BY 1| Region | Orders |
|---|---|
| AMER | 728 |
| EMEA | 777 |
See also
- Filters and parameters
- Other functions in Filters:
REQUIRED_FILTER