Area: Ingestion
Sub-Area: Lineage
Applies to: OSS + Cloud
Issue
Query-based lineage from Snowflake query logs is incomplete, has missing tables, or shows wrong relationships. Common causes are a recipe that fails validation, a time window that is too short, missing grants, or a SQL query that DataHub can't parse.
You Might Be Asking
- Why is my query-based lineage incomplete?
- How far back does DataHub look for query history?
- How do I test whether DataHub can parse a query?
Cause
- Snowflake table lineage and column lineage are on by default. You don't need to enable them. Column lineage needs
include_table_lineageto be true, Snowflake Enterprise Edition or above, and the right grants on the role. - The time window controls how much query history DataHub reads.
start_timeaccepts relative values such as-7d.end_timeis a plain datetime that defaults to now in UTC. It does not accept relative values such as-1d. - Recipes reject unknown keys, so a key the Snowflake source doesn't define fails validation.
sql_parseris one example. Remove it. -
include_view_lineageandinclude_view_column_lineagewere removed from the Snowflake source in December 2024. DataHub drops them with a warning. View lineage is always ingested when view definitions are available. -
use_queries_v2already defaults to true. It selects the queries extractor. It is not a parsing-quality switch. - If DataHub can't parse a query at the table level, it drops the query and the query gives no lineage. If only column-level parsing fails, table lineage is kept and column lineage for that query is lost.
Solution
- Use a valid recipe. The lineage settings are defaults, so you can leave them out. Set only the lookback window.
source:
type: snowflake
config:
# ... connection settings ...
start_time: "-30d"
To end the window at a fixed time, set end_time to an absolute datetime. Remove sql_parser, include_view_lineage and include_view_column_lineage from your recipe.
-
Check the role's grants. Snowflake lineage needs appropriate grants on the role and Enterprise Edition or above. See the Snowflake prerequisites for the exact grants.
-
Test how DataHub parses a query. Run the CLI:
datahub check sql-lineage --platform snowflake --sql "SELECT * FROM db.schema.table1 JOIN db.schema.table2"
Use --sql-file <file> for a longer query. Optional flags are --platform-instance, --env, --default-db and --default-schema. The command runs online by default. It uses schema information from DataHub and produces column-level lineage. With --offline, or when tables are missing from DataHub, results are less accurate. From Python, you can call DataHubGraph.parse_sql_lineage(sql, platform=...), which returns a SqlParsingResult. See SQL parsing.
-
To see why a query failed, check the ingestion run report. It records parse failures at any log level.
observed_query_parse_failureslists each error with the first 100 characters of the query.num_observed_queries_failedandnum_observed_queries_column_failedcount the failures.views_parse_failuresandnum_views_failedcover view definitions. For the full error text in the log, set the log level to DEBUG. The aggregator then logsError parsing query <query>: <error>. -
For a query that still doesn't parse, add the lineage yourself. Use a patch so you add one edge and leave the other edges alone. A connector with
incremental_lineageset to false (the default) re-states lineage on each run. Snowflake URNs are lowercase by default, so copy the exact URN from DataHub.
from datahub.emitter.mce_builder import make_dataset_urn
from datahub.ingestion.graph.client import DataHubGraph
from datahub.ingestion.graph.config import DatahubClientConfig
from datahub.metadata.schema_classes import DatasetLineageTypeClass, UpstreamClass
from datahub.specific.dataset import DatasetPatchBuilder
graph = DataHubGraph(DatahubClientConfig(server="http://localhost:8080", token="<token>"))
upstream = UpstreamClass(
dataset=make_dataset_urn("snowflake", "db.schema.source", "PROD"),
type=DatasetLineageTypeClass.TRANSFORMED,
)
downstream_urn = make_dataset_urn("snowflake", "db.schema.target", "PROD")
patch = DatasetPatchBuilder(downstream_urn).add_upstream_lineage(upstream)
for mcp in patch.build():
graph.emit(mcp)
On Cloud, use https://<tenant>.acryl.io/gms as the server and a personal access token. See Add lineage with the SDK and the emitter guide.
- To track the time window between runs, set
enable_stateful_time_window: true. It defaults to false. Withuse_queries_v2on (the default),stateful_ingestion.enabledalone doesn't track the window. The olderenable_stateful_lineage_ingestionandenable_stateful_usage_ingestionflags work only whenuse_queries_v2is false.