Skip to content

Fixes 36357: Hex data models and column-level lineage from SQL cells (2.1) - #36387

Merged
ulixius9 merged 17 commits into
2.1from
ulixius9/hex-datamodels-2.1
Oct 29, 2026
Merged

ulixius9 merged 17 commits into
2.1from
ulixius9/hex-datamodels-2.1

Conversation

@ulixius9

@ulixius9 ulixius9 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #36357

Backport of #36371 to 2.1: the Hex connector ingests one HexDataModel per project, with a column group per SQL cell and column-level lineage from the warehouse tables through chained cells to the dashboard. The design, safety rules and review history are in #36371 and in ADR:2026-10-27-hex-project-is-one-data-model-with-a-column-group-per-cell-id (included here).

The commits of #36371 are cherry-picked with -x, including its last commit (c02d176, a kept data model stays linked). 2.1 is merged in. Its Hex source-URL fix (#36419) conflicted in hex/client.py, so that file and the data model's optional sourceUrl are resolved the same way as on main. Apart from 2.1's own existing baseline entries, the PR's files on this branch are now identical to main. Also carries #36541 (cherry-picked with -x): cells reading a broken cell keep their data model groups, the fix for the edge case Gitar raised on #36388.

Type of change:

  • New feature

Tests:

Unit tests

  • PYTHONPATH=src python -m pytest tests/unit/topology/dashboard/test_hex*.py on this branch → 146 passed.
  • Also clean on this branch: ruff check / ruff format --check, check_ruff_suppressions.py --check, basedpyright on hex/ (0 errors), check_decision_records.py, and the impact-map --check-branch.

Backend integration tests

Manual testing performed

  • Ran this branch's ingestion code against a live Hex workspace (two demo projects on Snowflake) and a local server built from the PR → 0 errors, 0 warnings. The server stored both HexDataModels and accepted all 74 column links.

UI screen recording:

Not applicable: ingestion connector change with no UI code.

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.
  • For JSON Schema changes: no migration is needed; it only adds an enum value.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: the change is Fixes 36357: Hex data models and column-level lineage from project SQL cells #36371 as reviewed there (nine REVIEW.md passes plus the bot reviews), applied unchanged.

RetriggerView in GreptileConfidence Score: 3/5

Fix the lost dashboard link and skipped dashboard-only lineage before merging.

Findings

  1. P1 Saved model loses dashboard link ▶
  2. P1 Dashboard lineage stops updating ▶

Summary

Adds one HexDataModel per Hex project, with stable column groups for SQL cells and column lineage through chained cells.

  • Each Hex project gets a data model with a group for every SQL cell.
  • Hex lineage connects warehouse columns to the outputs of SQL cells.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Hex[Hex project export] --> Cells[SQL cells]
  Cells --> Resolve[Resolve warehouse tables and chained cells]
  Resolve --> Model[One HexDataModel per project]
  Tables[Warehouse columns] --> Model
  Model --> Dashboard[Hex dashboard]
  History[Warehouse query history] --> Dashboard
Loading

Reviews (3) · Last reviewed commit: "Hex: keep models without data connection..." · Reviewed by Greptile

Each Hex project now gets one HexDataModel with a struct column per SQL
cell, holding the columns that cell outputs. Column lineage runs from the
warehouse table columns to those cells, then data model -> dashboard.

The SQL comes from the project export (falling back to the cells API),
which names each cell's result variable, so chained SQL cells are inlined
as CTEs the way Hex runs them and trace back to the warehouse. Input
parameters ({{ x }}) parse as values, and sqlglot resolves each output
column with table schemas from OpenMetadata. The warehouse query history
path stays as the fallback when no cells can be read.

The Hex client retries 429 responses, as Hex rate-limits each endpoint
to about 30 requests per minute.

(cherry picked from commit 33b47d3)
A project whose cells or data connections can't be read keeps the data
model an earlier run created, marked as seen and still linked to its
dashboard, instead of being deleted over a failed API call. A failed
data connections read is retried for the next project rather than cached.

A table reference matching several tables (the same schema.table in two
services, or a bare name) now resolves to none instead of the first
search hit.

