# Metric Views Linter CLI (certified-asset audit)

## PURPOSE
A Click + Pandas command-line tool that audits "metric views" and certified assets the way the Genie demo browses its Discover page. In the video, users apply filters for **certified** vs **popular** assets and inspect metric views, dashboards, tables and Genie agents grouped into **domains** (commercial, uptake, healthcare). This CLI takes a YAML/JSON export of a workspace's asset catalog and reports: uncertified assets sitting in certified domains, metric views that reference missing tables, stale Q3 metrics, and coverage gaps per domain.

## WHY THIS MATTERS
Genie's confidence comes from a curated semantic layer — "somebody has defined that this is a curated asset and should be leveraged more than assets somebody created for a one-off analysis." Governance is what makes an answer trustworthy. Before any NL-to-SQL layer can be trusted, someone must lint the metric definitions. This tool teaches that discipline.

## HOW TO BUILD
1. `pip install -r requirements.txt`.
2. Model the catalog as a single DataFrame: `asset_id, name, type, domain, certified, owner, last_updated, refers_to`.
3. Write three Click commands: `lint` (all checks), `coverage` (assets per domain), and `certify` (mark assets and re-emit JSON).
4. Use Pandas grouping/joins for each rule; print a colourless, pipe-friendly table so it works in CI.
5. Exit non-zero when lint fails so it drops into a pre-commit hook or Airflow task.

```python
@cli.command()
@click.option("--catalog", type=click.Path(exists=True), required=True)
@click.option("--fail-on", type=click.Choice(["error", "warn"]), default="error")
def lint(catalog: str, fail_on: str) -> None:
    df = load_catalog(catalog)
    issues = check_certification(df) + check_unresolved_joins(df)
    render(issues)
    if any(i.level == "ERROR" for i in issues):
        raise SystemExit(1)
```

## WHEN TO USE IN PRODUCTION
Run it in CI on every pull request that touches metric-view definitions, or nightly against the workspace export to catch certification drift before business users build dashboards on uncurated assets. Great for platform teams standardizing metrics across cross-functional teams. Not the tool for ad-hoc exploratory SQL, real-time lineage, or column-level PII scanning — use a dedicated catalog/lineage product for those.

## HOW IT HELPS STUDENTS
They learn Pandas group-by/merge for real governance logic, Click command design, and — crucially — that "certified" is a return value a machine can check, not a vibe. It's a gateway into data-contract and semantic-layer thinking, and CI exit codes make it feel like real platform work.

## STARTER CODE
`starter/main.py` ships a runnable Click CLI with a bundled sample catalog, all three commands, and `# TODO` markers for extra rules (staleness by date, owner coverage, domain filters).
