Skip to content

Comments

Support AT semantics for window measures#23

Merged
nicosuave merged 2 commits intomainfrom
window-at-semantics
Feb 23, 2026
Merged

Support AT semantics for window measures#23
nicosuave merged 2 commits intomainfrom
window-at-semantics

Conversation

@nicosuave
Copy link
Member

Summary

  • add AGGREGATE(window_measure) AT (...) support using context-first recomputation
  • enforce single-valued semantics for window measures under AT and throw a clear error when multiple distinct values exist
  • keep plain AGGREGATE(window_measure) behavior unchanged
  • fix top-level GROUP BY insertion so window OVER (ORDER BY ...) clauses are not misdetected as outer ORDER BY
  • add/adjust SQL tests for successful and failing AT window-measure cases
  • update README and LIMITATIONS docs for the new behavior

Validation

  • make release
  • ./build/release/test/unittest test/sql/measures.test

Copy link

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

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: 9684977769

ℹ️ 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".

/// Returns true if expression appears to use a SQL window clause.
fn is_window_expression(expr: &str) -> bool {
let expr_upper = expr.to_uppercase();
expr_upper.contains(" OVER(") || expr_upper.contains(" OVER (")

Choose a reason for hiding this comment

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

P2 Badge Recognize all valid window clause spellings

is_window_expression only checks for the literal substrings " OVER(" and " OVER (", so valid window syntax such as line breaks/tabs before OVER or named windows like OVER w is not detected. In those cases extract_measures_from_sql will classify the measure as decomposable and replace it with NULL AS <measure>, which silently breaks both direct measure queries and the new AT (...) window handling for otherwise valid SQL formatting.

Useful? React with 👍 / 👎.

.derived_expr
.clone()
.unwrap_or_else(|| resolved.expression.clone());
let is_window_measure = is_window_expression(&resolved.expression);

Choose a reason for hiding this comment

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

P2 Badge Detect window semantics from expanded derived expression

This branch decides whether to apply window-specific single-value enforcement using resolved.expression, but execution uses expression_for_eval (which can be an expanded derived expression). For derived measures that expand into a window expression, the code takes the non-window path and emits a scalar subquery without the distinct-value guard, which can fail at runtime (multi-row scalar subquery) or return incorrect AT results instead of the intended window ambiguity error.

Useful? React with 👍 / 👎.

@nicosuave nicosuave merged commit c695800 into main Feb 23, 2026
8 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