Skip to content

Commit

Permalink
fix prunproperties (#5494)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 authored Apr 14, 2023
1 parent 0adad87 commit f79c3b8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/graph/visitor/PropertyTrackerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ void PropertyTracker::insertVertexProp(const std::string &name,
vertexPropsMap[name][tagId].emplace(propName);
} else {
auto propIter = iter->second.find(tagId);
if (propIter == iter->second.end()) {
if (propIter == iter->second.end() || propName == "*") {
iter->second.erase(tagId);
std::unordered_set<std::string> temp({propName});
iter->second.emplace(tagId, std::move(temp));
} else {
Expand Down Expand Up @@ -209,18 +210,17 @@ void PropertyTrackerVisitor::visit(AttributeExpression *expr) {
switch (lhs->kind()) {
case Expression::Kind::kInputProperty:
case Expression::Kind::kVarProperty: {
// maybe: $e.prop
auto *varPropExpr = static_cast<PropertyExpression *>(lhs);
auto &entityAlias = varPropExpr->prop();
propsUsed_.insertEdgeProp(entityAlias, unknownType_, propName);
// maybe: $v.tag
// maybe : $v.tag
auto ret = qctx_->schemaMng()->toTagID(space_, propName);
if (!ret.ok()) {
status_ = std::move(ret).status();
if (ret.ok()) {
auto tagId = ret.value();
propsUsed_.insertVertexProp(entityAlias, tagId, "*");
break;
}
auto tagId = ret.value();
propsUsed_.insertVertexProp(entityAlias, tagId, "*");
// maybe: $e.prop
propsUsed_.insertEdgeProp(entityAlias, unknownType_, propName);
break;
}
case Expression::Kind::kCase: { // (case xxx).name
Expand Down
5 changes: 5 additions & 0 deletions src/graph/visitor/PrunePropertiesVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ void PrunePropertiesVisitor::pruneCurrent(Traverse *node) {
}
auto tagIter = usedVertexProps.find(tagId);
if (tagIter != usedVertexProps.end()) {
auto &tagProps = tagIter->second;
if (tagProps.find("*") != tagProps.end()) {
prunedVertexProps->emplace_back(vertexProp);
continue;
}
usedProps.insert(tagIter->second.begin(), tagIter->second.end());
}
if (usedProps.empty()) {
Expand Down
36 changes: 36 additions & 0 deletions tests/tck/features/match/MatchGroupBy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,39 @@ Feature: Match GroupBy
| "Danny Green" | 36 | 1 |
| "Dejounte Murray" | 33 | 1 |
| "Dirk Nowitzki" | 42 | 1 |

Scenario: [9] Match GroupBy
When executing query:
"""
MATCH p = (a)-[b:like]->(c)-[:serve]->(d:team)
WHERE id(a) == 'Tim Duncan'
WITH
a,
collect(
CASE c.player.name
WHEN null THEN null
ELSE [c.player.name, b.likeness, d.team.name]
END
) AS res
RETURN res
"""
Then the result should be, in order, with relax comparison:
| res |
| [["Tony Parker", 95, "Hornets"], ["Tony Parker", 95, "Spurs"], ["Manu Ginobili", 95, "Spurs"]] |
When executing query:
"""
MATCH p = (a)-[b:like]->(c)-[:serve]->(d:team)
WHERE id(a) == 'Tim Duncan'
WITH
a,
collect(
CASE c.player.name
WHEN null THEN null
ELSE [c.player, b.likeness, d.team.name]
END
) AS res
RETURN res
"""
Then the result should be, in order, with relax comparison:
| res |
| [[{age: 36, name: "Tony Parker"}, 95, "Hornets"], [{age: 36, name: "Tony Parker"}, 95, "Spurs"], [{age: 41, name: "Manu Ginobili"}, 95, "Spurs"]] |

0 comments on commit f79c3b8

Please sign in to comment.