Skip to content

feat(data-analytics-demo): T-10 MetricFlow semantic layer#90

Merged
leagames0221-sys merged 1 commit into
mainfrom
feat/data-analytics-demo-t10-semantic
May 17, 2026
Merged

feat(data-analytics-demo): T-10 MetricFlow semantic layer#90
leagames0221-sys merged 1 commit into
mainfrom
feat/data-analytics-demo-t10-semantic

Conversation

@leagames0221-sys

Copy link
Copy Markdown
Owner

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

Path Role
semantic/kpi.yml 3 semantic models (customers, subscriptions, invoices) + 4 metrics (customers, active_subscriptions, monthly_recurring_revenue, paid_invoice_volume)
src/data_analytics_demo/semantic/validator.py Pure-Python validator — parses the YAML, enforces required keys, non-empty dims/measures, cross-references
tests/test_semantic.py 5 cases — AC-6.1 / AC-6.2 / missing-file / empty-dims / unknown-measure + canonical inventory
Makefile semantic-validate + cli.py semantic Both wired up
pyproject.toml Adds types-PyYAML to dev deps so mypy --strict sees yaml stubs

AC coverage

AC Behaviour Verified by
6.1 make semantic-validate exits 0 on a valid file test_ac_6_1_valid_file_returns_report + live make-target run
6.2 Each metric has ≥ 1 dimension and ≥ 1 measure enforced in validator._validate_metric; test_ac_6_2_… plus the negative test_empty_metric_dimensions_raises test

Why an in-process validator instead of mf validate-configs

The 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.py keeps the test suite self-contained and gives us a clear, AC-traceable failure mode when the YAML drifts.

Local verify

  • make semantic-validateOK — 3 semantic models / 4 metrics: customers, active_subscriptions, monthly_recurring_revenue, paid_invoice_volume
  • ruff + mypy --strict clean (21 source files)
  • pytest 32 passed; coverage 87.20%
  • check-doc-drift.mjs 0 fail / check-adr-claims.mjs 77/77

Test plan

  • Required CI checks green (existing 11 + python-test + python-audit)
  • No HIVE-token leaks (D-HIVE-OPACITY)

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.
@vercel

vercel Bot commented May 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
craftstack-collab Ready Ready Preview, Comment May 17, 2026 3:53pm
craftstack-knowledge Ready Ready Preview, Comment May 17, 2026 3:53pm

@leagames0221-sys leagames0221-sys merged commit 04884e8 into main May 17, 2026
13 checks passed
@leagames0221-sys leagames0221-sys deleted the feat/data-analytics-demo-t10-semantic branch May 17, 2026 15:55
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant