Skip to content

Add persistent measure views to the DuckDB extension - #507

Merged
nicosuave merged 3 commits into
measure-compilerfrom
duckdb-measure-views
Nov 29, 2026
Merged

nicosuave merged 3 commits into
measure-compilerfrom
duckdb-measure-views

Conversation

@nicosuave

@nicosuave nicosuave commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Allow an analyst to declare measures over a table or query with CREATE VIEW … AS SELECT … AS MEASURE … after loading SQLCtx. DuckDB stores the view and SQLCtx recomputes its measures at the query’s grain. For West sales of 10 and 30 and an East sale of 80, a filtered AGGREGATE(aov) returns 20 and the overall average is 40.

This layer connects the compiler to DuckDB’s parser, catalog and binder. It covers typed column discovery, persistent and attached views, replacement and rollback, and errors when a reader accesses a virtual measure without loading SQLCtx.

@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:20.616701Z d87f352 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: d87f352281

ℹ️ 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 thread sqlctx-duckdb/src/sqlctx_parser.cpp Outdated
Comment on lines +935 to +936
for (const auto &column : bound.names) {
fields.push_back(make_uniq<ColumnRefExpression>(SqlctxIdentifier(SqlctxName(column))));

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 Preserve expressions and qualifiers when expanding wildcards

When a measure declaration uses a modified or qualified wildcard, rebuilding its fields solely from bound.names discards the expressions and source qualifiers that DuckDB bound. For example, CREATE VIEW sales AS SELECT * REPLACE (amount * 2 AS amount), sum(amount) AS MEASURE revenue FROM raw_sales silently exposes the original amount rather than the doubled value; * RENAME (region AS bucket) instead attempts to bind a nonexistent source column named bucket. Qualified stars over joins can likewise become ambiguous. Preserve the expanded projection expressions and their aliases instead of constructing unqualified column references from output names.

Useful? React with 👍 / 👎.

@nicosuave
nicosuave force-pushed the duckdb-measure-views branch from d87f352 to 328886c Compare November 29, 2026 15:51
@nicosuave
nicosuave merged commit 7bacd63 into main Nov 29, 2026
30 of 57 checks passed
@nicosuave
nicosuave deleted the duckdb-measure-views 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