Skip to content

fix(cypher): lower list comprehensions in unwind - #209

Merged
prrao87 merged 1 commit into
mainfrom
fix/unwind-list-comprehension
Nov 25, 2026
Merged

prrao87 merged 1 commit into
mainfrom
fix/unwind-list-comprehension

Conversation

@prrao87

@prrao87 prrao87 commented Nov 25, 2026

Copy link
Copy Markdown
Member

Why

UNWIND over a list comprehension panicked with entered unreachable code: the logical planner turns comprehensions into operators. WITH and RETURN turn comprehensions into plan operators before planning their expressions, but UNWIND skipped that step, so the comprehension reached an expression planner that assumes it never sees one. Both forms failed, with a filter or a map, over a literal list or a collected one.

UNWIND [x IN [1, 2, 3] WHERE x > 1] AS y RETURN y   -- now returns 2, 3

Closes #206.

What changed

  • When an UNWIND list contains a comprehension, the planner now applies the same rewrite WITH uses: the comprehension becomes an operator on the input rows (or on a single empty row when UNWIND starts the query), and UNWIND then unwinds the resulting column.
  • UNWIND lists without a comprehension are planned exactly as before, so other queries see no plan change. This PR makes no performance claim, and the benchmark suites were not run.
  • The rewrite runs before the UNWIND alias is bound, so the alias isn't visible inside its own list expression.

Validation

  • New Rust unit test checks the plan: Project over Unwind on the comprehension's column over ListComprehension.
  • New Python tests run the three queries from the issue (filter, map, and a collected list) and check their results.
  • cargo fmt --all, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass locally.
  • In python/: make test (1803 passed, 2 skipped) and make lint pass locally.
  • Pattern comprehensions in UNWIND take the same path but have no dedicated test. Node.js tests and the docs build weren't run, since neither bindings nor docs changed. CI pending.

🤖 Generated with Claude Code

UNWIND passed its list expression to the physical planner unlowered, so a
list comprehension reached the unreachable branch in expression.rs. Run it
through rewrite_exists_in_value, as WITH and RETURN do.

Closes #206
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying lance-csr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1705263
Status: ✅  Deploy successful!
Preview URL: https://99ad7b90.lance-csr.pages.dev
Branch Preview URL: https://fix-unwind-list-comprehensio.lance-csr.pages.dev

View logs

@prrao87
prrao87 marked this pull request as ready for review November 25, 2026 15:41
@prrao87
prrao87 merged commit e3278fd into main Nov 25, 2026
9 checks passed
@prrao87
prrao87 deleted the fix/unwind-list-comprehension branch November 25, 2026 15:42
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.

UNWIND over a list comprehension panics with unreachable code

1 participant