feat(ir): WITH forwards a whole node (#814 slice 2)#896
Merged
Conversation
`MATCH (n) WITH n …` now carries a node through the WITH scope reset instead of erroring (the prior #814 deferral). A node variable spans multiple columns (var_<n>.node_uuid + properties), so: - Lowerer (lower_with_op): a WITH item that is a bare VarRef to a node var (one with a NodeScan shape) forwards ALL input columns under that var's qualifier unchanged, rather than projecting a single column. The scope reset then maps the var to its column prefix. - Binder (lower_with): a no-rename node item (`WITH n` / `WITH n AS n`) reuses the node's var (no fresh mint) and re-registers it in node_vars after the reset, so a later `RETURN n` materializes a whole node value (#785) and `n.x` resolves. Still deferred (clear errors): renaming a node (`WITH n AS m`, needs column re-qualification) and forwarding a relationship/path. Validated: new e2e `with_forwards_whole_node_then_property` and `with_forwards_whole_node_then_node_value` (84 pass); IR/rel goldens unchanged (with_pipeline uses scalar WITH); clippy --workspace -D warnings + fmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
WalkthroughThe PR implements whole-node variable forwarding through ChangesWITH Whole-Node Forwarding
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 |
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.
Part of #814 (slice 2 — whole-node forwarding through WITH; does not close it).
Summary
MATCH (n) WITH n …now carries a node through theWITHscope reset instead of erroring (the slice-1 deferral). This was the most-cited deferral and a prerequisite forWITH-then-RETURN n.How
A node variable spans multiple columns (
var_<n>.node_uuid+ each property), so a single aliased projection can't represent it:lower_with_op): a WITH item that is a bareVarRefto a node var (one with aNodeScanshape) now forwards all input columns under that var's qualifier, unchanged — instead ofcol(expr).alias(name). The scope reset maps the var to its column prefix.lower_with): a no-rename node item (WITH n/WITH n AS n) reuses the node's var (no fresh mint) and re-registers it innode_varsafter the reset, so a laterRETURN nmaterializes a whole node value (rust: node-value materialization — return a whole node value (identity+labels+props) from an expression #785) andn.xresolves.Deferred (clear errors, not silently wrong)
WITH n AS m) — needs column re-qualification.Validation
with_forwards_whole_node_then_property(WITH n WHERE n.age>28 RETURN n.name→ Alice+Carol),with_forwards_whole_node_then_node_value(WITH n RETURN n→ node Struct) — 84 pass.with_pipelineuses scalar WITH);cargo clippy --workspace -- -D warnings+ fmt clean.🤖 Generated with Claude Code
Note
Support forwarding a whole node through WITH in graph IR
crates/gf-ir/src/binder.rsnow allowsWITH n(bare node variable, no rename) to pass through the scope reset, reusing the existingVarIdand re-registering it as a node var so downstreamRETURN nandn.xresolve correctly.crates/gf-rel/src/lowerer.rsdetects node-shapedVarRefitems and projects all columns under the variable's qualifier prefix instead of a single scalar column.WITH n AS mand forwarding a relationship or path throughWITHremain rejected with explicit errors.crates/gf-api/tests/e2e_baseline.rsare updated to assert correct row results and node-value struct access afterWITH n.Macroscope summarized b2f4e33.
Summary by CodeRabbit
WITHclause now supports forwarding whole node variables through queries, enabling full node variables to retain all their properties and structure through subsequent query operations. This allows queries likeWITH n WHERE n.age > 28 RETURN n.nameandWITH n RETURN nto succeed as expected.