Skip to content

Support aggregate call decorations and window frames - #50

Merged
nicosuave merged 4 commits into
mainfrom
aggregate-call-semantics
Sep 14, 2026
Merged

nicosuave merged 4 commits into
mainfrom
aggregate-call-semantics

Conversation

@nicosuave

Copy link
Copy Markdown
Member

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.

@nicosuave
nicosuave marked this pull request as ready for review September 14, 2026 12:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T12:27:00.620946Z 80f18ef 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: 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".

Comment thread src/measure_windows.cpp
Comment on lines +1337 to +1340
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));

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 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 👍 / 👎.

Comment thread src/measure_windows.cpp
Comment on lines +1051 to +1054
case WindowContextType::SET:
if (!global && !removed.count(dimension_key(modifier.dimension))) {
sets[modifier.dimension] = modifier.value;
expand = true;

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 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 👍 / 👎.

@nicosuave
nicosuave merged commit 0b5fc82 into main Sep 14, 2026
39 of 40 checks 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