ArcadeDB's OpenCypher engine was silently ignoring the WHERE clause written directly
inside a relationship bracket pattern, for example:
MATCH (a)-[r:KNOWS WHERE r.since < 2019]-(b) RETURN ...The ANTLR grammar correctly defines the inline WHERE expression in relationshipPattern,
but three layers all failed to propagate it:
- AST -
RelationshipPatternhad no field for the WHERE predicate. - Parser -
CypherASTBuilder.visitRelationshipPattern()never calledctx.expression(). - Executor -
MatchRelationshipStephad no code path to evaluate such a predicate.
- Added
whereExpression: BooleanExpressionfield. - Added
getWhereExpression()andhasWhereExpression()accessors. - Old two-arg and three-arg constructors delegate to the new four-arg constructor (backward compatible).
- After extracting variable/types/properties, checks
ctx.expression()and calls the existingparseBooleanExpression()helper to produce aBooleanExpression. - Passes it as the
whereExpressionargument to the newRelationshipPatternconstructor.
- Added
matchesEdgeWhereExpression(edge, lastResult)helper that builds a temporaryResultInternalwith the relationship variable bound to the edge and callswhereExpression.evaluate(tempResult, context). - The call is inserted right after the existing
matchesEdgePropertiescheck, so it short-circuits before heavier downstream processing.
Added OpenCypherPatternPredicateTest.InlineRelationshipPredicate (3 methods):
| Test | What it verifies |
|---|---|
inlineWhereOnRelationshipIsApplied |
Undirected pattern - only 2018 edge returned |
inlineWhereOnRelationshipDirected |
Directed pattern - single row, Alice->Bob:2018 |
inlineWhereWithExternalWhereClause |
Inline predicate combined with outer WHERE |
All 3 new tests pass. Full OpenCypher suite (5 377 tests) passes with no regressions.