Skip to content

fix(planner): scan the start node of a later pattern that introduces a new variable - #172

Open
JayPokale wants to merge 1 commit into
lance-format:mainfrom
JayPokale:fix/multi-match-where-aliases
Open

JayPokale wants to merge 1 commit into
lance-format:mainfrom
JayPokale:fix/multi-match-where-aliases

Conversation

@JayPokale

Copy link
Copy Markdown

Closes #117

In a MATCH with several comma-separated patterns, LogicalPlanner::plan_path always continued a later path from the plan built so far, even when the path's start node is a variable that no earlier pattern bound. That start node was never scanned. For the query in #117 the logical plan was:

Filter
  Expand p -> h          <- p was never scanned
    Expand p -> c
      Expand c -> co
        ScanByLabel c

so the columns of p, and of nodes reached from it, were missing. On main the query from the issue fails with Failed to build filter: Schema error: No field named h__name, and the simpler

MATCH (c:City)-[:inCountry]->(co:Country), (p:Person)-[:livesIn]->(c)
WHERE co.name = 'France' RETURN p.id AS id

fails with No field named p__id.

The fix: when a later path starts at an unbound variable (or an anonymous node), plan a ScanByLabel for it and join it with the plan so far. As before, a path that starts at an already-bound variable continues from the plan. When the path then reaches an already-bound node (c above), the existing variable-reuse filter in join_relationship_to_target connects the two patterns, so the result is correct. The join is a cross join followed by that filter; a join on the relationship could be planned more cheaply, but I kept this change to fixing correctness.

Tests (tests/test_multi_match_where.rs), run on the DataFusion executor with three people, two cities, two countries and two hobbies:

Commands run in crates/lance-graph: cargo test (all unit, integration and doc tests pass), cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings.

I used an AI assistant (Claude) while working on this; I reviewed and tested the change.

…a new variable

In MATCH clauses with several comma-separated patterns, a path pattern
after the first one always continued from the plan built so far, even
when its start node was a variable that no earlier pattern had bound.
The start node was never scanned, so its columns, and the columns of
nodes reached from it, were missing, and the query failed with
"No field named ..." errors.

Scan such a start node and join it with the plan so far. When the path
then reaches an already-bound node, the existing variable-reuse filter
connects the two patterns.

Closes lance-format#117
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.

Multi-match query with WHERE predicate downstream filter/projection fails

1 participant