Skip to content

feat(cypher): support WITH collect/UNWIND/MATCH reentry (#1000) - #1020

Merged
lmeyerov merged 2 commits into
masterfrom
feat/1000-with-unwind-match
Apr 2, 2026
Merged

lmeyerov merged 2 commits into
masterfrom
feat/1000-with-unwind-match

Conversation

@lmeyerov

@lmeyerov lmeyerov commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Support WITH scalar, collect(alias) AS list UNWIND list AS alias MATCH ... RETURN Cypher queries where carried scalars accompany the collect(). Previously only the single-item WITH collect(alias) AS list shape was supported.

Closes #1000

Benchmark impact

Unblocks LDBC SNB Interactive:

  • interactive-complex-9 (recent messages by friends/friends-of-friends)
  • interactive-complex-6 (tag co-occurrence)

Fix

_rewrite_collect_unwind_reentry_query() in lowering.py now:

  1. Scans all WITH items to find the collect() (not just the first/only)
  2. Rewrites the collect item and preserves other items as carried scalars
  3. Places the whole-row alias first so _compile_bounded_reentry_query() correctly identifies it

Test plan

  • 3 new tests: single scalar, multiple scalars, DISTINCT collect with scalar
  • 510 lowering tests pass, 0 failures
  • Lint clean
  • CI green

lmeyerov and others added 2 commits April 1, 2026 19:28
…CH (#1000)

IC-6 shape: WITH root.val AS rv, collect(b1) AS bees UNWIND bees AS b2
MATCH (b2)-[:Y]->(c) RETURN rv, c.id — currently rejected by
_rewrite_collect_unwind_reentry_query() which only handles the simple
WITH collect(alias) AS list UNWIND list AS alias form.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
_rewrite_collect_unwind_reentry_query() previously rejected WITH clauses
with more than one item. Now it finds the collect() item among multiple
WITH items, rewrites it, and places the whole-row alias first so the
reentry machinery correctly identifies it as the primary projection.

This unblocks LDBC SNB Interactive complex-6 and complex-9 query shapes:
  WITH tag.id AS knownTagId, collect(distinct friend) AS friends
  UNWIND friends AS f
  MATCH (f)<-[:HAS_CREATOR]-(post:Post) ...

Tests: 3 new tests (single scalar, multiple scalars, DISTINCT collect
with scalar). DRY: shared graph factory, removed duplicate test.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@lmeyerov
lmeyerov marked this pull request as ready for review April 2, 2026 03:07
@lmeyerov
lmeyerov merged commit fff9b81 into master Apr 2, 2026
101 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.

Cypher lowering does not support WITH ... UNWIND after MATCH-introduced graph aliases

1 participant