GET_LINEAGE

functionnot supportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Table functions

Given a Snowflake object, returns data lineage information upstream or downstream from that object. Upstream means the path of objects that led to the creation of the object; downstream means the path of objects that were created from the object.

Syntax

supportedpartialnot supportednot scored

SNOWFLAKE.CORE.GET_LINEAGE(
    '<object_name>',
    '<object_domain>',
    '<direction>',
    [ <max_distance>, ]
    [ '<object_version>', ]
    [ '<namespace>', ]
    [ '<object_type>', ]
    [ '<external_id>', ]
    [ '<column_name>' ]
)

Parameters

NameRequiredDescription
'object_name'requiredName of the object for which data lineage information is retrieved. Use the fully qualified name if the object is in a schema different from the current schema in the session. Specify a storage integration by its unqualified name, because integrations are account-level objects.
'object_domain'requiredThe domain of the object. Supported domains are ‘COLUMN’, ‘TABLE’ (which includes all table-like objects including views and dynamic tables), ‘SEMANTIC_VIEW’ (for semantic views), ‘STAGE’, ‘INTEGRATION’ (for storage integrations), ‘STREAM’, ‘TASK’, ‘TASK_GRAPH’, ‘CORTEX_SEARCH_SERVICE’ (for Cortex Search services), ‘MODEL MONITOR’ (for model monitors), and ‘CORTEX_AGENT’ (for Cortex Agents). Specify an external table as ‘TABLE’. The output reports its domain as ‘EXTERNAL_TABLE’. Specify a model monitor as ‘MODEL MONITOR’, with a space rather than an underscore. This is the same value that the output reports for a model monitor. Specify an agent as ‘CORTEX_AGENT’. ‘AGENT’ isn’t a valid domain, even though the object type is displayed as Agent in Snowsight. For ML lineage, use TABLE for feature views (which are dynamic tables and views internally), ‘DATASET’, or ‘MODEL’ for models. To retrieve lineage for an object that isn’t in Snowflake, use ‘EXTERNAL’, or ‘EXTERNAL_COLUMN’ for a column of such an object. Both require the namespace argument. For more information, see Lineage for objects outside Snowflake.
'direction'requiredThe direction for which the lineage should be retained. Supported directions are ‘UPSTREAM’ and ‘DOWNSTREAM’.
max_distanceoptionalThe number of levels of lineage to retrieve. The maximum is 5; this is also the default.
'object_version'optionalFor versioned objects, such as datasets and models, the version of the object for which lineage is retrieved. If not specified, the default version is used.
'namespace'optionalThe namespace of the object, which identifies the system the object comes from. Required when object_domain is ‘EXTERNAL’ or ‘EXTERNAL_COLUMN’, and not valid for any other domain.
'object_type'optionalThe specific type of the object within its namespace, such as the type a data catalog assigns it. Only valid when object_domain is ‘EXTERNAL’ or ‘EXTERNAL_COLUMN’.
'external_id'optionalThe identifier that the originating system assigns to the object. Only valid when object_domain is ‘EXTERNAL’ or ‘EXTERNAL_COLUMN’.
'column_name'optionalThe name of the column to retrieve lineage for. Required when object_domain is ‘EXTERNAL_COLUMN’, and not valid for any other domain.

Usage notes

Output

