feat(ir): name un-aliased aggregate columns by source text (#598/#599) — corpus 555→570#909
Merged
Merged
Conversation
An aggregate RETURN item with no `AS` (`RETURN count(*)`, `min(x)`, `sum(i)`) was named `agg_<idx>`, so it failed the TCK's header-exact result comparison. It now takes the verbatim expression text (`ReturnItem::display`, the same source the non-aggregate columns use since #906), falling back to `agg_<idx>` only when neither an explicit alias nor display text is present. Corpus passing 555 → 570 (+15, 0 regressions); baseline re-blessed. Naming the group-by keys of a *mixed* aggregate query (`RETURN n.name, sum(n.num)`) is a follow-up — it needs per-key output aliases on the `Aggregate` op. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
WalkthroughIn ChangesAggregate alias fallback and TCK coverage update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
DecisionNerd
added a commit
that referenced
this pull request
Jun 24, 2026
Completes source-text naming for the aggregate path (un-aliased aggregates landed in #909) and fixes whole-node group keys. In a mixed aggregate query like `RETURN n.name, count(*)`, the `n.name` group-by column was named by its lowered expression (`var_0.name`), failing the TCK header-exact comparison. The `Aggregate` IR op now carries an optional per-key output alias — `group_aliases`, parallel to `group_by` and `#[serde(skip_serializing_if = "Vec::is_empty")]` so existing plans/goldens are unchanged — filled by the binder from each RETURN item's `AS` alias or verbatim source text and applied by `lower_aggregate` via `.alias()`. Group keys are also now materialized through the same path as terminal RETURN items: a whole-node group key (`RETURN n, count(*)`) rewrites to `_node_struct` rather than a bare `var_N` (which is not a real column and lowered against an unbound reference). (Thanks CodeRabbit.) Corpus passing 570 → 575 (+5, 0 regressions); baseline re-blessed. No golden churn (the IR aggregation golden has an empty group-by). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DecisionNerd
added a commit
that referenced
this pull request
Jun 24, 2026
Completes source-text naming for the aggregate path (un-aliased aggregates landed in #909) and fixes whole-node group keys. In a mixed aggregate query like `RETURN n.name, count(*)`, the `n.name` group-by column was named by its lowered expression (`var_0.name`), failing the TCK header-exact comparison. The `Aggregate` IR op now carries an optional per-key output alias — `group_aliases`, parallel to `group_by` and `#[serde(skip_serializing_if = "Vec::is_empty")]` so existing plans/goldens are unchanged — filled by the binder from each RETURN item's `AS` alias or verbatim source text and applied by `lower_aggregate` via `.alias()`. Group keys are also now materialized through the same path as terminal RETURN items: a whole-node group key (`RETURN n, count(*)`) rewrites to `_node_struct` rather than a bare `var_N` (which is not a real column and lowered against an unbound reference). (Thanks CodeRabbit.) Corpus passing 570 → 575 (+5, 0 regressions); baseline re-blessed. No golden churn (the IR aggregation golden has an empty group-by). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An aggregate
RETURNitem with noAS—RETURN count(*),min(x),sum(i)— was namedagg_<idx>, so it failed the TCK's header-exact result comparison (column_by_name("count(*)")).lower_return_aggregatenow uses the item's verbatim expression text (ReturnItem::display, the same source #906 introduced for non-aggregate columns), falling back toagg_<idx>only when neither an explicit alias nor display text exists.This is the dominant Aggregation-corpus pattern (single top-level aggregate, no
AS), which the binder already lowered correctly — only the output column name was wrong.Impact
Corpus passing 555 → 570 (+15, 0 regressions); baseline re-blessed. No golden churn (the IR aggregation golden uses an aliased aggregate).
Follow-up
Naming the group-by keys of a mixed aggregate query (
RETURN n.name, sum(n.num)→ then.namecolumn is still named by its lowered expr, notn.name) needs per-key output aliases on theAggregateIR op — a separate PR. Nested aggregates (count(*) + 1) need the Aggregate→Project decomposition, also separate.Verification
Refs #598/#599 (does not close).
🤖 Generated with Claude Code
Note
Name un-aliased aggregate RETURN columns by their source expression text
binder.rs, aggregate RETURN items without an explicit alias now use the item's verbatim display text (e.g.,count(*),min(x)) as the column name, matching openCypher naming behavior, with fallback toagg_<n>only when no display text exists.Macroscope summarized 2ed78ac.
Summary by CodeRabbit
Bug Fixes
Tests