(cherry picked from commit 16ad476)
…ailures

- A table reference resolves only when exactly one table matches across
  all db service prefixes, and only with a schema: from the SQL, the Hex
  connection's defaults (now read from the data connections API) or the
  prefix. A bare name is no longer matched in any service.
- Tables the warehouse query history found but no cell resolved still
  link to the dashboard, instead of cells replacing that lineage.
- The cells API stands in for the export only when the export is not
  allowed (403/404). A transient export failure, or a failed table
  search, now leaves the project's data model as it is rather than
  rewriting it from incomplete cells.
- The data model lookup for the dashboard link can no longer fail the
  dashboard, and an unread project's model is marked as seen without one.

(cherry picked from commit 22d96d4)
… names

- Columns resolve case-insensitively, quoted or not, so Snowflake's
  "REGION" and Postgres' "createdAt" match the table's columns instead of
  losing their lineage (a table-qualified one used to drop the whole
  cell). A failed qualify now keeps the columns, without lineage. A column
  passed straight through keeps its table's casing.
- A cell is stored for the cells chained after it once its references
  name the tables found, so tables it found through its connection's
  defaults still resolve from a dataframe cell.
- Column names are made unique after they are made valid, so two
  outputs can no longer collapse into one rejected name.
- Data connections the token can't read (403/404) are treated as none
  known, rather than as a transient failure that would keep every data
  model unchanged forever.

(cherry picked from commit 6af0b43)
- A table reference a cell could not resolve now carries the database and
  schema it was searched under, so a chained cell inlining it, which has
  no connection defaults of its own, can't match a table elsewhere.
- A quoted alias keeps the spelling it was given in the data model.

(cherry picked from commit 791ff4a)
- A table reference a cell could not resolve is marked, and a chained
  cell inlining it leaves it unresolved, rather than searching it again
  without that cell's connection defaults (which could match a table in
  another database through a prefix).
- A warehouse cell only inlines upstream cells on its own connection, as
  Hex does; SQL on dataframes can read any cell's result.
- A UNION branch selecting * from an unknown table no longer drops the
  cell: sqlglot's IndexError there now keeps the columns without lineage.

(cherry picked from commit c42a857)
…odels

- The names a dataframe SQL cell reads are dataframes, so they are never
  looked up as warehouse tables; such a cell reaches the warehouse only
  through the cells it chains to.
- Outputs sharing a name (o.id, c.id, or * over a join) are all kept,
  the repeats suffixed, instead of all but the first being dropped.
- dataModelFilterPattern applies to Hex data models.

(cherry picked from commit cacf30b)
- An inlined upstream cell keeps its own WITH, and table references are
  found scope by scope, so a CTE defined inside an upstream cell can no
  longer capture a warehouse table of the same name the downstream cell
  reads.
- Each cell's column group is named by its stable id (the export's cellId,
  the cells API's staticId) with the label as its display name, so a
  renamed or reordered cell keeps its columns' descriptions, tags and
  lineage.
- Lineage never targets a data model excluded by dataModelFilterPattern,
  which this run deletes.

(cherry picked from commit c5d461c)
- Add ADR:2026-10-27-hex-project-is-one-data-model-with-a-column-group-per-cell-id:
  the data model and its column groups are named by project and cell
  id, tables resolve only uniquely and with a schema, and a failed read
  keeps the existing data model.
- A cell over 10,000 nodes isn't stored for inlining, so a notebook where
  each cell joins the ones before it no longer grows exponentially; the
  cells chained to it keep their columns, without lineage.
- Inlining keeps WITH RECURSIVE, so a recursive CTE isn't looked up as
  a table.
- Only the first branch of a Jinja {% if %} is kept, so the SQL parses.
- A bare * over a join with a dataframe is spelled out per table, so the
  known table's columns are kept.

(cherry picked from commit 61debe6)
The kept-model link now applies dataModelFilterPattern like the data
model and lineage stages, so a dashboard is never pointed at a data
model this run deletes.

(cherry picked from commit 05f7d5c)
…caps

- A t.* is dropped only where t names an unknown table in that SELECT's
  own scope, so an alias reused across CTEs no longer loses the known
  table's columns (and their lineage).
