Skip to main content
On this page

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

ArgumentDescription
nameThe filter’s name, in quotes. Readers and the inputs of kater run turn it on by this name.
conditionThe 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.
labelThe 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 AND condition 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 orders
WHERE
OPTIONAL_FILTER('is_one_of__region', KATER__IS_ONE_OF(orders.region, 'AMER', 'EMEA'), label='Region')
GROUP BY
orders.region
ORDER BY
1
RegionOrders
AMER728
EMEA777

See also