Skip to content

Commit

Permalink
Allow the expressions like 'v.tag' in return (#5440)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtcyclist authored Mar 28, 2023
1 parent b7ce0d2 commit 1e22423
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/graph/visitor/PropertyTrackerVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,19 @@ void PropertyTrackerVisitor::visit(AttributeExpression *expr) {
auto &propName = constVal.getStr();
switch (lhs->kind()) {
case Expression::Kind::kInputProperty:
case Expression::Kind::kVarProperty: { // $e.name
case Expression::Kind::kVarProperty: {
// maybe: $e.prop
auto *varPropExpr = static_cast<PropertyExpression *>(lhs);
auto &edgeAlias = varPropExpr->prop();
propsUsed_.insertEdgeProp(edgeAlias, unknownType_, propName);
auto &entityAlias = varPropExpr->prop();
propsUsed_.insertEdgeProp(entityAlias, unknownType_, propName);
// maybe: $v.tag
auto ret = qctx_->schemaMng()->toTagID(space_, propName);
if (!ret.ok()) {
status_ = std::move(ret).status();
break;
}
auto tagId = ret.value();
propsUsed_.insertVertexProp(entityAlias, tagId, "*");
break;
}
case Expression::Kind::kCase: { // (case xxx).name
Expand Down
6 changes: 5 additions & 1 deletion src/graph/visitor/PrunePropertiesVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ void PrunePropertiesVisitor::pruneCurrent(AppendVertices *node) {
usedProps.insert(unknownIter->second.begin(), unknownIter->second.end());
}
if (tagIter != usedVertexProps.end()) {
usedProps.insert(tagIter->second.begin(), tagIter->second.end());
if (tagIter->second.find("*") != tagIter->second.end()) {
usedProps.insert(props.begin(), props.end());
} else {
usedProps.insert(tagIter->second.begin(), tagIter->second.end());
}
}
if (usedProps.empty()) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions tests/tck/features/match/Base.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,8 @@ Feature: Basic match
MATCH (v:player{name:"Tim Duncan"}) RETURN v.player AS vtag
"""
Then the result should be, in any order:
| vtag |
| {name:"Tim Duncan"} |
| vtag |
| {age: 42, name: "Tim Duncan"} |
When executing query:
"""
MATCH (v:player)-[]->(b) WHERE v.age > 30 RETURN v.player.name AS vname
Expand Down
13 changes: 11 additions & 2 deletions tests/tck/features/match/Base.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,17 @@ Feature: Basic match
MATCH (v:player{name:"Tim Duncan"}) RETURN v.player AS vtag
"""
Then the result should be, in any order:
| vtag |
| {name:"Tim Duncan"} |
| vtag |
| {age: 42, name: "Tim Duncan"} |
When executing query:
"""
match (v)
where id(v) == "Tim Duncan"
return v.player, v.bachelor.name
"""
Then the result should be, in any order:
| v.player | v.bachelor.name |
| {age: 42, name: "Tim Duncan"} | "Tim Duncan" |
When executing query:
"""
MATCH (v:player)-[]->(b) WHERE v.age > 30 RETURN v.player.name AS vname
Expand Down

0 comments on commit 1e22423

Please sign in to comment.