Support aggregate call decorations and window frames - #50
Conversation
Codex Review SummaryThis 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: 80f18ef833
ℹ️ 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".
| auto cte = make_uniq<CommonTableExpressionInfo>(); | ||
| cte->query_node = std::move(plan.base); | ||
| cte->materialized = CTEMaterialize::CTE_MATERIALIZE_ALWAYS; | ||
| output->cte_map.map.insert(Identifier(plan.base_name), std::move(cte)); |
There was a problem hiding this comment.
Generate collision-free window CTE names
Choose the generated plan.base_name after checking the query's existing CTE names. For a query such as WITH __ys_window_source_0_base AS (...) SELECT AGGREGATE(revenue) OVER () ..., this insert collides with the user CTE and does not install the lineage base CTE, while the rewritten source still references that name. The query then either binds against the user's unrelated CTE and returns incorrect results or fails because the generated ID/column fields are absent.
Useful? React with 👍 / 👎.
| case WindowContextType::SET: | ||
| if (!global && !removed.count(dimension_key(modifier.dimension))) { | ||
| sets[modifier.dimension] = modifier.value; | ||
| expand = true; |
There was a problem hiding this comment.
Normalize SET dimensions before storing overrides
Key sets by dimension_key(modifier.dimension) rather than the raw spelling. If a window call sets the same dimension using equivalent spellings, such as AT (SET yr = 2022) AT (SET v.yr = 2023), both raw keys survive; the later loop emits two predicates against the same base dimension and ANDs them, producing an empty context instead of allowing one SET to override the other according to modifier order.
Useful? React with 👍 / 👎.
The native frontend previously rejected DISTINCT, FILTER, argument ORDER BY, OVER, and EXPORT_STATE on AGGREGATE calls. These now recompute base and derived measures with their decorations intact.
Window frames track original base-row identities, preserve grouped-measure statistics, and avoid multiplying measures after consumer joins. Joined filters and ordering retain their input scope and declaration tie-breaks. Derived exported states retain their aggregate statistics and scalar formula for finalization and combination.
DuckDB 1.5.5 keeps its compatibility frontend. Native export restrictions and cross-shard DISTINCT state-combination behavior are documented. Includes SQL regression coverage for both native parser modes, frames, aliases, nested queries, empty inputs, joins, and persistent states.