What you will be able to do
- Explain how a data metric function and an expectation together form a data quality check
- Pick the system DMF that measures a given problem, including closely related pairs such as DUPLICATE_COUNT and DUPLICATE_PERCENT
- Attach DMFs to a table or view with ALTER or CREATE, and set DATA_METRIC_SCHEDULE
- Predict when DMFs incur cost and name the objects a DMF cannot be set on
Key concept
Data quality check (DMF + expectation) — A data metric function only measures something about your data, such as a NULL count. It becomes a pass/fail check once you pair it with an expectation, which compares the measured value to a rule and reports a violation when the rule fails.
1.Measuring data quality with DMFs and expectations
Cleaning starts with knowing what is wrong, and how badly. In Snowflake that measurement is done by a data metric function (DMF): a function that returns a number describing your data, such as how many NULLs a column holds or how recently a table was updated. The value carries no verdict. A NULL count of 40 is neither good nor bad until somebody decides what it should be.
That decision is the expectation. Snowflake compares each value a DMF returns against the expectation, and values that fail are reported as expectation violations you can act on. Inside an expectation the left side of the comparison is always the keyword VALUE, so VALUE = 0 means "this metric must be zero". The allowed operators are the comparisons, AND, OR, NOT, and EQUAL_NULL. Arithmetic on VALUE, subqueries and quoted strings are rejected. If you build a check in Snowsight, you choose the DMF and write its expectation in the same step.
CREATE OR REPLACE TABLE orders (
order_id NUMBER,
customer_id NUMBER
)
WITH DATA METRIC FUNCTION (
SNOWFLAKE.CORE.NULL_COUNT
ON (customer_id)
EXPECTATION no_null_customers ( VALUE = 0 ),
SNOWFLAKE.CORE.DUPLICATE_COUNT
ON (order_id)
EXPECTATION no_duplicate_orders ( VALUE = 0 )
);DMFs come in two kinds. System DMFs live in the CORE schema of the shared SNOWFLAKE database, which is why they are written SNOWFLAKE.CORE.NULL_COUNT. Snowflake maintains them, and you cannot rename them or change what they do. When no system DMF measures what you need, you write a custom DMF. Inside a custom DMF you can call DATA_METRIC_SCHEDULED_TIME to get the scheduled evaluation time, for example to build your own freshness metric. That function is not a metric in its own right and cannot be associated with a table.
Checkpoint 1 of 6· Fill the gap
This statement binds two system DMFs to a new table, and each one has an expectation that the metric must be zero. Which token completes the first expectation?
CREATE OR REPLACE TABLE orders (
order_id NUMBER,
customer_id NUMBER
)
WITH DATA METRIC FUNCTION (
SNOWFLAKE.CORE.NULL_COUNT
ON (customer_id)
EXPECTATION no_null_customers ( ? = 0 ),
SNOWFLAKE.CORE.DUPLICATE_COUNT
ON (order_id)
EXPECTATION no_duplicate_orders ( VALUE = 0 )
);An expectation compares what the DMF returns to a rule, and the left side of that comparison must always be the keyword VALUE. You don't write the column name or the DMF name there, and the quoted string 'VALUE' is rejected.
Source: docs.snowflake.com2.Choosing the right system DMF
The system DMFs are grouped by the quality dimension they measure: completeness, consistency, freshness, outliers, schema, statistics, uniqueness, validity and volume. Most count and percentage DMFs count bad values, so lower is better. Others, such as NOT_NULL_COUNT, count values that meet a condition. The Statistics DMFs (AVG, MAX, STDDEV and so on) return a plain measurement, so you supply the threshold in the expectation. The Outliers DMFs apply a built-in cutoff, such as Tukey fences or a Z-score, and count the values that fall outside it.
They don't, and the pairs below are where wrong answers usually come from. DUPLICATE_COUNT counts duplicates including NULLs. DUPLICATE_PERCENT and UNIQUE_PERCENT exclude NULLs, so for a column with at least one non-NULL value the two percentages add up to 100. The validity DMFs also map directly onto type conversion. They tell you, before you cast anything, how many strings will fail to become a native number or timestamp.
| DMF | Counts | Does not count |
|---|---|---|
| NULL_COUNT / NOT_NULL_COUNT | NULLs / non-NULLs; together they cover every row | Nothing; the two are complements |
| DUPLICATE_COUNT | Duplicate values, including NULL values | n/a |
| DUPLICATE_PERCENT | Share of non-NULL rows whose value occurs more than once | NULL values |
| BLANK_COUNT | Values that are empty or only spaces | NULL values |
| EMPTY_STRING_COUNT | Only the empty string | NULL values, whitespace-only strings |
| INVALID_ISO8601_FORMAT_COUNT | Values whose layout is not ISO 8601 | Values like 2026-13-45, which have a valid layout |
| INVALID_TIMESTAMP_STRING_COUNT | Values that cannot be parsed as a timestamp or date | n/a |
| INVALID_INTEGER_COUNT | Values not written as an integer, such as 3.7 | n/a |
| INVALID_NUMERIC_TYPE_CAST_COUNT | Values that cannot be cast to a number | 3.7, which casts fine |
Checkpoint 2 of 6· Check yourself
A VARCHAR staging column should hold order dates, and you will later cast it to DATE. You want a check that catches values such as 2026-13-45 before the cast fails. Which system DMF should the expectation use?
INVALID_TIMESTAMP_STRING_COUNT counts strings that cannot be parsed as a timestamp or date, so it catches impossible dates. INVALID_ISO8601_FORMAT_COUNT checks only the layout, and 2026-13-45 has a valid layout, so it would pass.
“INVALID_ISO8601_FORMAT_COUNT checks only the layout of a value, and INVALID_TIMESTAMP_STRING_COUNT checks whether the value can be parsed as a timestamp.”Source: docs.snowflake.com
Checkpoint 3 of 6· Check yourself
Loads into the order_id key column sometimes contain several NULLs. Your uniqueness check must flag repeated NULLs as well as repeated real IDs. Which system DMF should it use?
DUPLICATE_COUNT includes NULL values when it counts duplicates. DUPLICATE_PERCENT and UNIQUE_PERCENT measure only non-NULL rows, so repeated NULLs never affect either of them.
“DUPLICATE_COUNT | Determine the number of duplicate values in a column, including NULL values.”Source: docs.snowflake.com
Sources3
3.Attaching DMFs to tables and views
A DMF runs automatically only once it is associated with a table or view. You make the association with ALTER TABLE or ALTER VIEW and name the columns to pass in as arguments. Table-level DMFs such as ROW_COUNT take an empty column list, ON (). You can associate several system DMFs with one object to cover several dimensions at once.
ALTER TABLE t
ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT
ON (c1);ACCEPTED_VALUES also takes a lambda alongside the column. The DMF returns how many records do *not* satisfy the lambda, so the statement below counts rows where age is not 5.
ALTER TABLE t1
ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.ACCEPTED_VALUES ON (age, age -> age = 5);You can also bind DMFs when you create the object, with WITH DATA METRIC FUNCTION, so monitoring starts with no separate ALTER step. On tables it follows the column definitions. On views, materialized views and dynamic tables it goes before AS SELECT. All bindings in the statement attach atomically: if one is invalid, the whole CREATE fails. CREATE OR REPLACE rebuilds the bindings from scratch, CREATE IF NOT EXISTS leaves existing bindings alone, and both CLONE and LIKE copy the source's bindings to the new object. That last rule matters when you clone a table to test a cleanup, because the clone keeps running the same checks. To remove a binding, use ALTER TABLE ... DROP DATA METRIC FUNCTION.
Checkpoint 4 of 6· Match them up
You maintain a table that already has DMF bindings. Match each statement to what happens to those bindings.
Tap a term, then the definition that fits it.
CREATE OR REPLACE rebuilds bindings from scratch, and CREATE IF NOT EXISTS leaves an existing object alone. CLONE and LIKE copy the source's bindings, so a clone made to test a cleanup still runs the same checks. To remove a binding you use DROP DATA METRIC FUNCTION.
“CLONE: The cloned object inherits DMF bindings from the source.”Source: docs.snowflake.com
Checkpoint 5 of 6· Fill the gap
Table t already exists. Which keyword completes this statement so that NULL_COUNT on column c1 runs automatically?
ALTER TABLE t
? DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT
ON (c1);On an existing table or view, you create the association with ALTER TABLE or ALTER VIEW ... ADD DATA METRIC FUNCTION and list the columns to pass in. WITH DATA METRIC FUNCTION belongs in a CREATE statement, not in ALTER.
Source: docs.snowflake.comSources2
4.DATA_METRIC_SCHEDULE, cost and where DMFs cannot go
How often checks run is set per object, not per DMF. The DATA_METRIC_SCHEDULE parameter on a table, view or materialized view defaults to one hour, and every DMF on that object follows the same schedule. If you want one check every five minutes and another once a day, they cannot share a table.
| Value | Effect |
|---|---|
| '5 MINUTE' | Runs the table's DMFs every 5 minutes |
| 'USING CRON 0 8 * * * UTC' | Runs them at 8:00 AM UTC daily |
| 'TRIGGER_ON_CHANGES' | Runs them when DML, such as an insert, changes the table (only some table kinds; reclustering does not trigger) |
| '' | Suspends every DMF on the table until a valid value is set again |
ALTER TABLE hr.tables.empl_info SET DATA_METRIC_SCHEDULE = 'TRIGGER_ON_CHANGES';Two timing details catch people out. A schedule change takes up to 10 minutes to apply to DMFs that were already on the table, although newly added DMFs are not delayed. A table can also change between the scheduled time and the moment the DMF actually evaluates, so when you read results in DATA_QUALITY_MONITORING_RESULTS, use the measurement_time column. To pause a single check, modify its association with SUSPEND and later RESUME.
Scheduled DMFs run on serverless compute, and the credits appear on the bill under Data Quality Monitoring. Creating a DMF costs nothing, and neither does calling one in a SELECT. You can track spend in DATA_QUALITY_MONITORING_USAGE_HISTORY. A tight schedule on a large table is therefore a real cost decision, and setting the schedule to '' is the quickest way to stop it.
DMFs can be set on regular tables (including temporary and transient tables), dynamic tables, event tables, external tables, Apache Iceberg tables, views and materialized views. These are the exceptions:
- hybrid tables and streams
- shared tables or views, and shares (you cannot grant DMF privileges to a share)
- object tags
- objects in a reader account, and trial accounts altogether
An account can hold at most 50,000 DMF associations, and each DMF set on each object counts as one.
Checkpoint 6 of 6· Fill the gap
Every check on the empl_info table should run as soon as an insert or other DML changes its data, not on a fixed interval. Which value completes the statement?
ALTER TABLE hr.tables.empl_info SET DATA_METRIC_SCHEDULE = ? ;'TRIGGER_ON_CHANGES' runs the table's DMFs when DML modifies the table. '5 MINUTE' and the cron value run on a timer whether or not the data changed, and '' suspends every DMF on the table. The schedule is a table-level parameter, so all DMFs on empl_info share it.
Source: docs.snowflake.comSources
(3)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“A DMF measures an attribute of your data such as how many NULL values exist in a column”
↩︎ Measuring data quality with DMFs and expectations“Return values that fail the check are reported as expectation violations so you can take appropriate action.”
↩︎ Measuring data quality with DMFs and expectations“You cannot set a DMF on a hybrid table or a stream object.”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“You are not billed for creating a DMF.”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“You can only have 50,000 total associations of DMFs on objects per account.”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“Setting a DMF on an object tag is not supported.”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“An expectation is combined with a DMF to create a data quality check.”
↩︎ Key concept“You are not billed for unscheduled data metric function usage, such as calling a DMF with a SELECT statement.”
↩︎ Exam trap 2“Billing occurs only when a scheduled DMF is computed on an object.”
↩︎ Prediction - 2.
“The left side of the comparison must be the keyword VALUE.”
↩︎ Measuring data quality with DMFs and expectations“Allowed operators are: =, !=, <>, <, >, <=, >=, AND, OR, NOT, and EQUAL_NULL.”
↩︎ Measuring data quality with DMFs and expectations“When associating the DMF, you specify which columns are passed to the DMF as arguments.”
↩︎ Attaching DMFs to tables and views“All DMF bindings attach atomically.”
↩︎ Attaching DMFs to tables and views“CLONE: The cloned object inherits DMF bindings from the source.”
↩︎ Attaching DMFs to tables and views“By default, the schedule is set to one hour. All data metric functions on a table or view follow the same schedule.”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“There is a 10-minute lag from when you modify the DMF from a table for any scheduling changes to take effect”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“specify the measurement_time column in your query as the basis for the evaluation”
↩︎ DATA_METRIC_SCHEDULE, cost and where DMFs cannot go“All data metric functions on a table or view follow the same schedule.”
↩︎ Exam trap 1 - 3.
“Snowflake provides system DMFs in the CORE schema of the shared SNOWFLAKE database.”
↩︎ Measuring data quality with DMFs and expectations“Call it in the body of a custom DMF to retrieve the scheduled evaluation time”
↩︎ Measuring data quality with DMFs and expectations“The Statistics DMFs return a measurement rather than a pass or fail signal.”
↩︎ Choosing the right system DMF“Determine what percentage of non-NULL rows have a value that occurs more than once.”
↩︎ Choosing the right system DMF“For example, 3.7 is counted by INVALID_INTEGER_COUNT but not by INVALID_NUMERIC_TYPE_CAST_COUNT.”
↩︎ Choosing the right system DMF“Determine the number of duplicate values in a column, including NULL values.”
↩︎ Exam trap 3“INVALID_ISO8601_FORMAT_COUNT checks only the layout of a value, and INVALID_TIMESTAMP_STRING_COUNT checks whether the value can be parsed as a timestamp.”
↩︎ Checkpoint“DUPLICATE_COUNT | Determine the number of duplicate values in a column, including NULL values.”
↩︎ Checkpoint