Area: Ingestion Issues
Sub-Area: SQL Connector Lineage Configuration
Applies to: OSS + Cloud
Issue
A SQL Server stored procedure copies data from one or more source databases into another database on the same server, for example a warehouse database. Ingestion succeeds, but the procedure's lineage in DataHub is missing the tables that live in the other databases.
This article covers the SQL Server source (type: mssql or mssql-odbc). The settings below are SQL Server settings. Other SQL connectors don't have all of them.
You Might Be Asking
- Why doesn't lineage show for tables that a stored procedure fills, even though ingestion completes?
- How do I get cross-database lineage from SQL Server stored procedures?
- Why are upstream tables from another database missing from the procedure's lineage?
- What permissions does the DataHub login need to read stored procedure definitions?
Cause
The SQL Server source parses each stored procedure's code after it has scanned every database in the run. It keeps a table in the procedure's lineage only when it finds that table among the tables it knows. It treats any other table as a temporary table and leaves it out of the lineage. The run report shows no warning for a table it left out.
When the recipe sets database (or sqlalchemy_uri), the source reads only that one database. Tables in the other databases are then not scanned, and the procedure loses those edges.
Solution
-
Let the recipe read every database the procedure uses. Remove
databaseandsqlalchemy_urifrom the recipe. With neither set, the source lists all databases on the server and ingests each one thatdatabase_patternallows. To limit the scope, usedatabase_patternwith an allow list that includes the source databases and the destination database. -
Leave stored procedure lineage on.
include_stored_proceduresandinclude_lineageboth default totrue. If either isfalse, the source builds no stored procedure lineage. -
Make sure the DataHub login can connect to each database. If the login can't open a database, the run report shows
Error logging in to databasefor it and the source skips that database, so lineage to its tables is lost. -
Grant the permissions from the SQL Server source prerequisites. In each database that holds tables or procedures:
USE [DATA_DB_NAME] GRANT VIEW DEFINITION TO [USERNAME] GRANT SELECT ON OBJECT::sys.sql_expression_dependencies TO [USERNAME]The same page lists the
msdbpermissions for SQL Server Agent jobs. -
Review the URN case settings. When
convert_urns_to_lowercaseorconvert_column_urns_to_lowercaseisfalse(the default), the run report shows this warning:Lineage may not resolve accurately because 'convert_urns_to_lowercase' is False. To ensure correct lineage, set 'convert_urns_to_lowercase' to True.Read the caution below before you turn these on for a source you already ingest.
-
Run the ingestion again. Each stored procedure appears as a Data Job, with the tables it reads as inputs and the tables it writes as outputs.
Example recipe:
source:
type: mssql
config:
host_port: "<your-host>:1433"
username: "<your-service-account>"
password: "<your-password>"
# No "database" key, so every allowed database on the server is read.
database_pattern:
allow:
- "^SourceDb1$"
- "^SourceDb2$"
- "^Warehouse$"
include_stored_procedures: true
include_lineage: true
convert_urns_to_lowercase: true
convert_column_urns_to_lowercase: true
sink:
type: datahub-rest
config:
server: "https://<your-datahub-host>/gms"
token: "<your-datahub-token>"
You don't need include_query_lineage or include_usage_statistics for stored procedure lineage. Those read query history and need VIEW SERVER STATE and SQL Server 2016 or later.
If parsing fails for a procedure, the run report shows Failed to parse stored procedure lineage with the procedure name.
Caution: convert_urns_to_lowercase is part of each dataset URN, and it defaults to false. If you already ingested SQL Server with mixed case names, turning it on changes the URN of every such dataset (Warehouse.dbo.Orders becomes warehouse.dbo.orders). With stateful ingestion, the next run soft deletes the old datasets as stale. If more than fail_safe_threshold percent (75 by default) of the entities changed, the run soft deletes nothing, reports Skipping stateful ingestion / stale entity removal, and you get duplicates. Without stateful ingestion, you get duplicates. Documentation, tags, owners and glossary terms added in the UI stay on the old datasets. Choose the value before the first run, or plan how to move that metadata before you switch.
Related Documentation
Tags: stored-procedure, lineage, mssql, sql-server, cross-database-lineage, ingestion-configuration, include_stored_procedures, convert_urns_to_lowercase, data-job