Skip to content

Fixes #35319: Add lineage to the Databend connector - #35320

Merged
Khairajani merged 2 commits into
open-metadata:mainfrom
youngsofun:feat/databend-lineage
Oct 16, 2026
Merged

Khairajani merged 2 commits into
open-metadata:mainfrom
youngsofun:feat/databend-lineage

Conversation

@youngsofun

@youngsofun youngsofun commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #35319

Adds lineage to the Databend connector. Databend records table and column lineage from its query planner into system_history.lineage_history; the new lineage source reads those records directly instead of parsing SQL.

Type of change:

  • New feature

High-level design:

  • databend/lineage.py — DatabendLineageSource(LineageSource), registered as lineage_source_class, so it runs in the standard lineage pipeline.
    • processViewLineage → CREATE_VIEW records. Only the latest CREATE VIEW of each view is used; with overrideViewLineage, stale upstreams are removed through the existing override_lineage mechanism.
    • processQueryLineage → CTAS / DML records within queryLogDuration.
  • Scope: only edges whose both endpoints are tables or views of the default catalog, matching what the connector ingests. Self-edges from in-place DML are dropped.
  • Edges: records are merged per (source, target); column mappings are unioned and kept only when both columns exist in OpenMetadata; the latest query becomes sqlQuery. Endpoints are resolved by FQN (bounded LRU cache); endpoints not yet ingested are skipped and picked up on a later run. schemaFilterPattern / tableFilterPattern apply to both ends.
  • When lineage is unavailable (history tables or lineage disabled, missing SELECT on system_history, license, Databend older than v1.2.933), the lineage workflow reports one failure explaining the missing requirement, mapped from the Databend error code. Metadata, profiler and data quality are unaffected, and the new GetLineage test-connection step is optional.
  • Schema: databendConnection.json declares supportsLineageExtraction so the UI offers a Lineage ingestion; derived artifacts regenerated. No migration needed (field with a default, no stored data change).
  • Alternatives considered: parsing view definitions and query history like other connectors — rejected because Databend already records exact, column-level lineage from the planner, and query_log does not record the current catalog.

Tests:

Use cases covered

  • CTAS, INSERT ... SELECT with a cross-database join, two-level CTAS chains and views produce table and column lineage in OpenMetadata.
  • A replaced view only keeps the upstreams of its latest definition.
  • External-catalog edges are ignored; edges to tables not yet ingested are skipped.
  • Missing history tables, disabled lineage, missing privilege, license errors and older Databend versions produce a specific error in the lineage workflow while test connection (except the optional GetLineage) and metadata ingestion keep working.

Unit tests

  • ingestion/tests/unit/source/database/databend/test_lineage.py — runs the real lineage query against an emulated system_history.lineage_history: filters, merging, latest view definition, column filtering, missing endpoints, error hints, single failure per run.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • ingestion/tests/integration/databend/test_lineage.py — starts Databend with lineage and history tables enabled, runs metadata + lineage workflows and asserts table, column and view lineage in OpenMetadata. Skipped when Databend rejects the Enterprise license.
  • Ran tests/integration/databend locally: 11 passed.

Manual testing performed

  1. Started a standalone Databend with [lineage] and [log.history] enabled and created tables with CTAS, INSERT ... SELECT, a cross-database join and views.
  2. Ran metadata and lineage ingestion against a local OpenMetadata server built from this branch.
  3. Verified table and column lineage in the lineage view (screenshots below).
  4. Verified the error message of the lineage workflow on Databend with history tables disabled, lineage disabled, a user without system_history privileges, and Databend v1.2.930.

UI screen recording:

lineage-customer-revenue-columns lineage-agg-customer-sales-columns

Checklist:

  • I have read the CONTRIBUTING document.

  • My PR title is Fixes <issue-number>: <short explanation>

  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.

  • I have commented on my code, particularly in hard-to-understand areas.

  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.

  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).

  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

  • Decision check: no durable decision beyond this connector's behavior.

  • The issue properly describes why the new feature is needed, what's the goal, and how we are building it.

  • I have updated the documentation.

  • I have added tests around the new logic.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@youngsofun
youngsofun marked this pull request as draft October 13, 2026 08:41
@youngsofun
youngsofun force-pushed the feat/databend-lineage branch from 1bcbb9f to eab051a Compare October 14, 2026 09:03
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@youngsofun
youngsofun force-pushed the feat/databend-lineage branch from eab051a to 5a2e316 Compare October 14, 2026 12:53
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

…tory

Add a Databend lineage source that reads table and column lineage recorded by
Databend's query planner from system_history.lineage_history instead of
parsing SQL.

- View lineage comes from CREATE_VIEW records; only the latest definition of a
  view is used, and overrideViewLineage clears stale upstreams.
- Query lineage comes from CTAS and DML records within queryLogDuration.
- Only edges whose both endpoints are tables or views of the default catalog
  are read, matching the catalogs the connector ingests.
- Endpoints not yet ingested in OpenMetadata are skipped; columns are kept only
  when present on both tables.
- When lineage_history cannot be read, the workflow reports one failure that
  explains the missing requirement (history tables, lineage, privileges,
  license or Databend version). Other workflows are unaffected; the
  GetLineage test-connection step is optional.
