Skip to content

Fixes #38334: MicroStrategy column lineage for schema cube metrics - #38335

Merged
Khairajani merged 6 commits into
mainfrom
mstr-metric-column-lineage
Nov 24, 2026
Merged

Khairajani merged 6 commits into
mainfrom
mstr-metric-column-lineage

Conversation

@Khairajani

@Khairajani Khairajani commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38334

Metrics of schema-based MicroStrategy cubes now get column-level lineage. Until now they got table-level lineage only.

  • By the SQL alias: the SQL names a metric's projection after the column alias set on it, else, on servers that derive aliases from names, after its name: Revenue Rank becomes REVENUERANK. The metric is linked to the warehouse columns that projection reads. The column alias is read from the metric's definition, so metric column lineage needs Architect read; without it, metrics get no column edge rather than a guessed one.
  • By its definition, otherwise: with Architect read, the metric is followed to the metrics and facts it is built from.
    • The definition is read as resolved tokens, because only the tokens resolve the fact inside a metric built in Workstation.
    • A component the SQL names takes that alias's columns.
    • A fact takes the columns its expressions map to.
  • An alias is a metric's only when no other dataset object claims it. Every object first claims the name it is projected under (a metric its column alias, else its name), so a metric named Revenue but aliased NETAMOUNT never takes another metric's REVENUE. Referenced metrics are matched on their own alias too, even ones the dataset does not hold. A metric that cannot be read still claims its name, so it blocks that projection without getting a link.
  • No link: a metric derived in a dossier, or a metric that cannot be read. Generated WJXBFSn aliases are never mapped by position.
  • Cost: every schema cube metric costs one modeling call per run, for its column alias; one the SQL does not name costs one more per metric and fact it is built from. All are cached per id.
  • Attribute forms change too: form expressions now map every column they name, so a derived form such as ApplySimple over two columns links both.

Type of change:

  • Improvement

High-level design:

Recorded in a v8 amendment to ADR:2026-11-05-microstrategy-charts-are-named-by-dossier-and-the-search-is-paged.

Tests:

Unit tests

  • Added to ingestion/tests/unit/topology/dashboard/test_microstrategy.py, 125 pass:
    • the columns each projection alias reads;
    • a metric linked by its alias;
    • metrics whose column aliases cross each other's names, in the dataset and in a definition;
    • a compound metric linked through its parts;
    • a Workstation metric linked through its tokens;
    • a name another object shares, in the dataset or only in a definition;
    • a metric with no schema definition;
    • a metric that cannot be read still keeps its name from other metrics;
    • a metric that references itself;
    • a 403 that leaves metrics without column links.

Manual testing performed

  • MicroStrategy trial with BigQuery, main vs this PR (fresh services, local server): 26 → 28 column pairs.
    • The cube's Workstation metric now links order_items.quantity on the cube and on the report built on it.
    • 0 failures, the same warnings, and nothing else changed.
    • The trial uses generated aliases, so this run covers the definition path only.
  • Compound metric: a metric on the trial built as one metric divided by another resolves through the real API to both facts and their columns. Checked at client level, not inside a cube.
  • Alias path: checked offline against real cube SQL that uses name-derived aliases, plus the unit tests.
  • Column alias: set one on a trial metric; the API returns it as top-level columnNameAlias (absent when unset), and the client reads it from the definition it already fetches. The cube SQL using it is per the MicroStrategy docs, not re-run.

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 added tests around the new logic.
  • For connector/ingestion changes: I updated the documentation.
  • Decision check: v8 amendment to the MicroStrategy ADR.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 4/5

The PR still needs the existing fix for unreadable metrics allowing wrong column links before merging.

Findings

  1. P1 Failed reads allow wrong links ▶

Summary

Adds column-level lineage for schema-cube metrics in MicroStrategy.

  • Schema cube metrics now link to the warehouse columns they use.
  • Attribute forms now link every column in nested expressions.

Khairajani documents the accepted limits: name matching without Architect access can be wrong, and alias claims cannot cover metrics outside the dataset that its definitions never reach.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Schema metric] --> B[Read metric definition]
  B --> C{SQL alias has one owner?}
  C -->|Yes| D[Use columns read by that alias]
  C -->|No| E[Follow referenced metrics and facts]
  E --> F[Match fact columns against cube SQL]
  D --> G[Add column lineage]
  F --> G
