From 518aa2a326253b7c5cbfe36609585a5e55b5d969 Mon Sep 17 00:00:00 2001 From: CPWstatic <13495049+CPWstatic@users.noreply.github.com> Date: Tue, 28 Dec 2021 21:10:27 +0800 Subject: [PATCH] Forbid redefined alias in a single path pattern. --- src/graph/validator/MatchValidator.cpp | 7 ++++++- tests/tck/features/match/MultiQueryParts.feature | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/graph/validator/MatchValidator.cpp b/src/graph/validator/MatchValidator.cpp index 82573403cc7..90f1668ceac 100644 --- a/src/graph/validator/MatchValidator.cpp +++ b/src/graph/validator/MatchValidator.cpp @@ -152,6 +152,7 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path, auto steps = path->steps(); auto *pool = qctx_->objPool(); nodeInfos.resize(steps + 1); + std::unordered_map nodeAliases; for (auto i = 0u; i <= steps; i++) { auto *node = path->node(i); @@ -176,7 +177,10 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path, anonymous = true; alias = vctx_->anonVarGen()->getVar(); } else { - aliases.emplace(alias, AliasType::kNode); + if (!nodeAliases.emplace(alias, AliasType::kNode).second) { + return Status::SemanticError("`%s': Redefined alias in a single path pattern.", + alias.c_str()); + } } Expression *filter = nullptr; if (props != nullptr) { @@ -196,6 +200,7 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path, nodeInfos[i].props = props; nodeInfos[i].filter = filter; } + aliases.merge(nodeAliases); return Status::OK(); } diff --git a/tests/tck/features/match/MultiQueryParts.feature b/tests/tck/features/match/MultiQueryParts.feature index 8ba7e4cb4a2..63d73327f1b 100644 --- a/tests/tck/features/match/MultiQueryParts.feature +++ b/tests/tck/features/match/MultiQueryParts.feature @@ -201,6 +201,16 @@ Feature: Multi Query Parts Then the result should be, in order: | scount | lcount | | 19 | 110 | + When executing query: + """ + MATCH (m:player{name:"Tim Duncan"})-[:like]-(n)--() + WITH m,n + MATCH (m)--(n) + RETURN count(*) AS scount + """ + Then the result should be, in order: + | scount | + | 270 | # Below scenario is not suppoted for the execution plan has a scan. When executing query: """ @@ -219,3 +229,8 @@ Feature: Multi Query Parts RETURN m """ Then a SemanticError should be raised at runtime: Alias used but not defined: `m' + When executing query: + """ + MATCH (v:player)-[e]-(v:team) RETURN v, e + """ + Then a SemanticError should be raised at runtime: `v': Redefined alias in a single path pattern.