What you will be able to do
- Use OBJECT_DEPENDENCIES to find the objects that a change would affect
- Read the Snowsight lineage graph, including column lineage and gaps in tags
- Tell direct_objects_accessed, base_objects_accessed and objects_modified apart in ACCESS_HISTORY
- Attach system DMFs with expectations and set a DATA_METRIC_SCHEDULE
- Read DMF results from DATA_QUALITY_MONITORING_RESULTS and explain when DMFs are billed
1.Impact analysis with OBJECT_DEPENDENCIES
Tags record what data is. Governance also needs to know what depends on what, who touched the data and whether the data is healthy. The first of these comes from object dependencies. An object depends on another when it needs that object's metadata to work. In create view myview as select * from mytable;, the view is the referencing object and the table is the referenced object. Snowflake records these relationships in the Account Usage view OBJECT_DEPENDENCIES.
| Dependency type | Recorded when | Example |
|---|---|---|
| BY_NAME | a statement or object uses another object's name | a view that selects FROM a table |
| BY_ID | an object stores another object's ID | an external stage that stores a storage integration's ID |
| BY_NAME_AND_ID | an object depends on both the name and the ID | a materialized view on a table |
The main use is impact analysis. Suppose a table owner plans to add a column. Querying OBJECT_DEPENDENCIES by the table's name lists every view and other object that will be affected, so the changes can be scheduled without breaking anyone's queries. The same relationships help compliance officers trace sensitive data from its source (the referenced object) to its targets (the referencing objects).
SELECT referencing_object_name, referencing_object_domain, referenced_object_name, referenced_object_domain FROM snowflake.account_usage.object_dependencies WHERE referenced_object_name = 'SALES_STAGING_TABLE' and referenced_object_domain = 'EXTERNAL TABLE';Some relationships are missing from the view, and an impact analysis built on it inherits those gaps:
- Creating a table from a clone of another table is not recorded as a dependency.
- An object called from inside a function is not recorded. A view that uses
get_presigned_url(@stage1, …)does not show a dependency onstage1. - Objects outside Snowflake, such as an Amazon S3 bucket, are not tracked.
- Dependencies created by replication are not recorded.
- Definitions that use session parameters can't be resolved accurately, because the parameter values change from session to session.
- After a
CREATE OR REPLACEorALTERbreaks aBY_NAME_AND_IDreference, only the dependency from before the change is recorded.
Tags are a different thing from dependencies, and mixing the two up leads to the wrong view. A tag is a named label with a string value attached to an object or column. With tag propagation, a tag is copied automatically from a source object to a target, for example from a tagged table to a view built on it, or from a table to a new table made from it with CTAS. ACCOUNT_USAGE.TAG_REFERENCES_WITH_LINEAGE is one of the views that records tag assignments; its apply_method column shows whether a tag was set by hand or arrived by propagation. It reports tag assignments, so it is not a list of the objects that depend on a table.
Checkpoint 1 of 5· Check yourself
A table owner plans to add a column to the ORDERS table. Before making the change, they query SNOWFLAKE.ACCOUNT_USAGE.OBJECT_DEPENDENCIES to list every view that selects from ORDERS. Which query finds those views?
A view over a table references that table. The view is the referencing object and ORDERS is the referenced object. Filtering on referenced_object_name = 'ORDERS' therefore returns the views that depend on ORDERS. TAG_REFERENCES_WITH_LINEAGE only follows tags that propagated, so it would miss dependent views that carry no propagated tag.
“Object dependencies, when an object references a base object but does not materialize or copy data, such as when a view references a table.”Source: docs.snowflake.com
2.Tracing data flow in the Snowsight lineage graph
Data lineage combines two kinds of relationship. Data movement happens when data is copied or materialised from one object into another, for example by CREATE TABLE AS SELECT, INSERT or MERGE. Object dependencies are references that copy nothing, such as a view over a table. In both cases the source is upstream and the target is downstream. After CREATE TABLE table2 AS SELECT col1 FROM table1;, table2 and its col1 are downstream of table1.
To open the graph, go to Catalog » Explorer, select a table or view, and choose the Lineage tab. The graph opens one step at a time, and +/- expands the next level upstream or downstream. Select the arrow between two objects to see how the downstream object was created, for example the SQL statement that built it. Nodes are grouped by database and then by schema, and external objects are grouped by vendor. Objects your role can't access go into a separate group that is collapsed by default, and your privileges also control what details appear.
Column lineage goes one level deeper. In the side panel, hover over a column, choose View Lineage, and pick upstream or downstream. The Distance column shows how many steps away each related column is. A distance of 1 means the object was created directly from the current one, and 2 means it was created from an object that was created from the current one.
The same dialog also finds gaps in tagging. A tag is a named label with a string value, such as pii = 'Highly confidential', attached to an object or a column. If a column is tagged, the columns it flows into usually need the same tag with the same value. When they don't, a banner appears. A tag with a dashed border means the related column doesn't have the tag. A yellow border means the column has the tag but with a different value. Review and Apply then fixes those columns in one step.
Checkpoint 2 of 5· Check yourself
In the View Column Lineage dialog, you look at a downstream column that comes from a column tagged pii = 'Highly confidential'. The downstream column's tag has a yellow border. What does this tell you?
A yellow border means the tag is on the column but its value doesn't match. A dashed border would mean the tag is missing. Review and Apply can fix either case in one step.
“If a tag has a yellow border, the value of the tag doesn’t match.”Source: docs.snowflake.com
3.Auditing reads and writes with ACCESS_HISTORY
Lineage tells you how objects are connected. ACCESS_HISTORY tells you what each query actually did. This Account Usage view keeps one record per statement for the last 365 days. Each record includes user_name, query_start_time and JSON arrays describing the objects and columns the statement touched. To find who read a sensitive table in the last 30 days, filter on query_start_time, match the table's name in the accessed-objects arrays, and return user_name.
| Column | What it records |
|---|---|
| direct_objects_accessed | tables, views, columns, UDFs and procedures named in the query, including those selected with * |
| base_objects_accessed | all the base data objects the query needed to run, including columns |
| objects_modified | the objects written by the query, with baseSources and directSources for each written column |
| object_modified_by_ddl | DDL changes, including setting a masking or row access policy and setting or changing a tag |
| policies_referenced | the masking and row access policies enforced, including policies on intermediate objects |
The difference between direct and base access shows up with nested views. Say an analyst queries sales_summary, which is built on sales_clean, which selects from sales_raw. direct_objects_accessed shows sales_summary, because that is the object named in the query. base_objects_accessed shows sales_raw and its columns, the base data the query actually read. To answer which underlying tables a report touched, use base_objects_accessed.
Writes go to objects_modified. Take an UPDATE that sets orders.total_price from quantity and unit_price. The entry for total_price lists the columns it was computed from under baseSources and directSources. That gives you column-level write lineage even when a table is updated from its own columns.
Checkpoint 3 of 5· Check yourself
An auditor needs to know who changed the value of a governance tag on the EMAIL column from 'sensitive' to 'public', and when. Which ACCESS_HISTORY column holds that record?
Setting a tag or changing its value is a DDL operation on the column, so it lands in object_modified_by_ddl together with user_name and query_start_time. objects_modified covers data written by queries, not metadata changes.
“tag updates (for example, set a tag, change a tag value) on the object or column.”Source: docs.snowflake.com
Sources4
4.Measuring data quality with data metric functions
Data quality checks validate your data on a schedule, so problems show up before a consumer notices them. Each check is built from two parts. A data metric function (DMF) measures something, such as the number of NULLs in a column or how often a table is updated. On its own, a DMF doesn't decide whether that number is a problem. An expectation makes that decision. Each value the DMF returns is compared with the expectation, and any value that fails is reported as an expectation violation.
Common metrics are covered by system DMFs in SNOWFLAKE.CORE, such as NULL_COUNT, ROW_COUNT, DUPLICATE_COUNT, BLANK_COUNT and ACCEPTED_VALUES. If no system DMF measures what you need, write a custom DMF. You attach a DMF to a table or view with ALTER TABLE or ALTER VIEW, naming the columns it receives. ROW_COUNT takes no column, so it is attached with ON ().
ALTER TABLE t
ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT
ON (c1);You can also attach a DMF and its expectation when you create the object, so monitoring starts right away. In an expectation, the left side of the comparison must be the keyword VALUE. All bindings in the statement attach together: if one is invalid, the whole CREATE fails. Objects created with CLONE or LIKE inherit the source object's DMF bindings.
CREATE OR REPLACE TABLE customers (
customer_id NUMBER,
email VARCHAR
)
WITH DATA METRIC FUNCTION (
SNOWFLAKE.CORE.NULL_COUNT
ON (email)
EXPECTATION no_null_email ( VALUE = 0 )
);How often checks run is set by the table's DATA_METRIC_SCHEDULE object parameter. The default is one hour, and every DMF on the table or view shares the same schedule. A new schedule takes ten minutes to take effect. Anomaly detection, which currently covers data volume and freshness, does not follow this schedule.
| Value | Runs the DMFs |
|---|---|
| '5 MINUTE' | every five minutes |
| 'USING CRON 0 8 * * * UTC' | at 8:00 AM UTC every day |
| 'TRIGGER_ON_CHANGES' | after DML changes the table, such as an insert (reclustering does not trigger a run) |
DMFs can be set on tables (including temporary and transient tables), views, materialized views, dynamic tables, event tables, external tables and Apache Iceberg™ tables. They cannot be set on hybrid tables, streams, object tags, shared tables or views, or objects in reader accounts. An account can have at most 50,000 DMF associations. A column can have only one DMF of each kind, so you can't attach NULL_COUNT to the same column twice.
Checkpoint 4 of 5· Check yourself
Your team runs ALTER TABLE customers ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT ON (email). The table uses the default schedule. Every hour the DMF returns 12, but no expectation violation is ever reported. What is the most likely reason?
A DMF only returns a measurement. An expectation, such as VALUE = 0, compares that value and reports any value that fails as a violation. The default schedule is hourly, so the DMF is running. Anomaly detection currently covers only volume and freshness.
“The DMF returns a value based on the current state of your data, but doesn't define whether that value constitutes a data quality issue”Source: docs.snowflake.com
5.Reading DMF results and controlling their cost
Scheduled DMF results go to an event table, and you can read them in three ways depending on how much access you want to give. The raw event table, SNOWFLAKE.LOCAL.DATA_QUALITY_MONITORING_RESULTS_RAW, suits teams that build their own views or procedures on top of it. The SNOWFLAKE.LOCAL.DATA_QUALITY_MONITORING_RESULTS view flattens that data and is the easiest option when no post-processing is needed. The SNOWFLAKE.GOVERNANCE_VIEWER database role cannot query this view. The DATA_QUALITY_MONITORING_RESULTS table function returns the same columns but covers only one table per call, so you can give someone that table's results and nothing else.
DATA_QUALITY_MONITORING_RESULTS(
REF_ENTITY_NAME => '<string>' ,
REF_ENTITY_DOMAIN => '<string>'
)Each result row includes table_name, metric_name, argument_names, measurement_time and value, which is what the DMF returned. For a view or materialized view, pass 'VIEW' as REF_ENTITY_DOMAIN. For any kind of table, pass 'TABLE'.
Billing follows the schedule. Scheduled DMFs run on serverless compute and appear on the bill under Data Quality Monitoring. Creating a DMF costs nothing. Calling a DMF yourself in a SELECT is also not billed as Data Quality Monitoring, which makes it a cheap way to test a metric before scheduling it. Writing results to the event table is billed separately as Logging. To track DMF credits, query DATA_QUALITY_MONITORING_USAGE_HISTORY, or METERING_DAILY_HISTORY where service_type is DATA_QUALITY_MONITORING.
SELECT SNOWFLAKE.CORE.NULL_COUNT(
SELECT
ssn
FROM hr.tables.empl_info
);Checkpoint 5 of 5· Check yourself
An engineer wants to try out a new data quality metric on a large table and keep Data Quality Monitoring charges as low as possible. Which of these activities is billed under Data Quality Monitoring?
Only scheduled DMF runs are billed as Data Quality Monitoring. Creating a DMF is free, and calling it in a SELECT is not billed as Data Quality Monitoring, so testing a metric that way is cheap. Writing results to the event table is billed separately, as Logging.
“Billing occurs only when a scheduled DMF is computed on an object.”Source: docs.snowflake.com
Practise it for real
Put a NULL check on a column, schedule it, and read its results
1.Run SELECT SNOWFLAKE.CORE.NULL_COUNT(SELECT ssn FROM hr.tables.empl_info); against a table you own, substituting your own table and column.
Why: Calling the DMF yourself tests the metric without creating a scheduled association, so it isn't billed as Data Quality Monitoring.
You should see: A single NUMBER: how many NULLs the column contains right now.
2.Attach the DMF with ALTER TABLE my_table ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.NULL_COUNT ON (my_column); replacing my_table and my_column with your own names.
Why: The association is what makes Snowflake run the DMF on a schedule.
You should see: The statement succeeds. Trying to attach NULL_COUNT to the same column a second time fails.
3.Set ALTER TABLE my_table SET DATA_METRIC_SCHEDULE = '5 MINUTE'; then confirm it with SHOW PARAMETERS LIKE 'DATA_METRIC_SCHEDULE' IN TABLE my_table;
Why: The default hourly schedule is too slow for a test, and every DMF on the table follows this one setting.
You should see: SHOW PARAMETERS lists DATA_METRIC_SCHEDULE with the value 5 MINUTE at TABLE level.
4.After about fifteen minutes, call DATA_QUALITY_MONITORING_RESULTS(REF_ENTITY_NAME => 'my_db.my_schema.my_table', REF_ENTITY_DOMAIN => 'TABLE') with your own database, schema and table names.
Why: The schedule takes ten minutes to take effect, and then the first scheduled run has to complete.
You should see: One row per run, with metric_name NULL_COUNT and the count in the value column.
Stuck? Get a nudge
If no rows appear, check that your role has access to DMF results. The GOVERNANCE_VIEWER database role cannot query the results view.
Sources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Snowflake tracks object dependencies in the Account Usage view OBJECT_DEPENDENCIES.”
↩︎ Impact analysis with OBJECT_DEPENDENCIES“Querying the OBJECT_DEPENDENCIES view based on the table name returns all of the objects (e.g. views) that will be affected.”
↩︎ Impact analysis with OBJECT_DEPENDENCIES“Snowflake tracks object dependencies for Snowflake objects only.”
↩︎ Impact analysis with OBJECT_DEPENDENCIES“the view does not record the dependency necessary to create a new table from the clone of another table.”
↩︎ Exam trap 3 - 2.
“The tag was automatically propagated from one object to another.”
↩︎ Impact analysis with OBJECT_DEPENDENCIES“Users associate a tag with an arbitrary string value when assigning the tag to a Snowflake object.”
↩︎ Tracing data flow in the Snowsight lineage graph - 3.
“CREATE TABLE AS SELECT (CTAS), INSERT, or MERGE operations on tables result in data movement.”
↩︎ Tracing data flow in the Snowsight lineage graph“if the downstream distance is 1, then the column is in an object that was created directly from the current object.”
↩︎ Tracing data flow in the Snowsight lineage graph“If a tag has a dashed border, the column does not have the tag applied.”
↩︎ Tracing data flow in the Snowsight lineage graph“Object dependencies, when an object references a base object but does not materialize or copy data, such as when a view references a table.”
↩︎ Checkpoint“Object dependencies, when an object references a base object but does not materialize or copy data, such as when a view references a table.”
↩︎ Prediction“If a tag has a yellow border, the value of the tag doesn’t match.”
↩︎ Checkpoint - 4.
“query the access history of Snowflake objects (e.g. table, view, column) within the last 365 days (1 year).”
↩︎ Auditing reads and writes with ACCESS_HISTORY“A JSON array that specifies the objects that were associated with a write operation in the query.”
↩︎ Auditing reads and writes with ACCESS_HISTORY“tables, views, and columns directly named in the query explicitly or through shortcuts such as using an asterisk”
↩︎ Auditing reads and writes with ACCESS_HISTORY“A JSON array of all base data objects to execute a query, including columns, external functions, UDFs, and stored procedures.”
↩︎ Exam trap 1“tag updates (for example, set a tag, change a tag value) on the object or column.”
↩︎ Checkpoint - 5.
“A DMF measures an attribute of your data such as how many NULL values exist in a column”
↩︎ Measuring data quality with data metric functions“An expectation is combined with a DMF to create a data quality check.”
↩︎ Measuring data quality with data metric functions“You cannot set a DMF on a hybrid table or a stream object.”
↩︎ Measuring data quality with data metric functions“Billing occurs only when a scheduled DMF is computed on an object.”
↩︎ Reading DMF results and controlling their cost“You are not billed for unscheduled data metric function usage, such as calling a DMF with a SELECT statement.”
↩︎ Exam trap 2“The DMF returns a value based on the current state of your data, but doesn't define whether that value constitutes a data quality issue”
↩︎ Checkpoint - 6.
“All data metric functions on a table or view follow the same schedule.”
↩︎ Measuring data quality with data metric functions - 7.
“Query the DATA_QUALITY_MONITORING_RESULTS view, which is a flattened version of the event table.”
↩︎ Reading DMF results and controlling their cost“However, you can only specify a single table when calling the function.”
↩︎ Reading DMF results and controlling their cost