Where Clause, Group By, and Joins
Check only some of the rows of a table, check each value of a field separately, or use the fields of other tables in a monitor.
Three optional settings change which rows a monitor checks, and how it reports its results:
- Where clause: The monitor only checks the rows that match a SQL condition.
- Group by: The monitor checks each value of one or more fields separately, with its own data points and its own status.
- Joins: The monitor combines the table with other tables, so that you can filter or group by their fields.
When you create a monitor, you add joins in the Select a dataset card, and set the where clause and the group by in the Monitor settings step. Not all templates offer these settings: the page of each template lists the ones it supports, in its Common Settings. See All Monitor Templates.
On this page, the examples use an orders table that receives about 10,000 new orders per day from several countries, and a payments table that holds the payments of these orders.
Where Clause
The where clause is a SQL condition. The monitor ignores the rows that don't match it, as if they were not in the table.
To add one, turn on the Where statement card and write the condition after the WHERE keyword. Write it in the SQL dialect of your data source: Sifflet adds it to the query as is.
For example, to count only the orders that were not cancelled, add the following where clause to a Volume monitor on orders:
status <> 'cancelled'Use a where clause to:
- Exclude rows that don't reflect real activity, such as test or deleted rows.
- Check a rule that only applies to some rows. For example,
shipped_atmust not be null for the orders whosestatusisshipped. - Reduce the cost of the monitor on a large table, by checking only the rows that matter.
How It Works
- Sifflet applies the where clause before it computes each data point. In Percentage value mode, the excluded rows don't count in the total either: a data point of 2% means that 2% of the rows that match the where clause are bad. See Thresholds.
- In incremental scan mode, Sifflet combines the where clause with the time filter of each period: the monitor checks the rows of the period that match the where clause. See Scan Modes.
- Sifflet wraps the where clause in parentheses, so you can use
ORwithout changing the other filters of the query. - Failing rows only include rows that match the where clause.
- With joins, the where clause can use the fields of every joined table. When a field exists in several tables, prefix it with the full name of its table, as you would in a
FROMclause on your data source.
To check several subsets of a table separately, such as each country, use a group by rather than one monitor per subset with a different where clause.
Group By
The group by splits the rows of the table by the values of one or more fields. Each distinct value is a dimension: the monitor computes the data points of each dimension and evaluates them separately.
To add one, turn on the Group by monitoring card and select one to ten Group by columns. With several fields, each combination of values is a dimension. Null values form their own dimension.
For example, a Volume monitor on orders, grouped by country, counts the new orders of each country every day. One day, the pipeline that loads the orders of France stops. The total number of orders only drops by 5%, which is within the normal range, but the FR dimension drops to zero and fails.
Use a group by when:
- The table holds the data of several countries, customers, sources, or products, and a problem can affect only one of them.
- Each value behaves differently. For example, a small country receives 50 orders per day and a large one 5,000: a single threshold on the total can't catch a drop in the small country.
How It Works
- Thresholds: With a dynamic threshold, each dimension has its own model, trained on its own history. With a static or relative threshold, the same limits apply to every dimension. See Thresholds.
- Status: A run fails when at least one dimension fails. The monitor creates a single incident for all its failing dimensions, not one incident per dimension.
- Results: The monitor page shows the status of each dimension, and its own graph and data points. See Check the Results of a Monitor.
- Missing values: When a value stops appearing in the data, Sifflet keeps checking its dimension. Volume and Freshness monitors count the periods without rows as zero rows.
Up to 1,200 DimensionsA run fails with an error when the group by returns more than 1,200 distinct values: Sifflet doesn't truncate the results. Group by fields with a limited number of values, such as a country or a status, rather than an identifier or a timestamp.
Joins
A join combines the table you monitor with another table of the same data source. The monitor then checks the joined rows, and you can use the fields of the joined table in the where clause, the group by, and the settings of some templates, such as the conditions of No-Code Condition or the custom aggregation of Metrics.
To add a join:
- In the Select a dataset card, click Add join.
- In the Join to dataset card, select the table to join.
- Select the Join type:
- Inner join (default): Only the rows that have a match in both tables.
- Left join: All the rows of the first table, with empty fields when the joined table has no match.
- Outer join: All the rows of both tables.
- Select the Left join key column and the Right join key column: the fields that must be equal for two rows to match. To match on several fields, click Add join key. Rows must match on all the keys.
You can add several joins. Each join adds a table, and its left key can come from the monitored table or from a table joined before it.
For example, to count the payments of each country, create a Volume monitor on payments, join orders with payments.order_id = orders.order_id, and group by country.
How It Works
- Joined tables must be in the same data source as the monitored table: Sifflet checks them with a single query.
- The join changes the rows that the monitor checks:
- An inner join drops the rows without a match. For example, a Volume monitor doesn't count the payments of an order missing from
orders. - When a row matches several rows of the joined table, the result contains one row for each match. For example, joining
orderswithpaymentsgives one row per payment, not per order: an order paid in two payments counts twice.
- An inner join drops the rows without a match. For example, a Volume monitor doesn't count the payments of an order missing from
- In incremental scan mode, the time filter applies to the joined rows, based on the Time window column. See Scan Modes.
To check that the values of a field exist in another table, use Referential Integrity rather than a join.
Monitor as Code
The where clause and the group by are the whereStatement and groupBy parameters of the monitor. See Parameters.
Joins are a joins list, next to datasets. The monitored table is the first entry of datasets. The following YAML creates the monitor of the join example:
kind: Monitor
version: 2
friendlyId: paymentsPerCountry
name: Payments per country
incident:
severity: Low
datasets:
- uri: snowflake://my_account/analytics.sales.payments
joins:
- dataset:
uri: snowflake://my_account/analytics.sales.orders
joinType: Inner
joinCondition:
kind: Equality
fieldPairs:
- leftField:
dataset:
uri: snowflake://my_account/analytics.sales.payments
name: order_id
rightField:
dataset:
uri: snowflake://my_account/analytics.sales.orders
name: order_id
parameters:
kind: Volume
groupBy:
field:
dataset:
uri: snowflake://my_account/analytics.sales.orders
name: country| Parameter | Required | Description |
|---|---|---|
joins[].dataset | Yes | The table to join. |
joins[].joinType | No | Inner (default), Left, Right, or Outer. |
joins[].joinCondition.kind | Yes | Equality. |
joins[].joinCondition.fieldPairs | Yes | The pairs of fields that must be equal. The leftField comes from the monitored table or from a table joined before, and the rightField from the joined table. |
Updated about 3 hours ago

