Skip to content

feat(ir): RETURN * projects all in-scope variables (#598)#897

Merged
DecisionNerd merged 1 commit into
mainfrom
feature/598-return-star
Jun 23, 2026
Merged

feat(ir): RETURN * projects all in-scope variables (#598)#897
DecisionNerd merged 1 commit into
mainfrom
feature/598-return-star

Conversation

@DecisionNerd

@DecisionNerd DecisionNerd commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Advances #598 (read-path). The last engine piece for the With1 cluster.

Summary

MATCH (a)-->(b) RETURN * now returns one column per in-scope named variable instead of erroring (variable * used before it was introduced). * parses as a Var named "*"; the binder now expands it to the current named vars from scope (sorted → deterministic plan), each lowered as the normal per-var projection — so node vars materialize as whole node values (#785).

Combined with WITH whole-node forwarding (#814 slice 2) + MATCH-after-WITH, the With1 shape MATCH (a) WITH a MATCH (a)-->(b) RETURN * now works end-to-end.

Scope

  • Anonymous pattern elements (no user name) aren't in scope → not returned.
  • Named relationship/path vars would expand here but still fail downstream (rel/path values unsupported) — not silently dropped.

Validation

  • New e2e: return_star_projects_all_in_scope_vars (columns a+b, node values), return_star_after_with_forwarded_node (the With1 MATCH-after-WITH shape) — 87 pass.
  • IR/rel goldens unchanged; cargo clippy --workspace -- -D warnings + fmt clean.

With this on main, #889 slice 2 (render + un-skip) finally has a runnable node-returning corpus cluster to land against.

🤖 Generated with Claude Code

Note

Expand RETURN * to project all in-scope named variables in the IR binder

  • Adds expand_return_wildcard in binder.rs to detect a Var named "*" in return items and replace it with one item per in-scope named variable from BinderState.vars, sorted for deterministic ordering.
  • Binder.lower_return now calls this expansion before aggregate detection and lowering, so wildcard projections resolve correctly instead of propagating a raw "*" variable.
  • Anonymous elements are excluded from expansion; named relationship and path variables are included but subject to downstream support limitations.
  • Adds two e2e tests covering basic RETURN * after MATCH and RETURN * after WITH node forwarding.

Macroscope summarized 39a7a3c.

Summary by CodeRabbit

  • Tests

    • Added end-to-end baseline tests for RETURN * behavior, validating proper projection of all in-scope variables as individual columns and correct handling in WITH clause scenarios with variable re-matching.
  • Bug Fixes

    • Fixed RETURN * wildcard expansion to systematically include all named variables currently in scope in query results, sorted alphabetically.

`MATCH (a)-->(b) RETURN *` now returns one column per in-scope named
variable instead of erroring ("variable `*` used before it was
introduced"). The binder expands the `*` return item (it parses as a
`Var` named "*") to the current named vars from scope, sorted for a
deterministic plan; each expands to the normal per-var projection, so
node vars materialize as whole node values (#785).

Combined with WITH whole-node forwarding (#814 slice 2) and
MATCH-after-WITH, the With1 shape `MATCH (a) WITH a MATCH (a)-->(b)
RETURN *` now works end-to-end.

Anonymous pattern elements (no user name) aren't in scope and so aren't
returned; named relationship/path vars would expand but still fail
downstream (rel/path values unsupported) rather than being silently
dropped.

Validated: new e2e `return_star_projects_all_in_scope_vars`,
`return_star_after_with_forwarded_node` (87 pass); IR/rel goldens
unchanged; clippy --workspace -D warnings + fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Implements RETURN * wildcard support in the binder: a new expand_return_wildcard helper replaces wildcard ReturnItems with one item per in-scope variable from BinderState.vars, sorted by name. lower_return calls this helper before aggregate detection and Project lowering. Two e2e baseline tests validate the behavior for plain MATCH and WITH + re-MATCH pipelines.

Changes

RETURN * Wildcard Expansion

Layer / File(s) Summary
Wildcard expansion in lower_return
crates/gf-ir/src/binder.rs
expand_return_wildcard replaces RETURN * AST items with one ReturnItem per in-scope variable from BinderState.vars, emitted in sorted order. lower_return calls this helper first, then runs aggregate detection and Project lowering on the expanded list.
E2E baseline tests for RETURN *
crates/gf-api/tests/e2e_baseline.rs
Two new tests: one verifies RETURN * after MATCH binding a and b produces all in-scope variable columns; the second verifies RETURN * after a WITH + re-MATCH pipeline produces both the forwarded and re-matched variable columns with correct row counts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • DecisionNerd/graphforge#890: Modifies Binder::lower_return in the same file to handle whole-node materialization via _node_struct, directly adjacent to the return-lowering code path extended here.
  • DecisionNerd/graphforge#894: Reworks WITH clause scoping in binder.rs, which determines the in-scope variables that expand_return_wildcard reads from BinderState.vars after a WITH + re-MATCH pipeline.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: RETURN * now projects all in-scope variables instead of erroring.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is comprehensive, well-structured, and includes all key information: a clear summary of the change, the problem being solved, scope limitations, validation details, and context about blocking/unblocking other work.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/598-return-star

Comment @coderabbitai help to get the list of available commands.

@DecisionNerd DecisionNerd merged commit 56b745c into main Jun 23, 2026
41 checks passed
@DecisionNerd DecisionNerd deleted the feature/598-return-star branch June 23, 2026 22:14
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