Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Oct 19, 2021
1 parent 30e063b commit 8900443
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
38 changes: 6 additions & 32 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,35 +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;
}
auto *expr = ExpressionUtils::findAny(col->expr(), {Expression::Kind::kFunctionCall});
if (expr != nullptr) {
const auto &name = static_cast<const FunctionCallExpression *>(expr)->name();
if (name == "properties") {
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
7 changes: 7 additions & 0 deletions tests/tck/features/fetch/FetchVertices.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,10 @@ Feature: Fetch Int Vid Vertices
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 player 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"} |
7 changes: 7 additions & 0 deletions tests/tck/features/fetch/FetchVertices.strVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,10 @@ Feature: Fetch String Vertices
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 player '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"} |

0 comments on commit 8900443

Please sign in to comment.