From 30e063b17393b1f2b2f7cc127a4520061047f9b9 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Mon, 18 Oct 2021 18:09:07 +0800 Subject: [PATCH 1/2] fix fetch vertex properties(vertex) bug --- src/graph/validator/FetchVerticesValidator.cpp | 8 ++++++++ tests/tck/features/fetch/FetchVertices.intVid.feature | 7 +++++++ tests/tck/features/fetch/FetchVertices.strVid.feature | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/src/graph/validator/FetchVerticesValidator.cpp b/src/graph/validator/FetchVerticesValidator.cpp index 114c983a281..0ae3e4f8649 100644 --- a/src/graph/validator/FetchVerticesValidator.cpp +++ b/src/graph/validator/FetchVerticesValidator.cpp @@ -94,6 +94,14 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) { extractVertexProp(exprProps); break; } + auto *expr = ExpressionUtils::findAny(col->expr(), {Expression::Kind::kFunctionCall}); + if (expr != nullptr) { + const auto &name = static_cast(expr)->name(); + if (name == "properties") { + extractVertexProp(exprProps); + break; + } + } } for (auto col : yield->columns()) { diff --git a/tests/tck/features/fetch/FetchVertices.intVid.feature b/tests/tck/features/fetch/FetchVertices.intVid.feature index aac6a8eac58..f07fe4fe3f6 100644 --- a/tests/tck/features/fetch/FetchVertices.intVid.feature +++ b/tests/tck/features/fetch/FetchVertices.intVid.feature @@ -402,3 +402,10 @@ 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"} | diff --git a/tests/tck/features/fetch/FetchVertices.strVid.feature b/tests/tck/features/fetch/FetchVertices.strVid.feature index 8d89694e0a0..d9479df7c5a 100644 --- a/tests/tck/features/fetch/FetchVertices.strVid.feature +++ b/tests/tck/features/fetch/FetchVertices.strVid.feature @@ -513,3 +513,10 @@ 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"} | From 78c5144510c602493c989c41df7dec951c7ac9c1 Mon Sep 17 00:00:00 2001 From: jimingquan Date: Tue, 19 Oct 2021 12:01:53 +0800 Subject: [PATCH 2/2] address comment --- .../validator/FetchVerticesValidator.cpp | 38 +++---------------- src/graph/validator/FetchVerticesValidator.h | 2 - .../fetch/FetchVertices.intVid.feature | 7 ++++ .../fetch/FetchVertices.strVid.feature | 7 ++++ 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/graph/validator/FetchVerticesValidator.cpp b/src/graph/validator/FetchVerticesValidator.cpp index 0ae3e4f8649..3dbcd19eaa5 100644 --- a/src/graph/validator/FetchVerticesValidator.cpp +++ b/src/graph/validator/FetchVerticesValidator.cpp @@ -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 @@ -89,21 +74,6 @@ 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(expr)->name(); - if (name == "properties") { - extractVertexProp(exprProps); - break; - } - } - } - for (auto col : yield->columns()) { if (ExpressionUtils::hasAny(col->expr(), {Expression::Kind::kEdge, Expression::Kind::kPathBuild})) { @@ -111,13 +81,17 @@ Status FetchVerticesValidator::validateYield(YieldClause *yield) { } 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()); diff --git a/src/graph/validator/FetchVerticesValidator.h b/src/graph/validator/FetchVerticesValidator.h index 608aa39ffd7..fda754f393d 100644 --- a/src/graph/validator/FetchVerticesValidator.h +++ b/src/graph/validator/FetchVerticesValidator.h @@ -30,8 +30,6 @@ class FetchVerticesValidator final : public Validator { void extractVertexProp(ExpressionProps& exprProps); - Expression* rewriteIDVertex2Vid(const Expression* expr); - private: std::map> tagsSchema_; diff --git a/tests/tck/features/fetch/FetchVertices.intVid.feature b/tests/tck/features/fetch/FetchVertices.intVid.feature index f07fe4fe3f6..cdbfe636d7a 100644 --- a/tests/tck/features/fetch/FetchVertices.intVid.feature +++ b/tests/tck/features/fetch/FetchVertices.intVid.feature @@ -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 * 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"} | diff --git a/tests/tck/features/fetch/FetchVertices.strVid.feature b/tests/tck/features/fetch/FetchVertices.strVid.feature index d9479df7c5a..ad1dc516c01 100644 --- a/tests/tck/features/fetch/FetchVertices.strVid.feature +++ b/tests/tck/features/fetch/FetchVertices.strVid.feature @@ -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 * '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"} |