Stream filtering¶
Part of Streaming Transformations. See all pages in this section.
A WHERE clause filters records from the stream before they are written to the target table. Records that do not satisfy the predicate are silently discarded and do not appear in load history.
WHERE clause syntax¶
The predicate may combine any of the following:
| Element | Supported syntax |
|---|---|
| Comparison | =, != (<>), <, <=, >, >= |
| Range | BETWEEN <expr> AND <expr> |
| Membership | IN ( <value_list> ) |
| Null check | IS NULL, IS NOT NULL |
| Pattern match | LIKE, ILIKE |
| Logical | AND, OR, NOT |
| Built-in scalar functions | Yes (e.g., UPPER, TRY_CAST, IFF, COALESCE) |
| Metadata columns | Yes (e.g., METADATA$FILENAME, METADATA$START_SCAN_TIME) |
| Flattened element columns | Yes (e.g., f.value, when a LATERAL FLATTEN is present in the FROM clause) |
Stream column references in the WHERE clause use positional $n notation (for example, s.$1:field_name) or a column alias defined in the SELECT list. Predicates may also reference columns from dimension tables joined in the same subquery.
Not supported in WHERE:
- Subqueries
- Python, Java, and Scala language handlers, along with UDAFs, UDTFs, external functions, and Cortex AI functions
- Window functions
FLATTENin the predicate itself
Example — Filter by a stream field value¶
Ingest only records where the region is 'EU':
Example — Compound filter with a metadata column¶
Ingest only click and purchase events that arrive on or after a specific date:
Usage notes¶
- The per-channel offset token advances for every processed row, including rows excluded by the
WHEREpredicate. This may be surprising becauseget_latest_committed_offset_token(), the SDK method used to retrieve it, predates Streaming Transformations (API reference).
See also¶
The Scenarios show real-world use cases that combine stream filtering with other transformations. For the complete syntax with all features combined, see the Reference.
Previous: Pipe Creation · Next: Stream enrichment