Repository navigation
fix(#5490): apply the relationship inline WHERE on variable-length patterns - #5493
Conversation
…tterns
A relationship inline WHERE on a variable-length pattern was parsed onto the AST
but never handed to the traversal engine, so WHERE false still returned every
row. Two producers built a VariableLengthPathTraverser from the pattern and
passed only the types, the property map and the hop bounds: ExpandPathStep (the
MATCH executor) and PatternPredicateExpression.evaluateVLPPattern (the EXISTS {}
evaluator). GraphTraverser had no notion of a per-relationship predicate, so
there was nothing to pass it to.
Threads an optional Predicate<Edge> through the traversal package, applied at the
same per-edge choke point as the existing property filter, and forwarded by
VariableLengthPathTraverser to the BFS or DFS strategy it delegates to. Both
producers now build it from the pattern's WHERE, copying the enclosing bindings
once per source row so the predicate can reference outer-scope variables.
Pruning during traversal rather than post-filtering completed paths is
deliberate: under BFS shortest-path semantics a post-filter would discard a
target whose shortest path fails the predicate instead of finding the longer
path that satisfies it.
Pattern comprehensions were already correct and are pinned by a control test.
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 91.18% diff coverage · -8.38% coverage variation
Metric Results Coverage variation ✅ -8.38% coverage variation Diff coverage ✅ 91.18% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (4aaa90c) 138789 105147 75.76% Head commit (f18d3c0) 177857 (+39068) 119847 (+14700) 67.38% (-8.38%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#5493) 34 31 91.18% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Review: fix(#5490) apply relationship inline WHERE on variable-length patternsNice work. This is a high-quality, well-scoped fix. The diagnosis in the PR body and the
Minor suggestions (non-blocking)
The documented known gap (relationship variable binding to a single edge rather than the list for multi-hop reads) is correctly called out as pre-existing and out of scope. Overall: correct, well-tested, and consistent with the codebase's conventions. LGTM once you consider the DRY cleanup in (1). |
claude[bot] review on d41bd16 raised three non-blocking points, all applied. The two predicate builders in ExpandPathStep and PatternPredicateExpression were near-identical, so the scope-construction rule could drift between the MATCH and EXISTS spellings with only tests holding them together. Collapsed onto RelationshipPattern.buildInlineWherePredicate, which already owns both the relationship variable and the WHERE expression. Placed there rather than on GraphTraverser as suggested: GraphTraverser is in the traversal package and knows nothing about expression evaluation, so hosting the scope construction there would make the traversal layer depend on the AST and the evaluator. This also hoists getWhereExpression() out of the per-edge lambda, and the javadoc records that the returned predicate mutates a captured row and so needs a fresh instance per worker if variable-length traversal is ever parallelized.
|
Code review: PR #5493 - apply relationship inline WHERE on variable-length patterns Reviewed the diff and the touched traversal/AST classes. This is a tight, well-scoped fix and one of the more carefully argued PRs I have seen. Summary: looks correct, ship-worthy, with a couple of minor notes. What is good
Minor notes (non-blocking)
Nice work - the probe-before-fix table that surfaced the second broken surface ( |
Review: fix(#5490) apply the relationship inline WHERE on variable-length patternsThanks for the thorough writeup and the probing table, it made the review much easier to follow. Overall this is a clean, well-targeted fix: threading an optional I verified the central correctness claim independently: A few points below, one of which I would like your take on before merge. 1. The
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5493 +/- ##
============================================
- Coverage 66.60% 65.15% -1.46%
- Complexity 0 1113 +1113
============================================
Files 1696 1742 +46
Lines 138789 145858 +7069
Branches 30065 31226 +1161
============================================
+ Hits 92447 95032 +2585
- Misses 33680 37928 +4248
- Partials 12662 12898 +236 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #5490
A relationship inline
WHEREon a variable-length pattern was parsed onto the AST but never handed to the traversal engine, so-[r:E*1..1 WHERE r.tag = 'ok']->returned every row andWHERE falsereturned every row too. Two producers built aVariableLengthPathTraverserfrom the relationship pattern and passed only the types, the property map and the hop bounds:ExpandPathStep.createTraverser()(theMATCHexecutor) andPatternPredicateExpression.evaluateVLPPattern()(theEXISTS {}evaluator).GraphTraverserand its BFS/DFS subclasses had no notion of a per-relationship predicate, so there was nothing for the producers to pass it to. This threads an optionalPredicate<Edge>through the traversal package, applied at the same per-edge choke point as the existing property filter and forwarded byVariableLengthPathTraverserto whichever strategy it delegates to.Semantics: every relationship the path traverses must satisfy the predicate, matching the inline property map and the clause-level
all(e IN r WHERE ...)spelling. A test asserts the inline and clause-level spellings agree.Why prune rather than post-filter: filtering completed paths would be simpler, but under BFS shortest-path semantics it would discard a target whose shortest path fails the predicate instead of finding the longer path that satisfies it.
Performance: a null predicate means unconstrained, so patterns without an inline
WHEREdo no per-edge evaluation. Enclosing bindings are copied once per source row, not per edge, since a traversal evaluates this for every relationship it walks.Scope
The issue reported the
MATCHshape. I probed every surface that parses a variable-length relationship before fixing, which found a second broken one and two that were already correct:MATCH, fixed lengthMATCH, variable length (*1..1,*1..2,*)MATCH, variable length, property mapEXISTS {}, variable lengthEXISTS {}, variable length, property mapPattern comprehensions were already correct because
PatternComprehensionExpression.traverseVariableLengthenforces the predicate itself instead of delegating to the shared traverser. That is pinned by a control test so the two implementations cannot drift apart silently.Test plan
Issue5490VarLengthRelInlineWhereTest, 13 methods: 7 fail before the fix, all 13 pass afterWHERE false/WHERE trueas conclusive evidence the predicate is reaching the traversal*patternr.w < a.v + 10)all(e IN r WHERE ...)spellingEXISTS {}shapes, inlineWHEREand property mapcom.arcadedb.query.opencypher.**package: 7632 tests, 0 failuresExpandPathStep,PatternPredicateExpression,ShortestPathStepare the only ones, all inside the OpenCypher engine and all covered by that run.ShortestPathStepuses only the staticmatchesPropertyFilterhelper, which is untouched.OpenCypherCustomFunctionTestGraalVM polyglotNoClassDefFoundErrors are pre-existing: reproduced identically on a clean tree at 4aaa90c with the change stashedKnown gaps, not addressed here