Skip to content

Commit

Permalink
Fix variable types collected and graph crash
Browse files Browse the repository at this point in the history
add test cases
  • Loading branch information
czpmango committed Oct 14, 2022
1 parent 992b5c6 commit fd97376
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/graph/planner/match/MatchPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> aliases;
for (const auto* expr : exprs) {
DCHECK_EQ(expr->kind(), Expression::Kind::kLabelTagProperty);
auto* labelExpr = static_cast<const LabelTagPropertyExpression*>(expr)->label();
DCHECK_EQ(labelExpr->kind(), Expression::Kind::kVarProperty);
aliases.emplace_back(static_cast<const PropertyExpression*>(labelExpr)->prop());
if (expr->kind() == Expression::Kind::kVarProperty) {
aliases.emplace_back(static_cast<const PropertyExpression*>(expr)->prop());
} else {
DCHECK_EQ(expr->kind(), Expression::Kind::kLabel);
aliases.emplace_back(static_cast<const LabelExpression*>(expr)->name());
}
}
auto aliasesGenerated = matchCtx->aliasesGenerated;
if (!std::all_of(aliases.begin(), aliases.end(), [&aliasesGenerated](std::string& alias) {
Expand Down
37 changes: 37 additions & 0 deletions tests/tck/features/match/MultiLineMultiQueryParts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -361,3 +392,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.

0 comments on commit fd97376

Please sign in to comment.