Fixes #3244 : label filtering in Cypher MATCH relationship patterns#3252
Merged
lvca merged 3 commits intoArcadeData:mainfrom Jan 27, 2026
Merged
Conversation
Two bugs caused incorrect results in multi-MATCH/OPTIONAL MATCH Cypher queries: 1. MatchRelationshipStep never filtered target vertices by label. A pattern like (a:CHUNK)<-[r:in]-(b:NER) would return ANY connected vertex as b, not just NER vertices. Fixed by passing the target NodePattern and checking vertex type against label constraints. 2. Already-bound variables with labels were treated as unbound. The sourceAlreadyBound check required !sourceNode.hasLabels(), so writing (searchedChunk:CHUNK) in a subsequent MATCH created a full type scan instead of using the already-bound value. Fixed by tracking bound variable names across MATCH clauses. Also adds identity checking: when a target variable is already bound from a previous step, the traversed vertex must match the bound vertex identity. https://claude.ai/code/session_017hhsQf7fzBvXcGSeg48hfP
AssertJ's assertThat() has ambiguous overloads for Object return types from getProperty(). Switched to JUnit assertEquals/assertTrue/assertFalse. https://claude.ai/code/session_017hhsQf7fzBvXcGSeg48hfP
Contributor
🧪 CI InsightsHere's what we observed from your CI run for 1fc22ba. 🟢 All jobs passed!But CI Insights is watching 👀 |
Contributor
Author
|
Claude code did what gemini could not do. Claude code wrote all of this. |
Collaborator
|
@claude review this pr |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Contributor
|
@claude please check this again |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Contributor
Author
Contributor
|
@ExtReMLapin could you please rebase from main? Maybe claude is confused because it's too far apart? |
Contributor
Author
|
Claude is confused because it's not a branch on your repo but on mine. |
Contributor
|
@claude please review this PR |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Contributor
|
I'm checking it manually - old fashion. |
lvca
approved these changes
Jan 27, 2026
Contributor
|
Merged thanks! |
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.
What does this PR do?
This PR fixes a critical bug in Cypher query execution where target node labels in relationship patterns were not being filtered, and bound variables with repeated labels in subsequent MATCH clauses were not being properly recognized. This caused:
(chunk:CHUNK)<-[r:in]-(target:NER)would return vertices of all types connected via the "in" edge, not just NER verticessearchedChunk:CHUNKin multiple clauses) was not recognized as referring to the same bound variable, causing unnecessary cross-joinsMotivation
This fix addresses a user-reported issue where complex Cypher queries with multiple OPTIONAL MATCH clauses and repeated labels on bound variables were returning incorrect data. The root causes were:
MatchRelationshipStepwas not filtering target vertices by their labelsRelated issues
This fixes the issue reported in the user's query pattern where
searchedChunkswas incorrectly containing NER nodes instead of only CHUNK nodes.Changes Made
CypherExecutionPlan.java
boundVariablestracking across MATCH clauses to detect already-bound variablesbuildMatchStep()to skip creating new MatchNodeStep for variables already bound in previous MATCH clausesboundVariablesset and the old heuristicMatchRelationshipStepinstantiation to pass target node pattern and bound variables for filteringMatchRelationshipStep.java
targetNodePatternandboundVariableNamesfields to support label filtering and bound variable checkingmatchesTargetLabel()method to filter target vertices by their labelsCypherLabelFilteringTest.java (new)
Issue3218Test.java
Additional Notes
MatchRelationshipStepconstructor has an overload that maintains the old behaviorChecklist
mvn clean packagecommandhttps://claude.ai/code/session_017hhsQf7fzBvXcGSeg48hfP