The output is a table with one row per object relationship in the lineage path (that is, an edge in the lineage graph). Relationships are between objects designated as source and target in each row. The table includes the following columns: Column | Type | Description SOURCE_OBJECT_DATABASE | VARCHAR | The database that contains the source object. SOURCE_OBJECT_SCHEMA | VARCHAR | The schema that contains the source object. SOURCE_OBJECT_NAME | VARCHAR | The unqualified name of the source object. SOURCE_OBJECT_DOMAIN | VARCHAR | The domain of the source object. Possible values include ‘COLUMN’, ‘TABLE’, ‘EXTERNAL_TABLE’, ‘SEMANTIC_VIEW’, ‘DATASET’, ‘MODEL’ (for ML models), ‘MODEL MONITOR’, ‘STAGE’, ‘INTEGRATION’, ‘STREAM’, ‘TASK’, ‘TASK_GRAPH’, ‘CORTEX_SEARCH_SERVICE’, and ‘CORTEX_AGENT’. SOURCE_OBJECT_VERSION | VARCHAR | The version of the source object, for versioned objects such as datasets and models. NULL if the source object is not versioned. SOURCE_COLUMN_NAME | VARCHAR | The name of the source column, if the source object is a column. NULL if the source object is not a column. SOURCE_STATUS | VARCHAR | The status of the source object. Possible values are ‘ACTIVE’ and ‘MASKED’. ‘MASKED’ means that the current role can’t see the object. For details, see Usage notes. TARGET_OBJECT_DATABASE | VARCHAR | The database that contains the target object. TARGET_OBJECT_SCHEMA | VARCHAR | The schema that contains the target object. TARGET_OBJECT_NAME | VARCHAR | The unqualified name of the target object. TARGET_OBJECT_DOMAIN | VARCHAR | The domain of the target object. Possible values include ‘COLUMN’, ‘TABLE’, ‘EXTERNAL_TABLE’, ‘SEMANTIC_VIEW’, ‘DATASET’, ‘MODEL’ (for ML models), ‘MODEL MONITOR’, ‘STAGE’, ‘INTEGRATION’, ‘STREAM’, ‘TASK’, ‘TASK_GRAPH’, ‘CORTEX_SEARCH_SERVICE’, and ‘CORTEX_AGENT’. TARGET_OBJECT_VERSION | VARCHAR | The version of the target object, for versioned objects such as datasets and models. NULL if the target object is not versioned. TARGET_COLUMN_NAME | VARCHAR | The name of the target column, if the target object is a column. NULL if the target object is not a column. TARGET_STATUS | VARCHAR | The status of the target object. Possible values are ‘ACTIVE’ and ‘MASKED’. ‘MASKED’ means that the current role can’t see the object. For details, see Usage notes. DISTANCE | INTEGER | The distance of the target object from the source object in the lineage path. A direct relationship has a distance of 1. PROCESS | VARIANT | Provides details about how lineage between the source object and target object was established. For example, it might include the query ID of a SQL query or the name of a stored procedure that moved data from the source object to the target object. SOURCE_DETAILS | VARIANT | Additional details about the source object. See Object details. TARGET_DETAILS | VARIANT | Additional details about the target object. See Object details.

Object details

The SOURCE_DETAILS and TARGET_DETAILS columns are populated for every object in the lineage path. Keys with no value for a given object are omitted. Each column contains the following keys: Key | Description dataset_type | The specific type of the object. This is more granular than SOURCE_OBJECT_DOMAIN and TARGET_OBJECT_DOMAIN; for example, an object in the TABLE domain can have a dataset_type of TABLE or VIEW. origin | Where the lineage for the object came from: NATIVE for a Snowflake object, or OPEN_LINEAGE for an object whose lineage was ingested from an external source. namespace | The namespace of the object. Present for objects that aren’t Snowflake objects. external_id | The identifier of the object in the system it originates from. Present for objects that aren’t Snowflake objects.

Example

Assume you have created a table named TABLE_B from TABLE_A using CREATE TABLE AS SELECT, then created a table named TABLE_C from TABLE_B in a similar manner. The following SQL query retrieves two steps of downstream lineage from TABLE_A: The output is similar to the following:

Passing arguments by name

You can pass arguments by name instead of by position, which lets you omit the optional arguments you don’t need. The following query returns the same lineage as the previous example:

Lineage for objects outside Snowflake

Lineage isn’t limited to objects in Snowflake. For information about capturing lineage from an external system, see External lineage. After that lineage is ingested into your account, GET_LINEAGE reports it alongside your Snowflake lineage: - Objects outside Snowflake appear in the output. A lineage path that starts at a Snowflake object can continue into objects that aren’t in Snowflake. The SOURCE_DETAILS and TARGET_DETAILS columns identify these objects; their origin key distinguishes them from Snowflake objects. See Object details. - You can start from an object outside Snowflake. Set object_domain to ‘EXTERNAL’ (or ‘EXTERNAL_COLUMN’ for one of its columns) and pass the object’s namespace along with its name. This is useful for tracing which Snowflake objects an external object feeds, or what feeds it. - A chain of external objects takes one query per step. Lineage can continue from one external object to another: for example, from a Snowflake table to an external object and then on to a second external object. To retrieve the next step in such a chain, run a second query anchored on the external object you reached. For an object that isn’t in Snowflake, SOURCE_OBJECT_DATABASE and SOURCE_OBJECT_SCHEMA (and their target equivalents) are NULL, and the object’s domain is reported as ‘EXTERNAL’ or ‘EXTERNAL_COLUMN’. Assume that TABLE_A is exported to a file, and that lineage for the export has been ingested into your account. The following query retrieves downstream lineage from TABLE_A, extracting the namespace and origin of each target from TARGET_DETAILS: The output is similar to the following, in which the database and schema columns are NULL for the target because the target isn’t a Snowflake object: To retrieve the lineage of the file reached in the previous example, anchor on it: set object_domain to ‘EXTERNAL’ and pass its namespace along with its name. Repeat this pattern to follow a chain of external objects one step at a time.