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 fetch vertex properties(vertex) bug #3120

Merged
merged 3 commits into from
Oct 19, 2021
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
30 changes: 6 additions & 24 deletions src/graph/validator/FetchVerticesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ Status FetchVerticesValidator::validateImpl() {
return Status::OK();
}

Expression *FetchVerticesValidator::rewriteIDVertex2Vid(const Expression *expr) {
auto *pool = qctx_->objPool();
auto matcher = [](const Expression *e) -> bool {
std::string lowerStr = e->toString();
folly::toLowerAscii(lowerStr);
return e->kind() == Expression::Kind::kFunctionCall && lowerStr == "id(vertex)";
};
auto rewriter = [pool](const Expression *e) -> Expression * {
UNUSED(e);
return InputPropertyExpression::make(pool, nebula::kVid);
};

return RewriteVisitor::transform(expr, std::move(matcher), std::move(rewriter));
}

Status FetchVerticesValidator::validateTag(const NameLabelList *nameLabels) {
if (nameLabels == nullptr) {
// all tag
Expand Down Expand Up @@ -89,27 +74,24 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) {
}

auto &exprProps = fetchCtx_->exprProps;
for (const auto &col : yield->columns()) {
if (col->expr()->kind() == Expression::Kind::kVertex) {
extractVertexProp(exprProps);
break;
}
}

for (auto col : yield->columns()) {
if (ExpressionUtils::hasAny(col->expr(),
{Expression::Kind::kEdge, Expression::Kind::kPathBuild})) {
return Status::SemanticError("illegal yield clauses `%s'", col->toString().c_str());
}
col->setExpr(ExpressionUtils::rewriteLabelAttr2TagProp(col->expr()));
NG_RETURN_IF_ERROR(ValidateUtil::invalidLabelIdentifiers(col->expr()));

auto colExpr = col->expr();
auto typeStatus = deduceExprType(colExpr);
NG_RETURN_IF_ERROR(typeStatus);
outputs_.emplace_back(col->name(), typeStatus.value());
if (colExpr->kind() == Expression::Kind::kFunctionCall) {
if (colExpr->toString() == "id(VERTEX)") {
col->setAlias(col->name());
col->setExpr(rewriteIDVertex2Vid(colExpr));
col->setExpr(InputPropertyExpression::make(pool, nebula::kVid));
}
if (ExpressionUtils::hasAny(colExpr, {Expression::Kind::kVertex})) {
extractVertexProp(exprProps);
}
newCols->addColumn(col->clone().release());

Expand Down
2 changes: 0 additions & 2 deletions src/graph/validator/FetchVerticesValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class FetchVerticesValidator final : public Validator {

void extractVertexProp(ExpressionProps& exprProps);

Expression* rewriteIDVertex2Vid(const Expression* expr);

private:
std::map<TagID, std::shared_ptr<const meta::SchemaProviderIf>> tagsSchema_;

Expand Down
14 changes: 14 additions & 0 deletions tests/tck/features/fetch/FetchVertices.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,17 @@ Feature: Fetch Int Vid Vertices
Then the result should be, in any order, and the columns 0, 2 should be hashed:
| VertexID | player.name | id(VERTEX) |
| "Boris Diaw" | "Boris Diaw" | "Boris Diaw" |
When executing query:
"""
FETCH PROP ON player hash('Tim Duncan') YIELD id(vertex), properties(vertex).name as name, properties(vertex)
"""
Then the result should be, in any order, and the columns 0, 1 should be hashed:
| VertexID | id(VERTEX) | name | properties(VERTEX) |
| "Tim Duncan" | "Tim Duncan" | "Tim Duncan" | {age: 42, name: "Tim Duncan"} |
When executing query:
"""
FETCH PROP ON * hash('Tim Duncan') YIELD id(vertex), keys(vertex) as keys, tags(vertex) as tagss, properties(vertex) as props
"""
Then the result should be, in any order, and the columns 0, 1 should be hashed:
| VertexID | id(VERTEX) | keys | tagss | props |
| "Tim Duncan" | "Tim Duncan" | ["age", "name", "speciality"] | ["bachelor", "player"] | {age: 42, name: "Tim Duncan", speciality: "psychology"} |
14 changes: 14 additions & 0 deletions tests/tck/features/fetch/FetchVertices.strVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -513,3 +513,17 @@ Feature: Fetch String Vertices
Then the result should be, in any order:
| VertexID | player.name | id(VERTEX) |
| "Boris Diaw" | "Boris Diaw" | "Boris Diaw" |
When executing query:
"""
FETCH PROP ON player 'Tim Duncan' YIELD id(vertex), properties(vertex).name as name, properties(vertex)
"""
Then the result should be, in any order:
| VertexID | id(VERTEX) | name | properties(VERTEX) |
| "Tim Duncan" | "Tim Duncan" | "Tim Duncan" | {age: 42, name: "Tim Duncan"} |
When executing query:
"""
FETCH PROP ON * 'Tim Duncan' YIELD id(vertex), keys(vertex) as keys, tags(vertex) as tagss, properties(vertex) as props
"""
Then the result should be, in any order:
| VertexID | id(VERTEX) | keys | tagss | props |
| "Tim Duncan" | "Tim Duncan" | ["age", "name", "speciality"] | ["bachelor", "player"] | {age: 42, name: "Tim Duncan", speciality: "psychology"} |