Skip to content

feat(lightdash): emit raw measures and synthesise a row count - #18

Merged
andrebaaij merged 1 commit into
mainfrom
feat/lightdash-raw-measures
Aug 12, 2026
Merged

andrebaaij merged 1 commit into
mainfrom
feat/lightdash-raw-measures

Conversation

@andrebaaij

Copy link
Copy Markdown
Contributor

Two gaps that between them left 34 of 38 explores with no metric at all.

Raw measures

The emitter read only t.Metrics, so any ir.Measure no metric wrapped was dropped silently, along with its backing column (a column only appears if something references it).

On the benchmark source that meant 22 measures became 9 metrics. clicks and impressions vanished from obt_marketing_daily entirely, making "how many ad clicks" unanswerable through a semantic layer whose dbt model declares the column and whose warehouse table has it.

databricks_metric_view.go already had this pass. Not having it here meant one IR produced a materially thinner layer for one target than another, which is the opposite of what an IR is for. Dedup follows that precedent exactly: raw-vs-metric by name or rendered aggregate, raw-vs-raw by name only.

A measure whose expr is not a plain column degrades to a note. Without that guard, case when is_refunded then 1 else 0 end was emitted as a column name.

Row count

A table left with no metric gets <table>_count over its primary key.

Lightdash does not require this. Ad-hoc custom metrics work fine against a dimension-only explore, verified through Lightdash's own MCP path where a custom count on dim_product returns 103. So this is a workaround for an upstream bug, and the code says so.

Given nothing selectable, Lightdash's AI agent invents a metric id. MetricQueryBuilder joins the select list with no empty guard, so the unresolvable field is dropped and the rest compiles to:

SELECT

FROM `lightdash`.`fct_order_lines` AS "fct_order_lines"

ClickHouse rejects that (Code 62). Postgres accepts SELECT FROM t, which is why it went unnoticed upstream. It accounted for 9 of 18 failures in a 50-question benchmark run. A real countable metric removes the incentive to invent one.

Result

before after
explores with any metric 4/38 38/38
metrics total 9 56

Three tests added, golden regenerated. Suite green, vet and gofmt clean.

Two gaps that between them left 34 of 38 explores with no metric at all.

RAW MEASURES. The emitter read only t.Metrics, so any ir.Measure no metric
wrapped was dropped silently — along with its backing column, since a column
only appears if something references it. On the benchmark source that meant 22
measures became 9 metrics: clicks and impressions vanished from
obt_marketing_daily entirely, making "how many ad clicks" unanswerable through
a semantic layer whose dbt model declares the column and whose warehouse table
has it.

databricks_metric_view.go already had this pass. Not having it here meant one
IR produced a materially thinner layer for one target than another, which is
the opposite of what an IR is for. Dedup follows that precedent exactly:
raw-vs-metric by name OR rendered aggregate, raw-vs-raw by name only.

A measure whose expr is not a plain column degrades to a note. Without that
guard "case when is_refunded then 1 else 0 end" was emitted as a COLUMN NAME,
and Lightdash would look for a column called that.

ROW COUNT. A table left with no metric now gets <table>_count over its primary
key. Lightdash does not require this — ad-hoc custom metrics work fine against
a dimension-only explore, verified through Lightdash's own MCP path, where a
custom count on dim_product returns 103.

It is a workaround for an upstream bug, and worth being explicit that it is:
given nothing selectable, Lightdash's AI agent invents a metric id, and
MetricQueryBuilder joins the select list with no empty guard, so the
unresolvable field is dropped and the rest compiles to

    SELECT

    FROM `lightdash`.`fct_order_lines` AS "fct_order_lines"

which ClickHouse rejects (Code 62). Postgres accepts `SELECT FROM t`, which is
why it went unnoticed upstream. That accounted for 9 of 18 failures in a
50-question benchmark run. A real countable metric removes the incentive.

Result on the benchmark source: 38/38 explores now carry metrics (was 4/38),
56 metrics total (was 9).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XdPy5mkvNRuGZ59rShLUag
@andrebaaij
andrebaaij merged commit 64b1044 into main Aug 12, 2026
1 check passed
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