Metacenta

BI semantic layer · rule semantic-column-not-built

dbt semantic models reading unbuilt columns

A Metacenta review checks this under the rule Semantic models read columns their model builds. Everything below applies whether or not you ever commission one.

What this rule checks

For each dbt semantic model, this rule compares its entities, dimensions and measures with the columns its model builds. An element reads its expr, or its own name when there is no expr. Any element naming a column the model does not build is flagged.

Why it matters

dbt parses and builds this without complaint. It fails when somebody queries a metric that uses the element, usually from a dashboard, on the day the number is needed.

How to fix it

Point every semantic model at columns its model builds. Point each flagged element's expr at a column its model builds, or add the column to that model. Rebuild, then query one metric that uses it.

Before:

semantic_models:
  - name: orders
    model: ref('fct_orders')
    measures:
      - name: order_total
        agg: sum
        expr: amount_gbp

After:

semantic_models:
  - name: orders
    model: ref('fct_orders')
    measures:
      - name: order_total
        agg: sum
        expr: order_amount

When it is fine to leave

Rarely. The element fails on its first query, so it is broken rather than risky. A semantic model written ahead of its column should land in the same change as that column.

What we need to check it

manifest.json, plus catalog.json from dbt docs generate or an enforced contract on the model. Columns listed in YAML without a contract do not count, so that semantic model is left unexamined. An expr holding SQL rather than a bare column is not judged. A catalog older than the manifest is not used.