diff --git a/src/graph/planner/match/MatchPlanner.cpp b/src/graph/planner/match/MatchPlanner.cpp index 4f234b5c891..8110793578d 100644 --- a/src/graph/planner/match/MatchPlanner.cpp +++ b/src/graph/planner/match/MatchPlanner.cpp @@ -78,17 +78,19 @@ Status MatchPlanner::connectMatchPlan(SubPlan& queryPlan, MatchClauseContext* ma if (matchCtx->isOptional) { // connect LeftJoin match filter auto& whereCtx = matchCtx->where; - if (whereCtx.get() != nullptr) { - auto exprs = - ExpressionUtils::collectAll(whereCtx->filter, {Expression::Kind::kLabelTagProperty}); + if (whereCtx.get() != nullptr && whereCtx->filter != nullptr) { + auto exprs = ExpressionUtils::collectAll( + whereCtx->filter, {Expression::Kind::kVarProperty, Expression::Kind::kLabel}); // Check if all aliases in where clause are generated by the current match statement pattern std::vector aliases; for (const auto* expr : exprs) { - DCHECK_EQ(expr->kind(), Expression::Kind::kLabelTagProperty); - auto* labelExpr = static_cast(expr)->label(); - DCHECK_EQ(labelExpr->kind(), Expression::Kind::kVarProperty); - aliases.emplace_back(static_cast(labelExpr)->prop()); + if (expr->kind() == Expression::Kind::kVarProperty) { + aliases.emplace_back(static_cast(expr)->prop()); + } else { + DCHECK_EQ(expr->kind(), Expression::Kind::kLabel); + aliases.emplace_back(static_cast(expr)->name()); + } } auto aliasesGenerated = matchCtx->aliasesGenerated; if (!std::all_of(aliases.begin(), aliases.end(), [&aliasesGenerated](std::string& alias) { diff --git a/tests/tck/features/match/MultiLineMultiQueryParts.feature b/tests/tck/features/match/MultiLineMultiQueryParts.feature index 05bc40e0429..1b4c9e1634b 100644 --- a/tests/tck/features/match/MultiLineMultiQueryParts.feature +++ b/tests/tck/features/match/MultiLineMultiQueryParts.feature @@ -172,6 +172,37 @@ Feature: Multi Line Multi Query Parts | "Tim Duncan" | "Manu Ginobili" | NULL | | "Tim Duncan" | "Manu Ginobili" | NULL | | "Tim Duncan" | "Manu Ginobili" | NULL | + When executing query: + """ + MATCH (m)-[]->(n) WHERE id(m)=="Tim Duncan" + OPTIONAL MATCH (n)-[]->(l) WHERE id(n)=="Tony Parker" + RETURN id(m) AS m, id(n) AS n, id(l) AS l; + """ + Then the result should be, in any order: + | m | n | l | + | "Tim Duncan" | "Spurs" | NULL | + | "Tim Duncan" | "LaMarcus Aldridge" | NULL | + | "Tim Duncan" | "Tony Parker" | "Spurs" | + | "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" | + | "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" | + | "Tim Duncan" | "Tony Parker" | "Kyle Anderson" | + | "Tim Duncan" | "Tony Parker" | "Tim Duncan" | + | "Tim Duncan" | "Tony Parker" | "Tim Duncan" | + | "Tim Duncan" | "Tony Parker" | "Manu Ginobili" | + | "Tim Duncan" | "Tony Parker" | "Manu Ginobili" | + | "Tim Duncan" | "Tony Parker" | "Hornets" | + | "Tim Duncan" | "Tony Parker" | "Spurs" | + | "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" | + | "Tim Duncan" | "Tony Parker" | "LaMarcus Aldridge" | + | "Tim Duncan" | "Tony Parker" | "Kyle Anderson" | + | "Tim Duncan" | "Tony Parker" | "Tim Duncan" | + | "Tim Duncan" | "Tony Parker" | "Tim Duncan" | + | "Tim Duncan" | "Tony Parker" | "Manu Ginobili" | + | "Tim Duncan" | "Tony Parker" | "Manu Ginobili" | + | "Tim Duncan" | "Tony Parker" | "Hornets" | + | "Tim Duncan" | "Danny Green" | NULL | + | "Tim Duncan" | "Manu Ginobili" | NULL | + | "Tim Duncan" | "Manu Ginobili" | NULL | When executing query: """ OPTIONAL match (v:player) WHERE v.player.age > 41 @@ -245,7 +276,6 @@ Feature: Multi Line Multi Query Parts | count | | 4 | - @skip Scenario: Multi Line Multi Query Parts When executing query: """ @@ -288,15 +318,6 @@ Feature: Multi Line Multi Query Parts Then the result should be, in order: | scount | | 270 | - When executing query: - """ - MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan" - OPTIONAL MATCH (n)-->(v) WHERE v.player.age < m.player.age - RETURN count(*) AS count - """ - Then the result should be, in order: - | count | - | 45 | When executing query: """ MATCH (a:player{age:42}) WITH a @@ -361,3 +382,9 @@ Feature: Multi Line Multi Query Parts RETURN n,v """ Then a SemanticError should be raised at runtime: The where clause of optional match statement that reference variables defined by other statements is not supported yet. + When executing query: + """ + MATCH (m)-[]-(n) WHERE id(m)=="Tim Duncan" + OPTIONAL MATCH (n)-->(v) WHERE id(v) < id(m) RETURN count(*) AS count + """ + Then a SemanticError should be raised at runtime: The where clause of optional match statement that reference variables defined by other statements is not supported yet. diff --git a/tests/tck/ldbc/business_intelligence_workload/Read.feature b/tests/tck/ldbc/business_intelligence_workload/Read.feature index 5f80adc70cf..523aa4d4788 100644 --- a/tests/tck/ldbc/business_intelligence_workload/Read.feature +++ b/tests/tck/ldbc/business_intelligence_workload/Read.feature @@ -156,6 +156,7 @@ Feature: LDBC Business Intelligence Workload - Read (forum)-[:HAS_MEMBER]->(person:Person) OPTIONAL MATCH (person)<-[:HAS_CREATOR]-(post:Post)<-[:CONTAINER_OF]-(popularForum:Forum) + WITH popularForums, popularForum, person, post WHERE popularForum IN popularForums RETURN person.Person.id AS personId,