Skip to content

Fixes 37077: Hex lineage links source tables to the data model, not dashboard - #37078

Merged
ulixius9 merged 8 commits into
mainfrom
ulixius9/hex-source-lineage
Nov 5, 2026
Merged

ulixius9 merged 8 commits into
mainfrom
ulixius9/hex-source-lineage

Conversation

@ulixius9

@ulixius9 ulixius9 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #37077

Hex dashboards showed source tables wired straight to the dashboard, several of them tables the project never reads. Tables found only in the warehouse query history were linked to the dashboard instead of the data model. And because LineageParser lower-cases names, a BigQuery crm.Account missed its exact lookup and fell back to every account table in the project. Every Hex table edge now goes to the project's data model, query-history edges at node level only. A reference that names a schema never leaves it, and a lower-cased BigQuery name resolves to its single case-insensitive match.

Type of change:

  • Bug fix

High-level design:

  • One lineage target (hex/metadata.py): _lineage_target returns the data model while data models are on, and the dashboard only when they are off or the project's data model is filtered out. Cell edges (with column lineage) and query-history edges (without, since history can't say which cell read the table) both use it.
  • A data model wherever there are tables to link: a project whose cells output no columns, or can't be read, but read tables or show up in the query history gets a data model without columns. One without columns is kept when this run finds no tables for it, or when its lookup fails, so a project idle past the history's 7-day window, or a failed lookup, doesn't delete it and its lineage.
  • Query-history resolution (hex/query_fetcher.py): asks for the schema-less fallback only on a bare table name, and drops a bare name that matches several tables, as cells already do. The shared get_table_entities_from_query is untouched, since Dremio/Postgres view lineage relies on its fallback.
  • BigQuery (bigquery/resolution.py): a scoped reference that misses its exact name and any shard family takes the one case-insensitive match, none when several match (BigQuery names are case-sensitive). This applies to every scoped BigQuery lookup, not only Hex.
  • Decision records: amended ADR:2026-10-27-hex-project-is-one-data-model-with-a-column-group-per-cell-id (v3) and ADR:2026-11-03-bigquery-daily-shards-use-stable-logical-tables (v2).
  • Rollout: edges already linked to the dashboard by earlier runs stay until removed (lineage is additive).
  • Follow-ups:
    • Query-history SQL could run through the cell pipeline, keyed by the static_cell_id each Hex query carries, to give those edges column lineage.
    • A schema-qualified reference from a warehouse whose history has no database name can still match the same schema in several databases. This predates this PR.

Tests:

Use cases covered

  • A table the query history names but no cell resolved links to the data model, not the dashboard.
  • A lower-cased BigQuery reference finds its mixed-case table and never matches same-named tables in other schemas. Two case variants resolve to none.
  • A bare name matching several tables links none.
  • Unreadable cells, or cells that read tables but output no columns, still produce a data model to link to.
  • A data model built from query history alone survives an empty history window and a failed lookup. One whose SQL cells are all gone is still deleted, including one without columns that a cell created (raised by Gitar).
  • With data models off, tables still link to the dashboard.

Unit tests

  • I added unit tests for the new/changed logic. Each new guard fails with its fix reverted.
  • Files: tests/unit/topology/dashboard/test_hex_cell_lineage.py, tests/unit/entity_resolution/test_resolver.py, tests/unit/topology/dashboard/test_hex_ingestion_flow.py (pinned to includeDataModels: false to keep exercising the dashboard path).
  • Ran every unit test importing a changed module, plus tests/unit/topology/dashboard: 1738 passed, 1 skipped.
  • Wider sweep (tests/unit/utils, entity_resolution, lineage, topology): 7077 passed. The 3 failures in topology/pipeline/test_airflow_connection.py come from my local Airflow config (No module named 'cwl_airflow') and are unrelated.
  • Coverage on changed classes: hex/metadata.py 93%, bigquery/resolution.py 96%, hex/query_fetcher.py 80%. The fetcher's warehouse-connection code is only reached by integration tests.

Backend integration tests

  • Not applicable (no backend API changes, no Java changes).

Ingestion integration tests

  • I ran the integration tests covering my changed files locally. Not run: the Docker daemon isn't available on this machine. The covering test is tests/integration/ometa/test_hex_sharding_search.py, which the merge queue runs.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Diagnosed from a Hex ingestion debug log of a real workspace. The cells had resolved the mixed-case BigQuery tables onto the data model with column lineage. The query-history pass then linked eight same-named tables from unrelated datasets straight to the dashboard.
  2. Not yet re-run against a live workspace. The unit tests replay that scenario: lower-cased reference, same-named tables in other schemas, history-only tables.

UI screen recording:

Not applicable — ingestion-only bug fix.

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. (No schema changes.)

  • For a UI feature or feature task: Docker build + recording. (Not applicable, no UI.)

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

  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.

    • Reviewed at 7d6bc3e0089, no 🔴. Earlier passes found four, all fixed: a Dremio view-lineage regression from changing the shared helper; lineage dropped for projects without a data model; a column-less data model deleted after the history window; and the same deleted when its lookup fails. The local test run also caught the case-insensitive search preempting the shard-family lookup, fixed too.
  • Decision check: amends ADR:2026-10-27-hex-project-is-one-data-model-with-a-column-group-per-cell-id (v3) and ADR:2026-11-03-bigquery-daily-shards-use-stable-logical-tables (v2).

  • I have added a test that covers the exact scenario we are fixing.

Tables only the warehouse query history names now link to the project's
data model at node level instead of straight to the dashboard. A project
whose cells give no columns still gets a data model when the query history
names tables for it.