Loading

Reviews (9) · Last reviewed commit: "MicroStrategy: match a metric's SQL proj..." · Reviewed by Greptile

A metric is linked to the columns of the SQL projection named after it, else
through the metrics and facts its definition is built from.
@Khairajani
Khairajani requested a review from a team as a code owner November 20, 2026 20:03
@Khairajani Khairajani added the safe to test Add this label to run secure Github workflows on PRs label Nov 20, 2026
@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.

…and load on Python 3.11

A metric the definition references now matches an alias only when no other object of the dataset shares its name, as the metric's own name already did. The ParsedCube alias default moves to a factory, since Python 3.11 refuses an unhashable dataclass default.
…ct owns that name

A metric a definition references, but the dataset does not hold, could take the alias of a dataset object whose name normalizes the same. Aliases are now matched by object id: an alias is a metric's only when no other object of the dataset has that name.
A metric can set a column alias that the SQL generator names its projection after in place of its name, so a display name can match another metric's projection. Each metric's alias now comes from its definition, every dataset object claims the name it is projected under before any metric is matched, and referenced metrics are matched on their own alias. Without modeling privileges the name stands in for the alias.
A metric whose definition fails to read dropped out of the alias claims, so another metric sharing its name could take its projection. It now claims its name, blocking that match without getting a column edge itself.
Comment on lines +612 to +621
def _metric_sql_name(self, project_id: str, metric: MstrAvailableObject) -> str | None:
"""
The name the SQL gives a schema metric's projection, from its definition. Without modeling
privileges no column alias can be read, so the metric's name stands in for it; a metric that
cannot be read otherwise, such as one derived in a dossier, is projected under no name.
"""
sql_name = self.client.get_metric_sql_name(project_id, metric.id, metric.name or "")
if sql_name is None and self.client.modeling_denied:
return metric.name
return sql_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 we leave metric column lineage unresolved when a 403 prevents establishing alias ownership?

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.

Agreed, done. Without Architect read, metrics now get no column lineage instead of a guess by name.

@github-actions

Copy link
Copy Markdown
Contributor

UI browser tests

Ran: all test files (no impact map from main yet)

Result: ✅ 1070 passed · 154 skipped

… be read

Without modeling privileges a metric's column alias is unknown, so matching its name could take a projection another metric's alias names. Metrics now get no column edge then; they still claim their names, so no other metric takes those projections.
@gitar-bot

gitar-bot Bot commented Nov 24, 2026

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

Adds MicroStrategy metric and fact resolution to column lineage, so incorrect alias or definition matching could misstate warehouse dependencies in the catalog.

Adds column-level lineage for schema-based MicroStrategy cube metrics, linking them to the warehouse columns their SQL projection or definition reads. Referenced-metric alias lookup now respects the ambiguity guard, so a shared alias no longer produces a wrong link. No open issues remain.

✅ 1 closed
✅ Edge Case: Referenced-metric alias lookup skips the ambiguity guard

📄 ingestion/src/metadata/ingestion/source/dashboard/microstrategy/metadata.py:572-582
_metric_columns checks key not in ambiguous before it matches the metric's own name to an alias, but the two later lookups by referenced-metric name don't: the known= predicate passed to get_metric_parts and the parts.metrics loop both use only normalized(name) in alias_reads. Example: a dataset holds Margin and % Margin, both normalized to margin, and the SQL has a MARGIN projection. A metric built from % Margin then takes the MARGIN projection's columns, which may belong to Margin. It also stops following % Margin's definition, so the edge can be wrong while the true columns are lost. This breaks the ADR v8 rule that "a name that another object of the dataset shares matches no alias". Fix: run the same check (part not in ambiguous) in both places.

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 c911302 into main Nov 24, 2026
63 of 66 checks passed
@Khairajani
Khairajani deleted the mstr-metric-column-lineage branch November 24, 2026 09:03
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 for metrics of schema-based cubes

2 participants