Skip to content

Fixes #37803: MicroStrategy column-level lineage from cube SQL to data models - #37804

Merged
Khairajani merged 18 commits into
mainfrom
mstr-column-lineage
Nov 17, 2026
Merged

Khairajani merged 18 commits into
mainfrom
mstr-column-lineage

Conversation

@Khairajani

@Khairajani Khairajani commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #37803

MicroStrategy lineage stopped at table → data model. Each of those edges now carries the column pairs the cube's SQL supports.

  • Matched on what the SQL reads, not on aliases. MicroStrategy names a cube's output columns with generated aliases (WJXBFS1, CATEGORY0). A data model column is matched on the warehouse columns a projection reads. The SQL is read pass by pass, since passes are separated by blank lines, not semicolons.
  • Schema cubes: an attribute form's expression, read through the modeling API, says which (table, column) it can come from. The physical table is named as the SQL names it: its table prefix, else its namespace. A pair the SQL also reads links that column to the attribute's own column (Order), not the form's nested child (Order.ID): the lineage view draws no edge to a nested column. This needs the service account to read schema objects; on HTTP 403, the run logs one warning, makes no further modeling calls and keeps table lineage.
  • Tables are compared on every qualifier both sides name (table, schema, database or project), so same-named tables in different schemas or projects are never linked to each other's columns.
  • Data Import cubes: the modeling API refuses these, so objects are matched on the names the import derives from columns (Order Id ↔ order_id): the column of the same name, else the one column whose normalized name matches (letters of every script kept). An ambiguous match gets no edge.
  • Columns resolve within their own SELECT, so a nested query's aliases never resolve an outer column; a pass that opens with comments is still read.
  • Schema cube metrics get no column edge. The API does not tell which fact column a Workstation metric aggregates, and mapping WJXBFSn to metrics by position would be a guess.
  • A failure while building column lineage drops the column pairs, never the table edge.

Type of change:

  • Improvement

High-level design:

The rules are recorded in a v6 amendment to ADR:2026-11-05-microstrategy-charts-are-named-by-dossier-and-the-search-is-paged.

  • New module column_lineage.py reads the (table, column) pairs each projection reads, with sqlglot.
  • client.py reads attribute forms, logical tables and dataset types, each cached per id.
  • metadata.py adds the pairs to each table → data model edge.

The cost is one modeling call per schema attribute and per logical table per run.

Tests:

Use cases covered

  • A projection whose alias differs from its column (CATEGORY0, WJXBFS1) maps through the column it reads.
  • A multi-pass Data Import SQL is read pass by pass; a note or an unparsable pass is skipped.
  • A schema attribute maps to the column the SQL reads from that table, and nothing else; all of an attribute's forms map to its one column.
  • A schema cube metric gets no column edge.
  • A Data Import cube maps on names, without calling the modeling API.
  • Without modeling privileges, table lineage stays and one warning is logged.
  • A column lineage failure keeps the table edge.
  • A same-named table in another schema or project is never linked.
  • The emitted edge carries the pairs, including for a table the lineage search returned without columns.
  • An unreadable attribute is cached and warned about once; a 403 on an attribute or a table read stops modeling calls.
  • Unicode object names, names that normalize alike, a nested query reusing an outer alias, and a comment-led pass.

Unit tests

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable: there are no MicroStrategy integration tests. The E2E run is under Manual testing.

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

E2E verdict: ✅ pass. #37778 (base) vs this PR, each on a fresh service of a local OpenMetadata server.

  • MicroStrategy trial with a BigQuery warehouse:
    • a schema-based Intelligent Cube (three joined tables, WJXBFS1 metric alias);
    • a Data Import cube over four tables.
  • Public MicroStrategy demo: its schema "Retail Data Cube", lineage to MySQL.
Scenario Base This PR Verdict
Schema cube (trial) 3 table edges, 0 column pairs 3 table edges, 3 pairs: orders.status → Status, products.product_name → Product, order_items.order_id → Order; metric unmapped ✅
Data Import cube (trial) 4 table edges, 0 pairs 4 table edges, 19 pairs, each column to its data model column ✅
Schema cube (demo, generated aliases) 0 pairs 12 pairs, e.g. lu_category.CATEGORY_DESC → Category, lu_region.REGION_NAME → Region ✅
Table lineage unchanged unchanged (same edges) ✅
Column lines drawn on the lineage page (Column layer) none schema and Data Import cubes ✅
Failures 0 0 ✅
  • Run time: the trial run went from 16 s to 20 s, the cost of one modeling call per schema attribute and logical table.
    • The demo varied between 48 s and 78 s across identical runs (base: 23 s). Its guest login is refused 26 attribute reads with 503/504 responses, which the shared HTTP client retries.
    • A service account with the privilege gets normal answers, so this retry cost should not apply there.
  • Not covered E2E:
    • A missing modeling privilege: the trial and the demo both allow attribute reads, so this is covered by a unit test only.
    • Two demo tables (lu_item, lu_employee) get no pairs, because the local MySQL tables were ingested without the columns the cube reads.

