feat(data-analytics-demo): T-10 MetricFlow semantic layer#90
Merged
Conversation
Phase 6 of the data-analytics-demo bolt-on. Ships the single source of truth for KPI definitions and a validator that enforces the MetricFlow schema invariants the rest of the package depends on. What lands: - semantic/kpi.yml — 3 semantic models (customers, subscriptions, invoices) and 4 metrics (customers, active_subscriptions, monthly_recurring_revenue, paid_invoice_volume). Each metric carries ≥ 1 dimension and ≥ 1 measure per AC-6.2. - src/data_analytics_demo/semantic/validator.py — pure-Python validator. Parses the YAML, walks semantic_models[] / metrics[], and enforces: required keys, non-empty dims + measures, metric.measure references a declared measure, metric.dimensions all reference declared dimensions. - tests/test_semantic.py — 5 cases covering AC-6.1 + AC-6.2 + negative paths (missing file, empty dim list, unknown measure ref) + canonical metric inventory. - Makefile semantic-validate target + cli.py semantic subcommand wired up. - types-PyYAML added to dev deps so mypy --strict sees the yaml stubs. Local verify: - `make semantic-validate` → "OK — 3 semantic models / 4 metrics: …" - ruff OK / mypy OK (21 source files) / pytest 32 PASS / coverage 87.20% - check-doc-drift / check-adr-claims unchanged (0 fail / 77/77) Design note: the validator is independent of the MetricFlow CLI by design — it enforces the structural invariants the package relies on without shelling out to `mf validate-configs`, so the test suite has no CLI dependency and runs cleanly under pytest.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
2 tasks
leagames0221-sys
added a commit
that referenced
this pull request
May 21, 2026
Phase 6 of the data-analytics-demo bolt-on. Ships the single source of truth for KPI definitions and a validator that enforces the MetricFlow schema invariants the rest of the package depends on. What lands: - semantic/kpi.yml — 3 semantic models (customers, subscriptions, invoices) and 4 metrics (customers, active_subscriptions, monthly_recurring_revenue, paid_invoice_volume). Each metric carries ≥ 1 dimension and ≥ 1 measure per AC-6.2. - src/data_analytics_demo/semantic/validator.py — pure-Python validator. Parses the YAML, walks semantic_models[] / metrics[], and enforces: required keys, non-empty dims + measures, metric.measure references a declared measure, metric.dimensions all reference declared dimensions. - tests/test_semantic.py — 5 cases covering AC-6.1 + AC-6.2 + negative paths (missing file, empty dim list, unknown measure ref) + canonical metric inventory. - Makefile semantic-validate target + cli.py semantic subcommand wired up. - types-PyYAML added to dev deps so mypy --strict sees the yaml stubs. Local verify: - `make semantic-validate` → "OK — 3 semantic models / 4 metrics: …" - ruff OK / mypy OK (21 source files) / pytest 32 PASS / coverage 87.20% - check-doc-drift / check-adr-claims unchanged (0 fail / 77/77) Design note: the validator is independent of the MetricFlow CLI by design — it enforces the structural invariants the package relies on without shelling out to `mf validate-configs`, so the test suite has no CLI dependency and runs cleanly under pytest. Co-authored-by: leagames0221-sys <leagames0221@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 6 of the data-analytics-demo bolt-on. Ships the single source of truth for KPI definitions (MetricFlow-compatible YAML) and a pure-Python validator that enforces the schema invariants the rest of the package depends on.
What lands
semantic/kpi.ymlsrc/data_analytics_demo/semantic/validator.pytests/test_semantic.pysemantic-validate+cli.py semanticpyproject.tomltypes-PyYAMLto dev deps so mypy--strictsees yaml stubsAC coverage
make semantic-validateexits 0 on a valid filetest_ac_6_1_valid_file_returns_report+ live make-target runvalidator._validate_metric;test_ac_6_2_…plus the negativetest_empty_metric_dimensions_raisestestWhy an in-process validator instead of
mf validate-configsThe MetricFlow CLI is a heavy entry point and ties the test suite to a shell environment + dbt project context. The structural invariants this package relies on (existence of metrics + their measure/dimension cross-refs) are a small subset of MetricFlow's full validation surface. Putting that subset in
validator.pykeeps the test suite self-contained and gives us a clear, AC-traceable failure mode when the YAML drifts.Local verify
make semantic-validate→OK — 3 semantic models / 4 metrics: customers, active_subscriptions, monthly_recurring_revenue, paid_invoice_volumeruff+mypy --strictclean (21 source files)pytest32 passed; coverage 87.20%check-doc-drift.mjs0 fail /check-adr-claims.mjs77/77Test plan