Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pruneproperties #5494

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]] |