- The table lookup memo is an LRUCache(1000), and a project keeps at most
  100,000 nodes of cell queries for chaining; cells past it are stored as
  unresolvable rather than read as warehouse tables.
- The decision record now also states the child column casing, the
  inlining caps and the 429 retry budget.

(cherry picked from commit d996669)
@ulixius9
ulixius9 requested a review from a team as a code owner October 28, 2026 05:42
@ulixius9
ulixius9 requested review from Khairajani and removed request for a team October 28, 2026 05:42
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/, public/jsons/) have been automatically updated
based on JSON schema changes in this PR.

- Data connections the token can't read raise HexAccessDeniedError and
  are asked for once per run. Without them an existing data model is left
  as it is instead of being rebuilt without dialects and connection
  defaults; only a project without one gets one.
- A cell whose SQL fails to parse keeps its column group from the
  existing data model, with what users curated on it.
- A column name is parsed out of the lineage leaf rather than split on
  dots, so a quoted "customer.id" is one name.
- A column passed straight through keeps its table column's array
  element type, display type and nested fields.

(cherry picked from commit a6b8920)
Comment on lines +400 to +405
except Exception as exc:
# Without the earlier data model, the groups of the cells that failed would be lost
logger.debug(traceback.format_exc())
logger.warning("Could not read the data model of Hex project %s: %s", dashboard_details.id, exc)
self.datamodel_source_state.add(self._build_fqn(DashboardDataModel, dashboard_details))
return

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.

P1 Saved model loses dashboard link

When reading an existing model fails while preserving a failed SQL cell, this path marks the model as seen but yields no model record. _kept_data_model_fqn then skips keeping the link because the cached cell list is not None. The next dashboard request sends dataModels=[], removing the saved model's dashboard link even if the server has recovered.

Track this skipped update as an incomplete read and preserve the existing link.

Knowledge Base Used: Ingestion connectors

Comment on lines +582 to +585
if data_connections is None:
if not self.source_config.includeDataModels or self._data_model_exists(project):
return None
data_connections = {}

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.

P1 Dashboard lineage stops updating

When Hex denies access to data connections, _data_connections now stays None. With includeDataModels=false, this guard returns before reading any SQL cells. That blocks dashboard lineage even for fully qualified table names that need no connection defaults. Tables absent from the available query history get no dashboard link.

Previously, denied access returned {} and those cells were still traced. Keep the protection for existing models without disabling dashboard-only lineage.

Knowledge Base Used: Ingestion connectors

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 80%
80.15% (132353/165126) 66.73% (46863/70226) 69.78% (26578/38083)

# Conflicts:
#	ingestion/src/metadata/ingestion/source/dashboard/hex/client.py
…ugh columns

- A data model kept because its existing groups couldn't be read stays linked
  to the dashboard: the data model stage records what it kept and the dashboard
  stage links it, instead of only when the cells couldn't be read.
- A passed-through struct's fields copy only the table column's type, not its
  description, tags, constraint or profile.

(cherry picked from commit c02d176)
Matches the resolution on main (#36371) of the data model sourceUrl against
the workspace-scoped Hex URLs, which return None when the workspace id can't
be read.
A cell whose SQL fails keeps its existing group, but the cells reading its
result lost theirs: dataframe SQL over it was dropped and a warehouse cell
searched its name as a table, coming back with UNKNOWN columns. A cell reading
a failed cell now fails too, down the chain, so each keeps its group.

(cherry picked from commit ea7e122)
@gitar-bot

gitar-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Hex ingestion now builds project data models and infers column lineage; SQL or table-resolution mistakes could misrepresent catalog dependencies.

Adds Hex data model ingestion with one HexDataModel per project, a column group per SQL cell, and column-level lineage through chained cells to the dashboard. No issues found.

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

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@ulixius9
ulixius9 merged commit 54f4680 into 2.1 Oct 29, 2026
68 of 73 checks passed
@ulixius9
ulixius9 deleted the ulixius9/hex-datamodels-2.1 branch October 29, 2026 11:30
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.

2 participants