- Declare supportsLineageExtraction and regenerate the derived artifacts.

Integration tests skip the lineage cases when Databend rejects the license.
@youngsofun
youngsofun force-pushed the feat/databend-lineage branch from 58224fc to a514ebc Compare October 14, 2026 14:26
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@youngsofun
youngsofun marked this pull request as ready for review October 14, 2026 15:06
@youngsofun

Copy link
Copy Markdown
Contributor Author

@ulixius9 could you add safe to test when convenient? All Gitar findings are addressed (3/3 closed), the branch is rebased on the latest main, and unit plus lineage integration tests pass locally. I won't push further changes while CI runs. Thanks!

@ulixius9 ulixius9 added the safe to test Add this label to run secure Github workflows on PRs label Oct 15, 2026
@github-actions github-actions Bot removed the safe to test Add this label to run secure Github workflows on PRs label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@gitar-bot

gitar-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 3 closed / 3 findings

🔴 High risk · With overrideViewLineage enabled, the Databend source deletes stored view-lineage edges without emitted replacements, which could remove valid lineage relationships.

Adds Databend lineage by reading table and column edges from system_history.lineage_history rather than parsing SQL, registered as a standard lineage source. Resolved: old view upstreams are no longer reused when the latest CREATE VIEW has no matching rows, the replaced-view grace period is now documented as a judgment call, and stale view lineage is no longer kept when all current-definition edges are dropped. No open issues found.

✅ 3 closed
✅ Edge Case: Old view upstreams are reused when the latest CREATE VIEW has no matching rows

📄 ingestion/src/metadata/ingestion/source/database/databend/lineage.py:146-160 📄 ingestion/src/metadata/ingestion/source/database/databend/queries.py:25-31
merge_lineage_rows picks each view's latest definition only from rows that survive the SQL WHERE in DATABEND_LINEAGE_HISTORY, which keeps only default-catalog TABLE/VIEW endpoints. Some redefinitions produce no surviving rows: a view rebuilt with CREATE OR REPLACE VIEW to read only from an external catalog or a stage, or to select constants. In that case latest_view_query[target] points at the previous definition, so its old upstreams are emitted again as ViewLineage. With overrideViewLineage the run deletes the view's lineage and then writes those old edges back, which breaks the PR's claim that only the latest definition is used. To fix it, find each view's latest CREATE_VIEW query_id with no catalog or object-type filter (for example a subquery or a separate SELECT target_database, target_name, argMax(query_info:query_id, updated_on)). Then keep only rows matching that id. If no row matches, emit nothing for the view, so the override can still clear it.

✅ Quality: 5-minute replaced-view grace period is an unrecorded judgment call

📄 ingestion/src/metadata/ingestion/source/database/databend/lineage.py:67-70 📄 ingestion/src/metadata/ingestion/source/database/databend/lineage.py:308-322
REPLACED_VIEW_GRACE_PERIOD = timedelta(minutes=5) decides how long a view that was replaced with no upstream keeps its old ViewLineage before _clear_replaced_view_lineage deletes it. The value is a judgment call about how quickly Databend flushes its history tables. If it is too short, correct lineage gets deleted when a flush runs slow. If it is too long, stale lineage stays visible longer. No record under docs/decisions/ states this rule, and the PR's "Decision check: no durable decision" box doesn't cover it. The record would say: "With overrideViewLineage on, the Databend lineage source removes the ViewLineage of a view whose current definition has no recorded upstream only after 5 minutes have passed since system.views.updated_on, measured on Databend's clock, because lineage_history is flushed asynchronously."

✅ Edge Case: Stale view lineage kept when all current-definition edges are dropped

📄 ingestion/src/metadata/ingestion/source/database/databend/lineage.py:236-239 📄 ingestion/src/metadata/ingestion/source/database/databend/lineage.py:274-280 📄 ingestion/src/metadata/ingestion/source/database/databend/lineage.py:299-313
_clear_replaced_view_lineage only clears views that have no record in current_rows. A view can have current records and still get no request, because _yield_requests drops edges whose source matches schemaFilterPattern/tableFilterPattern or isn't ingested yet. Example: CREATE OR REPLACE VIEW v AS SELECT * FROM excluded_db.t. That view counts as current, so it is never cleared, and since no OMetaLineageRequest with override_lineage is emitted, its upstreams from the old definition stay in OpenMetadata even with overrideViewLineage on. This is the exact case the docstring says this method handles ("No lineage request is emitted for them"). Fix: build the clear set from the views that actually got a request, not from current_rows.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Khairajani Khairajani added the safe to test Add this label to run secure Github workflows on PRs label Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❌ UI Checkstyle Failed

❌ Bundle Runtime Check

A route chunk loads but one of its chunks still exports undefined: a chunking change broke module initialisation. Run yarn build && yarn bundle:runtime locally.


Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 77%
77.81% (126668/162785) 64.43% (80077/124268) 65.66% (26721/40692)

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@Khairajani
Khairajani enabled auto-merge October 16, 2026 08:22
@Khairajani
Khairajani added this pull request to the merge queue Oct 16, 2026
Merged via the queue into open-metadata:main with commit 2a60eab Oct 16, 2026
114 of 132 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lineage support for the Databend connector

5 participants