From f79c3b8355f7a79fcd4eb27c32f306c2eac7a954 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Fri, 14 Apr 2023 10:40:44 +0800 Subject: [PATCH] fix prunproperties (#5494) --- src/graph/visitor/PropertyTrackerVisitor.cpp | 16 ++++----- src/graph/visitor/PrunePropertiesVisitor.cpp | 5 +++ tests/tck/features/match/MatchGroupBy.feature | 36 +++++++++++++++++++ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/graph/visitor/PropertyTrackerVisitor.cpp b/src/graph/visitor/PropertyTrackerVisitor.cpp index 3e20f09f8e7..8fd0e42513f 100644 --- a/src/graph/visitor/PropertyTrackerVisitor.cpp +++ b/src/graph/visitor/PropertyTrackerVisitor.cpp @@ -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 temp({propName}); iter->second.emplace(tagId, std::move(temp)); } else { @@ -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(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 diff --git a/src/graph/visitor/PrunePropertiesVisitor.cpp b/src/graph/visitor/PrunePropertiesVisitor.cpp index 8cae8f06e1a..648e749bf9c 100644 --- a/src/graph/visitor/PrunePropertiesVisitor.cpp +++ b/src/graph/visitor/PrunePropertiesVisitor.cpp @@ -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()) { diff --git a/tests/tck/features/match/MatchGroupBy.feature b/tests/tck/features/match/MatchGroupBy.feature index 6fe3ae0c320..74020ea8815 100644 --- a/tests/tck/features/match/MatchGroupBy.feature +++ b/tests/tck/features/match/MatchGroupBy.feature @@ -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"]] |