feat: add data lineage#20198
Open
youngsofun wants to merge 6 commits into
Open
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
youngsofun
marked this pull request as draft
July 24, 2026 04:28
youngsofun
force-pushed
the
codex/lineage-meta-storage
branch
4 times, most recently
from
July 24, 2026 09:14
9997af8 to
a5def34
Compare
This was referenced Jul 24, 2026
youngsofun
force-pushed
the
codex/lineage-meta-storage
branch
from
July 24, 2026 09:45
a5def34 to
f46b5bc
Compare
youngsofun
marked this pull request as ready for review
July 24, 2026 22:37
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
youngsofun
force-pushed
the
codex/lineage-meta-storage
branch
from
July 24, 2026 22:50
f46b5bc to
a01e1f0
Compare
youngsofun
force-pushed
the
codex/lineage-meta-storage
branch
from
July 24, 2026 23:47
a01e1f0 to
74e7d45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This PR adds persistent object-level and column-level data lineage, lifecycle handling, and the Enterprise
GET_LINEAGEtable function.Related PRs
mainand drop that duplicate commit.ALTER VIEWquery and output-column changes. It was split out so the behavioral change can be reviewed independently. This PR no longer contains or depends on that change.The remaining changes stay together because the metadata schema, metadata API, persistence paths, lifecycle behavior,
GET_LINEAGE, and SQL workflow tests share the same identity and column-mapping contract. Intermediate subsets would not provide a complete or meaningfully testable user workflow.Reviewing commit by commit is recommended:
GET_LINEAGEtable function.This PR persists lineage for:
CREATE VIEWCREATE TABLE ... AS SELECT ...(CTAS)INSERT ... SELECTREPLACE INTO ... SELECTUPDATE ... FROMMERGECOPY INTOpersistence hooks are prepared, but extraction ofPlan::CopyIntoTablesources is not included yet.Motivation
Databend currently has no persistent metadata representation for tracing where tables and columns originate or where their data flows. This PR adds persistent bidirectional lineage metadata, column-level mappings, and a Snowflake-style
GET_LINEAGEtable function.Lineage model
A lineage edge always follows the canonical direction:
Objects with stable table IDs use ID-addressed lineage. Name-addressed lineage is used for name-bound dependencies, including view references and tables without stable lineage IDs.
Views form a lineage boundary: DML reading from a view records the view rather than expanding directly to its base tables. Streams behave differently: stream data columns are attributed to the base table, while stream metadata columns are ignored.
Self-referential writes do not create lineage loops. For example,
INSERT INTO t SELECT * FROM tdoes not create at -> tedge.Metadata and persistence
Each edge is stored in both directions under a tenant-scoped structured key. Structured key encoding provides escaping for object names and integrates with metactl, snapshots, backups, and tenant export/filter tooling.
Structural lineage is committed atomically with object metadata for
CREATE VIEWand CTAS. DML lineage is persisted after a successful table commit using a best-effort callback; lineage write failures do not change a successful DML result.DML merge operations preserve the existing lineage kind, update the last query metadata, and merge column edges without duplicates. Lineage metadata does not currently use TTL.
GET_LINEAGE
GET_LINEAGEis implemented as a table function:GET_LINEAGE( '<object_name>', '<object_domain>', '<direction>' [, distance] )Supported domains are
TABLE,VIEW,COLUMN, andSTAGE. Supported directions areUPSTREAMandDOWNSTREAM; distance defaults to 5 and must be between 1 and 5.The implementation uses a distance-ordered BFS. Metadata listing and object resolution are concurrent within each level, while levels remain sequential to preserve distance semantics. Query-time resolution validates the current object and column state.
GET_LINEAGEis gated by the EnterpriseFeature::Lineagelicense feature.Capture configuration
Capture is controlled independently from the Enterprise license:
The default is
false. This allows deployments that need lineage to opt into its planning and metadata costs. Capture remains stable across license changes, while querying throughGET_LINEAGErequires the Enterprise feature.Object lifecycle
Current limitations
COPY INTOsource lineage extraction is not implemented yet.GET_LINEAGEdomain because lineage passes through to its base table.AS MATERIALIZEDCTE lineage is not included yet.Tests
Coverage includes metadata key encoding, protobuf compatibility, lineage API behavior, BFS traversal, column propagation, CTAS, views, DML workflows, multi-table insert, rename/drop/undrop behavior, vacuum cleanup, cross-database ID resolution, self-writes, filter-only columns, aggregate expressions, CTEs, subqueries, and stream passthrough.
Type of change
This change is