Skip to content

Commit

Permalink
Forbid redefined alias in a single path pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Dec 28, 2021
1 parent babb547 commit 518aa2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, AliasType> nodeAliases;

for (auto i = 0u; i <= steps; i++) {
auto *node = path->node(i);
Expand All @@ -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) {
Expand All @@ -196,6 +200,7 @@ Status MatchValidator::buildNodeInfo(const MatchPath *path,
nodeInfos[i].props = props;
nodeInfos[i].filter = filter;
}
aliases.merge(nodeAliases);

return Status::OK();
}
Expand Down
15 changes: 15 additions & 0 deletions tests/tck/features/match/MultiQueryParts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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.

0 comments on commit 518aa2a

Please sign in to comment.