Skip to content

Compile measure views and validate measure expressions - #506

Merged
nicosuave merged 2 commits into
semantic-catalog-viewsfrom
measure-compiler
Nov 29, 2026
Merged

nicosuave merged 2 commits into
semantic-catalog-viewsfrom
measure-compiler

Conversation

@nicosuave

@nicosuave nicosuave commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Teach the Rust compiler to evaluate declared measures at the caller’s grain. The compiler tracks measure lineage through query scopes, resolves derived references in their owning model, and distinguishes a filtered aggregate from a bare measure. It rejects unsafe reaggregation and reports invalid dependencies in explicitly derived metric declarations.

The catalog and C API expose the measure definitions, compiler diagnostics and explanation data used by the DuckDB extension in the next layer.

@nicosuave
nicosuave added this pull request to stack #510 November 28, 2026 23:40
@nicosuave
nicosuave marked this pull request as ready for review November 29, 2026 15:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T15:08:17.961711Z 84df7ed Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84df7eda9a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1869 to +1870
aggregate = format!(
"__sqlctx_decorated_measure({})",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Implement the native helpers before emitting calls to them

Queries such as SELECT AGGREGATE(revenue) FILTER (WHERE region = 'west') FROM sales now emit __sqlctx_decorated_measure(...), but the DuckDB extension does not register that function, so the returned SQL fails at database binding rather than executing the measure. Repository-wide search, including hidden files and generated/build-file paths, found only the emitted call, not an implementation or registration. The new window and joined-visibility paths similarly emit undefined __sqlctx_measure_windows and __sqlctx_visible_join helpers. Include the host implementations and registrations with these compiler changes, or lower these operations into executable SQL.

Useful? React with 👍 / 👎.

Comment on lines +1073 to +1076
if raw_measure_source && !self.rewriter.security_controls {
if let Some(from) = &mut select.from {
for source in &mut from.expressions {
self.source(source)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expand declared dimensions on the row-preserving path

For a measure view without visible_source_sql, whose dimension is declared as {"name":"region","sql":"UPPER(region_code)"} over SELECT region_code, amount FROM raw_orders, SELECT region FROM sales takes this path and replaces only the source relation. It returns before the dimension-expansion pass, producing a reference to region against a subquery that exposes only region_code and amount; execution therefore fails with an unknown column. If the source happens to expose a same-named column, it silently returns that column instead of the declared expression. Apply dimension expansion to projections and predicates before returning while preserving the intended ungrouped row semantics.

Useful? React with 👍 / 👎.

@nicosuave
nicosuave merged commit 7bacd63 into main Nov 29, 2026
30 checks passed
@nicosuave
nicosuave deleted the measure-compiler branch November 29, 2026 16:27
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