Repository navigation
Add measure-preserving DuckDB views and speed up catalog discovery - #505
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84eeb497c6
ℹ️ 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".
| if selected.is_none() | ||
| && column["table"].is_null() | ||
| && output_aliases.contains(&field.to_ascii_lowercase()) |
There was a problem hiding this comment.
Preserve ORDER BY aliases that also name selected view fields
When an output alias also names a field exposed by the semantic view, this condition substitutes the view field instead of preserving the output alias. For example, after CREATE SEMANTIC VIEW sales AS SELECT country AS region, revenue AS gross FROM orders, SELECT gross AS region FROM sales ORDER BY region becomes an ordering by country. The downstream compiler then adds that dimension to the aggregation grain, returning country-level totals instead of the requested scalar total. Resolve unqualified ORDER BY output aliases before substituting view fields, including when the names collide.
Useful? React with 👍 / 👎.
| } else if outer.len() == 1 { | ||
| outer.values().next().and_then(Option::as_ref) | ||
| } else { | ||
| None |
There was a problem hiding this comment.
Resolve local view columns independently of inherited scopes
In a nested SELECT, outer includes both inherited relations and the current SELECT's sources because visit initializes its scope with outer.clone(). Consequently, an unrelated enclosing relation prevents unqualified columns from being expanded even when the inner SELECT has exactly one source. With sales exposing revenue AS gross, SELECT (SELECT gross FROM sales) AS total FROM main.raw_orders leaves the inner gross unchanged while replacing sales with its base model; compilation then fails because that model has no gross field. Track local sources separately and resolve them before considering enclosing scopes.
Useful? React with 👍 / 👎.
SQLCtx users can publish a selection of dimensions and measures with
CREATE SEMANTIC VIEW. Queries of that view choose their own grain, including when the measures are filtered or ratios of aggregates. Named views support aliases, nesting, replacement, dependency checks, transaction rollback and database reopen. DuckDB 2.0.1 handles the declaration in its native PEG grammar. DuckDB 1.5.6 uses the compatibility parser.The DuckDB extension also supports semantic queries through Python relations and the agent shell, resolves explicitly attached semantic models in their owning database, and returns SemanticInput results as a table.
sqlctx_explain(sql)reports the grain, join and fanout decisions made by the compiler.Catalog discovery now delays type binding until a query needs it and reuses a prepared compiler graph. On DuckDB 2.0.1 with 25 models and eight metrics per model, listing all semantic views went from 912 to 4 ms. Reading the nine columns and types of one model went from 860 to 19 ms. One semantic metric went from 4 to 5 ms. The benchmark verifies the returned rows and records all seven samples.
The community descriptor generator pins both supported DuckDB versions to a single source commit. Host coverage includes DuckFlight 0.2.1 and both parser load orders with Yardstick.