The query-history lookup no longer drops a schema the query names, and
BigQuery resolution retries a missed exact name case-insensitively, taking
only a single match: LineageParser lower-cases Account to account, which
used to fall back to every same-named table in the database.
A shard name such as events_20260101 misses the exact lookup by design;
the family resolves it without a search request.
…ta model

Address self-review findings:
- Leave get_table_entities_from_query as it was: Dremio view lineage relies on
  its schema fallback for nested folders. The Hex query fetcher now only asks
  for the fallback on a bare table name.
- A project with tables to link but no columns (unreadable cells, or cells
  that read tables yet output none) gets a data model without columns, so its
  lineage isn't dropped.
- Keep a data model without columns when this run finds no tables for it: the
  query history only looks back seven days.
…ames

- A data model without columns whose lookup fails is kept rather than
  deleted with its lineage.
- A bare name in the query history that matches several tables links none,
  as for cells.
- Record the BigQuery case-insensitive retry in its own decision record.
@ulixius9
ulixius9 requested a review from a team as a code owner November 4, 2026 16:29
@ulixius9
ulixius9 requested review from akashverma0786 and a balanced review from Copilot November 4, 2026 16:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 4, 2026

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 github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 05:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

A column-less data model with SQL came from cells, which are read each
run; keeping it after they are deleted left it and its lineage behind.
Copilot AI balanced review requested due to automatic review settings November 5, 2026 05:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…othing

A data model only the query history fills was saved with the SQL of
cells that read no resolvable table, so once its tables left the
history's lookback window it looked built from cells and was deleted
with its lineage. Write SQL only when the cells gave the data model
columns or tables.
Copilot AI balanced review requested due to automatic review settings November 5, 2026 07:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@gitar-bot

gitar-bot Bot commented Nov 5, 2026

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

🟡 Medium risk · Redirecting Hex lineage to data models and adding case-insensitive BigQuery resolution could misattribute source tables or omit lineage when names are ambiguous.

Hex lineage now links source tables to the project's data model instead of the dashboard, and BigQuery case-insensitive references resolve to their single match. A data model with no columns that a deleted SQL cell had created is now removed correctly. No open issues found.

✅ 1 closed
✅ Edge Case: Columnless data model from a deleted SQL cell is never removed

📄 ingestion/src/metadata/ingestion/source/dashboard/hex/metadata.py:672-676 📄 ingestion/src/metadata/ingestion/source/dashboard/hex/metadata.py:701-715 📄 ingestion/src/metadata/ingestion/source/dashboard/hex/metadata.py:687
_keep_columnless_data_model keeps any existing data model that has no columns. It does not check whether that model came from the query history or from SQL cells that output no columns. Here is how a model gets stuck. A project has a cell select * from sales.orders on a table with no columns, so this PR creates a columnless data model (test_a_cell_whose_table_gives_no_columns_still_links_it_to_a_data_model). The user then deletes the cell, and the query history no longer mentions the project. On the next run columns is empty and there are no tables, so yield_datamodel calls _keep_columnless_data_model. That marks the model as seen, so the model and its stale orders edge survive every later run. This goes against the stated rule that such a model "is deleted only when its SQL cells are gone". A columnless model created by history alone has sql=None, but one built from cells stores their SQL. Only keep the model when it has no sql; a model that has sql came from cells that are now gone.

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

@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@ulixius9
ulixius9 merged commit 75b1bbd into main Nov 5, 2026
70 of 71 checks passed
@ulixius9
ulixius9 deleted the ulixius9/hex-source-lineage branch November 5, 2026 13:20
ulixius9 added a commit that referenced this pull request Nov 5, 2026
…ashboard (#37078) (#37166)

* fix(hex): link source tables to the data model, never the dashboard

Tables only the warehouse query history names now link to the project's
data model at node level instead of straight to the dashboard. A project
whose cells give no columns still gets a data model when the query history
names tables for it.

The query-history lookup no longer drops a schema the query names, and
BigQuery resolution retries a missed exact name case-insensitively, taking
only a single match: LineageParser lower-cases Account to account, which
used to fall back to every same-named table in the database.

* fix(bigquery): try a shard family before a case variant

A shard name such as events_20260101 misses the exact lookup by design;
the family resolves it without a search request.

* fix(hex): keep the query-history schema rule to Hex, give tables a data model

Address self-review findings:
- Leave get_table_entities_from_query as it was: Dremio view lineage relies on
  its schema fallback for nested folders. The Hex query fetcher now only asks
  for the fallback on a bare table name.
- A project with tables to link but no columns (unreadable cells, or cells
  that read tables yet output none) gets a data model without columns, so its
  lineage isn't dropped.
- Keep a data model without columns when this run finds no tables for it: the
  query history only looks back seven days.

* fix(hex): keep a data model whose lookup fails, skip ambiguous bare names

- A data model without columns whose lookup fails is kept rather than
  deleted with its lineage.
- A bare name in the query history that matches several tables links none,
  as for cells.
- Record the BigQuery case-insensitive retry in its own decision record.

* chore(hex): prune G004 baseline entries for removed log calls

* fix(hex): only keep a column-less data model built from query history

A column-less data model with SQL came from cells, which are read each
run; keeping it after they are deleted left it and its lineage behind.

* fix(hex): keep a query-history data model beside cells that resolve nothing

A data model only the query history fills was saved with the SQL of
cells that read no resolvable table, so once its tables left the
history's lookback window it looked built from cells and was deleted
with its lineage. Write SQL only when the cells gave the data model
columns or tables.

* fix(hex): apply the prefix filter before judging a bare name ambiguous

(cherry picked from commit 75b1bbd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion 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.

Hex: query-history lineage links unrelated tables straight to the dashboard

3 participants