Skip to content

Commit

Permalink
Allow redefined aliases in with. Remove redudant columns in return. (#…
Browse files Browse the repository at this point in the history
…4868)

Allow redefined aliases in with. Remove redudant columns in return.
  • Loading branch information
xtcyclist authored Nov 28, 2022
1 parent 645afb4 commit f485455
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,28 @@ Status MatchValidator::buildColumnsForAllNamedAliases(const std::vector<QueryPar
}
}

std::set<std::string> visitedAliases;
for (auto &match : currQueryPart.matchs) {
for (auto &path : match->paths) {
for (size_t i = 0; i < path.edgeInfos.size(); ++i) {
if (!path.nodeInfos[i].anonymous) {
columns->addColumn(makeColumn(path.nodeInfos[i].alias));
if (visitedAliases.find(path.nodeInfos[i].alias) == visitedAliases.end()) {
columns->addColumn(makeColumn(path.nodeInfos[i].alias));
visitedAliases.emplace(path.nodeInfos[i].alias);
}
}
if (!path.edgeInfos[i].anonymous) {
columns->addColumn(makeColumn(path.edgeInfos[i].alias));
if (visitedAliases.find(path.edgeInfos[i].alias) == visitedAliases.end()) {
columns->addColumn(makeColumn(path.edgeInfos[i].alias));
visitedAliases.emplace(path.edgeInfos[i].alias);
}
}
}
if (!path.nodeInfos.back().anonymous) {
columns->addColumn(makeColumn(path.nodeInfos.back().alias));
if (visitedAliases.find(path.nodeInfos.back().alias) == visitedAliases.end()) {
columns->addColumn(makeColumn(path.nodeInfos.back().alias));
visitedAliases.emplace(path.nodeInfos.back().alias);
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/tck/features/match/RedefinedNode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,20 @@ Feature: Redefined symbols
MATCH (v:player{name:"abc"})-[e:like]->(v1)-[e:like]->(v2) RETURN *
"""
Then a SemanticError should be raised at runtime: `e': Redefined alias

Scenario: Redefined alias in with
Given an empty graph
And load "nba" csv data to a new space
And having executed:
"""
insert edge like (likeness) values "Tim Duncan"->"Tim Duncan":(100);
insert edge like (likeness) values "Carmelo Anthony"->"Carmelo Anthony":(100);
"""
When executing query:
"""
MATCH (n0)-[e0]->(n0) WHERE (id(n0) IN ["Tim Duncan", "Carmelo Anthony" ]) with * RETURN *
"""
Then the result should be, in any order:
| n0 | e0 |
| ("Tim Duncan" :player{age: 42, name: "Tim Duncan"} :bachelor{name: "Tim Duncan", speciality: "psychology"}) | [:like "Tim Duncan"->"Tim Duncan" @0 {likeness: 100}] |
| ("Carmelo Anthony" :player{age: 34, name: "Carmelo Anthony"}) | [:like "Carmelo Anthony"->"Carmelo Anthony" @0 {likeness: 100}] |

0 comments on commit f485455

Please sign in to comment.