UI screen recording:

Ingestion-only change; screenshots of the lineage page (Column layer) for the trial's Data Import cube.

Before (#37778): table lines only, no column lines.
before_collineage_data_import_cube

After (this PR): each warehouse column linked to its data model column.
after_collineage_data_import_cube

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.

  • 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 7d7a5dfb883. One 🔴 fixed: same-named tables in different schemas or projects could be linked; every qualifier is now compared, and forms use the table prefix. Five 🟡 fixed: an edge-level test, a parse timeout, 403-only privilege detection, the ADR wording and the doc wording. Second pass clean. Follow-up: schema pairs targeted nested form columns, which the lineage page never draws; they now target the attribute column, checked in the UI. Review fixes (Unicode and ambiguous name matches, nested-query aliases, comment-led passes, a refused table read): 6 regression tests, each failing before the fix; trial E2E and UI unchanged (22 pairs).

  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.

  • I have added tests around the new logic.

  • For connector/ingestion changes: I updated the documentation.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with no new actionable issues found.

Summary

Adds column lineage from MicroStrategy cube SQL to data model columns while keeping table edges when column lookup fails.

  • MicroStrategy cube lineage now links source and data-model columns.

Reviews (15) · Last reviewed commit: "MicroStrategy: skip a bracket-quoted nam..." · Reviewed by Greptile

- Tell Report Services documents, templates and themes from dossiers by
  viewMedia (the rule MicroStrategy's mstrio-py SDK uses) and skip them
  before reading a definition the dossier API cannot serve.
- Parse each cube's SQL once per cube and dialect instead of once per
  dbServicePrefixes entry and dossier; skip a prefix whose database does
  not match the table's qualifier.
- Give repeated data model column names a suffix, and drop a repeated object.
- Say when a dataset is a report rather than a cube.
A dataset can list its objects in another order on a later run; suffixes
given in listing order would then move a column name to another object.
Data model columns are matched on the warehouse columns each projection of
the cube SQL reads, not on MicroStrategy's generated aliases: schema
attributes through their form expressions (modeling API), Data Import
objects through the names the import derives from columns. Metrics of
schema cubes get no column edge.
Two tables sharing a name in different schemas or projects could be linked
to each other's columns. Forms name their physical table as the SQL does
(table prefix, else namespace), a 403 alone means missing privileges,
and a column parse failure keeps the table list.
@Khairajani
Khairajani requested a review from a team as a code owner November 13, 2026 22:27
@Khairajani
Khairajani requested review from stout-yeoman and removed request for a team November 13, 2026 22:27
@github-actions

github-actions Bot commented Nov 13, 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.

@Khairajani Khairajani added the safe to test Add this label to run secure Github workflows on PRs label Nov 14, 2026
…column

The lineage view draws no edge to a nested data model column, so pairs that
targeted an attribute form (Order.ID) were stored but never shown.
Base automatically changed from mstr-followup-fixes to main November 16, 2026 06:47
if not target:
return
if data_import:
columns = {column for _, column in reads if normalized(column) == normalized(available_object.name)}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you check whether normalization can link unrelated columns?

For example, if a Data Import cube reads both ab and a_b, would a target named ab receive lineage from both?

Distinct Chinese column names also appear to normalize to an empty string. Could we cover these cases with a regression test and skip ambiguous matches?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it could. Fixed in 8d87cc5: an object takes the column of the same name first, else the one column whose normalized name matches. ab vs a_b and distinct Chinese names are covered by regression tests, and ambiguous matches are skipped.

only_table = next(iter(tables.values())) if len(set(tables.values())) == 1 else None
columns = set()
for projection in select.expressions:
for column in projection.find_all(exp.Column):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you check alias resolution when a nested SELECT reuses an outer alias?

  SELECT a.id,
         (SELECT MAX(a.amount) FROM my_schema.refunds a) AS amount
  FROM my_schema.orders a

Would this traversal resolve the inner a.amount against the outer orders table as well, potentially adding an incorrect orders.amount lineage edge? Could we add a regression test to ensure each column resolves within its SELECT scope?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It did resolve against the outer table. Fixed in 8d87cc5: each column now resolves within its own SELECT, with your example as a regression test.

Data Import objects match the column of the same name, else one unique
normalized match that keeps letters of every script; nested queries
resolve columns against their own aliases; comment-led passes are read;
a refused table read stops modeling calls like a refused attribute read.
The dialect and database-name caches are now LRUs capped at CACHE_SIZE,
like the connector's other caches, and database names are read with
model_str.
A repeated comment group in a regex backtracked exponentially on an
unclosed /* (CodeQL). Comments are now skipped by a linear scan, and
passes are split on blank lines, then rejoined where no statement starts.
…ed columns

Passes split on a blank line before a statement, never inside a comment
or quoted text; an unclosed comment ends the scan without swallowing the
pass before it. A correlated column resolves against enclosing queries
when its own query has no such alias. An object listed twice in a dataset
counts once for name matching.
…t escapes

An alias a query defines as a derived table ends the lookup there, so it
never resolves to a same-named outer table. Quoted text in the pass split
honours backslash escapes in the dialects sqlglot reads them in, and its
end is found by a forward scan, so an unclosed string stays linear.
@Khairajani
Khairajani enabled auto-merge (squash) November 16, 2026 10:00
Comment on lines +190 to +191
if isinstance(source, exp.Table):
sources[(source.alias_or_name or source.name).lower()] = table_name_of(source)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you check whether a CTE sharing a physical table’s name could produce an incorrect column match here? For example, could c.id below be attributed to sales.my_table.id, even though it comes from a constant?

     WITH my_table AS (SELECT 1 AS id)
     SELECT c.id FROM my_table c CROSS JOIN sales.my_table t

# A column of a nested query is read with that query, against its own aliases first.
if column.find_ancestor(exp.Select) is not select:
continue
table = _resolve(select, column.table.lower()) if column.table else only_table

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you check how this resolves same-named tables in different schemas? Would this correctly retain s1 for id, or could the second table overwrite the lookup?

     SELECT s1.my_table.id
     FROM s1.my_table CROSS JOIN s2.my_table

…ery qualifier

A CTE named after a physical table no longer links its columns to that table, and a column
qualified as schema.table.column resolves to that schema's table when two same-named tables are
joined. Each SELECT's sources are read once per statement.
…nd cut the SQL view footer anywhere

A CTE body sees only the CTEs before it in a non-recursive WITH, and an UNNEST, VALUES or LATERAL
source is never read as a warehouse table, so an unqualified column is not given to the only real
table beside it. The engine steps block is cut wherever its marker starts, not only at a line start.
@gitar-bot

gitar-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 3 closed / 3 findings

Adding SQL-derived MicroStrategy column lineage and modeling API lookups could attach incorrect column relationships or increase ingestion latency.

Adds MicroStrategy column-level lineage from cube SQL to data model columns, so table-to-data-model edges now carry the column pairs the SQL reads. Resolved in this session: an unclosed-comment test input that never reached the comment branch, a derived-table alias that could resolve to a same-named outer table, and Hive/Spark LATERAL VIEW columns being read as the only table's columns. No open findings remain.

✅ 3 closed
✅ Quality: Unclosed-comment test input never reaches the /* branch

📄 ingestion/tests/unit/topology/dashboard/test_microstrategy.py:1054-1058 📄 ingestion/src/metadata/ingestion/source/dashboard/microstrategy/column_lineage.py:76-79
The input "/" + "//*" * 20000 is ///*//*..., so it starts with //. That is neither -- nor /*, so starts_with_sql goes straight to the SQL_KEYWORD.match branch and returns False on the first character. The unclosed-comment path (close < 0: return False, lines 76-79) never runs. The removed regex was anchored the same way and would also have failed fast on this input, so the test passes against the old code and the new code alike. It doesn't guard against the backtracking regression it's named for, and it doesn't check that an unclosed comment is rejected. To fix this, start the input with /* and leave it unclosed. A blank-line-separated pass that does the same would also cover the sql_passes split.

✅ Edge Case: Derived-table alias can resolve to a same-named outer table

📄 ingestion/src/metadata/ingestion/source/dashboard/microstrategy/column_lineage.py:145-159
_own_tables only collects exp.Table nodes, so it misses a derived table such as (select ...) b. When a nested SELECT reads b.x from its own derived table b, _resolve finds nothing in that scope and keeps walking outward. If an enclosing query has a real table aliased b, the column is credited to that outer table, which produces wrong lineage. Before this change the lookup returned None and no edge was drawn. The docstring says "a reused alias stays the inner one", but that only holds for table aliases. Fix: once an alias is defined in a scope by any FROM/JOIN source (Table, Subquery or CTE reference), stop the walk there and return None if that source is not a base table.

✅ Edge Case: Hive/Spark LATERAL VIEW is still read as the only table's columns

📄 ingestion/src/metadata/ingestion/source/dashboard/microstrategy/column_lineage.py:241-253
exp.Lateral was added to the source search, and the docstring now says LATERAL reads no warehouse column. For Hive/Spark/Databricks LATERAL VIEW explode(arr) t AS c, though, sqlglot puts the Lateral in the Select's laterals arg, not under a From or Join. So find_ancestor(exp.From, exp.Join, exp.Select) returns the Select and the branch skips it. The lateral never becomes a source. In select c from db.tbl lateral view explode(arr) t as c, only_table is still db.tbl and c is reported as (db.tbl, c), which is the false attribution this commit is meant to stop. One fix is to also accept a Lateral whose arg_key == "laterals".

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 merged commit b2c8af2 into main Nov 17, 2026
54 of 57 checks passed
@Khairajani
Khairajani deleted the mstr-column-lineage branch November 17, 2026 06:22
Khairajani added a commit that referenced this pull request Nov 17, 2026
…to data models (#37945)

* Fixes #37803: MicroStrategy column-level lineage from cube SQL to data models (#37804)

* MicroStrategy: skip documents, parse cube SQL once, dedupe columns

- Tell Report Services documents, templates and themes from dossiers by
  viewMedia (the rule MicroStrategy's mstrio-py SDK uses) and skip them
  before reading a definition the dossier API cannot serve.
- Parse each cube's SQL once per cube and dialect instead of once per
  dbServicePrefixes entry and dossier; skip a prefix whose database does
  not match the table's qualifier.
- Give repeated data model column names a suffix, and drop a repeated object.
- Say when a dataset is a report rather than a cube.

* MicroStrategy: suffix repeated column names in id order

A dataset can list its objects in another order on a later run; suffixes
given in listing order would then move a column name to another object.

* MicroStrategy: column-level lineage from cube SQL to data models

Data model columns are matched on the warehouse columns each projection of
the cube SQL reads, not on MicroStrategy's generated aliases: schema
attributes through their form expressions (modeling API), Data Import
objects through the names the import derives from columns. Metrics of
schema cubes get no column edge.

* MicroStrategy: compare every table qualifier in column lineage

Two tables sharing a name in different schemas or projects could be linked
to each other's columns. Forms name their physical table as the SQL does
(table prefix, else namespace), a 403 alone means missing privileges,
and a column parse failure keeps the table list.

* MicroStrategy: cache an unreadable schema attribute and warn once

* MicroStrategy: link schema attribute column lineage to the attribute column

The lineage view draws no edge to a nested data model column, so pairs that
targeted an attribute form (Order.ID) were stored but never shown.

* MicroStrategy: tighten column lineage matching from review

Data Import objects match the column of the same name, else one unique
normalized match that keeps letters of every script; nested queries
resolve columns against their own aliases; comment-led passes are read;
a refused table read stops modeling calls like a refused attribute read.

* MicroStrategy: bound the service lookup caches

The dialect and database-name caches are now LRUs capped at CACHE_SIZE,
like the connector's other caches, and database names are read with
model_str.

* MicroStrategy: skip leading SQL comments without a backtracking regex

A repeated comment group in a regex backtracked exponentially on an
unclosed /* (CodeQL). Comments are now skipped by a linear scan, and
passes are split on blank lines, then rejoined where no statement starts.

* MicroStrategy: split cube SQL passes in one scan and resolve correlated columns

Passes split on a blank line before a statement, never inside a comment
or quoted text; an unclosed comment ends the scan without swallowing the
pass before it. A correlated column resolves against enclosing queries
when its own query has no such alias. An object listed twice in a dataset
counts once for name matching.

* MicroStrategy: stop alias lookups at derived tables and honour dialect escapes

An alias a query defines as a derived table ends the lookup there, so it
never resolves to a same-named outer table. Quoted text in the pass split
honours backslash escapes in the dialects sqlglot reads them in, and its
end is found by a forward scan, so an unclosed string stays linear.

---------

Co-authored-by: Pablo Takara <[email protected]>
(cherry picked from commit b2c8af2)

* MicroStrategy: link no column to Data Import objects that share a name

---------

Co-authored-by: Pablo Takara <[email protected]>
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.

MicroStrategy: column-level lineage from cube SQL to data models

3 participants