diff --git a/src/graph/planner/ngql/FetchVerticesPlanner.cpp b/src/graph/planner/ngql/FetchVerticesPlanner.cpp index d908d206aa1..2782ab622e6 100644 --- a/src/graph/planner/ngql/FetchVerticesPlanner.cpp +++ b/src/graph/planner/ngql/FetchVerticesPlanner.cpp @@ -6,12 +6,8 @@ #include "graph/planner/ngql/FetchVerticesPlanner.h" -#include "graph/planner/plan/Algo.h" -#include "graph/planner/plan/Logic.h" -#include "graph/util/ExpressionUtils.h" +#include "graph/planner/plan/Query.h" #include "graph/util/PlannerUtil.h" -#include "graph/util/SchemaUtil.h" -#include "graph/validator/Validator.h" namespace nebula { namespace graph { diff --git a/src/graph/planner/ngql/FetchVerticesPlanner.h b/src/graph/planner/ngql/FetchVerticesPlanner.h index b24a7085233..7bbd9e34b91 100644 --- a/src/graph/planner/ngql/FetchVerticesPlanner.h +++ b/src/graph/planner/ngql/FetchVerticesPlanner.h @@ -11,8 +11,6 @@ #include "graph/context/ast/QueryAstContext.h" #include "graph/planner/Planner.h" #include "graph/planner/plan/PlanNode.h" -#include "graph/planner/plan/Query.h" -#include "graph/util/ExpressionUtils.h" namespace nebula { namespace graph { diff --git a/src/graph/planner/ngql/GoPlanner.cpp b/src/graph/planner/ngql/GoPlanner.cpp index 4c1e56dcac8..c12278417a1 100644 --- a/src/graph/planner/ngql/GoPlanner.cpp +++ b/src/graph/planner/ngql/GoPlanner.cpp @@ -6,12 +6,9 @@ #include "graph/planner/ngql/GoPlanner.h" -#include "graph/planner/plan/Algo.h" #include "graph/planner/plan/Logic.h" #include "graph/util/ExpressionUtils.h" #include "graph/util/PlannerUtil.h" -#include "graph/util/SchemaUtil.h" -#include "graph/validator/Validator.h" namespace nebula { namespace graph { diff --git a/src/graph/validator/FetchVerticesValidator.cpp b/src/graph/validator/FetchVerticesValidator.cpp index 0334205642c..0cb012fa0e9 100644 --- a/src/graph/validator/FetchVerticesValidator.cpp +++ b/src/graph/validator/FetchVerticesValidator.cpp @@ -68,37 +68,40 @@ Status FetchVerticesValidator::validateTag(const NameLabelList *nameLabels) { Status FetchVerticesValidator::validateYield(YieldClause *yield) { auto pool = qctx_->objPool(); - bool existVertex = false; + bool noYield = false; if (yield == nullptr) { // version 3.0: return Status::SemanticError("No YIELD Clause"); + // compatible with previous versions auto *yieldColumns = new YieldColumns(); - auto *vertex = new YieldColumn(VertexExpression::make(pool)); + auto *vertex = new YieldColumn(VertexExpression::make(pool), "vertices_"); yieldColumns->addColumn(vertex); yield = pool->add(new YieldClause(yieldColumns)); - existVertex = true; + noYield = true; } - for (const auto &col : yield->columns()) { - if (col->expr()->kind() == Expression::Kind::kVertex) { - existVertex = true; - break; - } - } - fetchCtx_->distinct = yield->isDistinct(); auto size = yield->columns().size(); outputs_.reserve(size + 1); - auto &exprProps = fetchCtx_->exprProps; auto *newCols = pool->add(new YieldColumns()); - if (!existVertex) { + if (!noYield) { outputs_.emplace_back(VertexID, vidType_); auto *vidCol = new YieldColumn(InputPropertyExpression::make(pool, nebula::kVid), VertexID); newCols->addColumn(vidCol); - } else { - extractVertexProp(exprProps); } + + 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()) { - // yield vertex or id(vertex) + 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(); diff --git a/src/graph/validator/test/FetchVerticesTest.cpp b/src/graph/validator/test/FetchVerticesTest.cpp index 8eec4604aa6..2d83805a4cb 100644 --- a/src/graph/validator/test/FetchVerticesTest.cpp +++ b/src/graph/validator/test/FetchVerticesTest.cpp @@ -40,7 +40,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { gv->setColNames({nebula::kVid, "person.name", "person.age"}); // project auto yieldColumns = std::make_unique(); - yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool))); + yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool), "vertices_")); auto *project = Project::make(qctx, gv, yieldColumns.get()); auto result = Eq(qctx->plan()->root(), project); ASSERT_TRUE(result.ok()) << result; @@ -70,7 +70,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { gv->setColNames({nebula::kVid, "person.name", "person.age", "book.name"}); // project auto yieldColumns = std::make_unique(); - yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool))); + yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool), "vertices_")); auto *project = Project::make(qctx, gv, yieldColumns.get()); auto result = Eq(qctx->plan()->root(), project); ASSERT_TRUE(result.ok()) << result; @@ -403,7 +403,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { gv->setColNames({nebula::kVid, "person.name", "person.age"}); // project auto yieldColumns = std::make_unique(); - yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool))); + yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool), "vertices_")); auto *project = Project::make(qctx, gv, yieldColumns.get()); auto result = Eq(qctx->plan()->root(), project); ASSERT_TRUE(result.ok()) << result; @@ -417,7 +417,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) { gv->setColNames({nebula::kVid, "person.name", "person.age"}); // project auto yieldColumns = std::make_unique(); - yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool))); + yieldColumns->addColumn(new YieldColumn(VertexExpression::make(pool), "vertices_")); auto *project = Project::make(qctx, gv, yieldColumns.get()); auto result = Eq(qctx->plan()->root(), project); ASSERT_TRUE(result.ok()) << result; diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 23cf2e2efd9..93dd0e7b232 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -658,9 +658,6 @@ expression | reduce_expression { $$ = $1; } - | KW_VERTEX { - $$ = VertexExpression::make(qctx->objPool()); - } ; constant_expression @@ -1051,7 +1048,17 @@ opt_argument_list ; argument_list - : expression { + : KW_VERTEX { + $$ = ArgumentList::make(qctx->objPool()); + Expression* arg = VertexExpression::make(qctx->objPool()); + $$->addArgument(arg); + } + | KW_EDGE { + $$ = ArgumentList::make(qctx->objPool()); + Expression *arg = EdgeExpression::make(qctx->objPool()); + $$->addArgument(arg); + } + | expression { $$ = ArgumentList::make(qctx->objPool()); Expression* arg = nullptr; arg = $1; diff --git a/tests/tck/features/fetch/FetchEmpty.feature b/tests/tck/features/fetch/FetchEmpty.feature index 4966081eea1..3fd183e831b 100644 --- a/tests/tck/features/fetch/FetchEmpty.feature +++ b/tests/tck/features/fetch/FetchEmpty.feature @@ -30,7 +30,7 @@ Feature: Fetch prop on empty tag/edge FETCH PROP ON * '1' """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ("1":zero_prop_tag_0:zero_prop_tag_1:person) | And drop the used space @@ -40,7 +40,7 @@ Feature: Fetch prop on empty tag/edge FETCH PROP ON zero_prop_tag_0 '1' """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ("1":zero_prop_tag_0) | When executing query: """ @@ -48,7 +48,7 @@ Feature: Fetch prop on empty tag/edge FETCH PROP ON zero_prop_tag_0 $-.id """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ("2":zero_prop_tag_0) | And drop the used space diff --git a/tests/tck/features/fetch/FetchVertices.intVid.feature b/tests/tck/features/fetch/FetchVertices.intVid.feature index a34bb76460b..d05cde1390e 100644 --- a/tests/tck/features/fetch/FetchVertices.intVid.feature +++ b/tests/tck/features/fetch/FetchVertices.intVid.feature @@ -25,7 +25,7 @@ Feature: Fetch Int Vid Vertices FETCH PROP ON player hash('Boris Diaw') """ Then the result should be, in any order: - | VERTEX | + | vertices_ | | (hash('Boris Diaw'):player{age:36,name:"Boris Diaw"}) | # Fetch prop on not existing vertex When executing query: @@ -207,7 +207,7 @@ Feature: Fetch Int Vid Vertices FETCH PROP ON * hash('NON EXIST VERTEX ID') """ Then the result should be, in any order: - | VERTEX | + | vertices_ | # on existing vertex When executing query: """ @@ -253,13 +253,13 @@ Feature: Fetch Int Vid Vertices FETCH PROP ON * hash('Tim Duncan') """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ("Tim Duncan":player:bachelor) | Scenario: Fetch and Yield id(v) When executing query: """ - FETCH PROP ON player hash('Boris Diaw'), hash('Tony Parker') | YIELD id($-.VERTEX) as id + FETCH PROP ON player hash('Boris Diaw'), hash('Tony Parker') | YIELD id($-.vertices_) as id """ Then the result should be, in any order, and the columns 0 should be hashed: | id | @@ -352,34 +352,34 @@ Feature: Fetch Int Vid Vertices | "Boris Diaw" | "Boris Diaw" | 36 | When executing query: """ - FETCH PROP ON * hash('Boris Diaw') YIELD id(vertex), player.age, vertex + FETCH PROP ON * hash('Boris Diaw') YIELD id(vertex), player.age, vertex as node """ - Then the result should be, in any order, and the columns 0 should be hashed: - | id(VERTEX) | player.age | VERTEX | - | "Boris Diaw" | 36 | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | + Then the result should be, in any order, and the columns 0, 1 should be hashed: + | VertexID | id(VERTEX) | player.age | node | + | "Boris Diaw" | "Boris Diaw" | 36 | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | When executing query: """ - FETCH PROP ON * hash('Boris Diaw') YIELD vertex + FETCH PROP ON * hash('Boris Diaw') YIELD vertex as node """ - Then the result should be, in any order: - | VERTEX | - | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | + Then the result should be, in any order, and the columns 0 should be hashed: + | VertexID | node | + | "Boris Diaw" | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | When executing query: """ - FETCH PROP ON * hash("Tim Duncan") YIELD player.name, player.age, team.name, bachelor.name, bachelor.speciality, vertex + FETCH PROP ON * hash("Tim Duncan") YIELD player.name, player.age, team.name, bachelor.name, bachelor.speciality, vertex as node """ - Then the result should be, in any order: - | player.name | player.age | team.name | bachelor.name | bachelor.speciality | VERTEX | - | "Tim Duncan" | 42 | EMPTY | "Tim Duncan" | "psychology" | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + Then the result should be, in any order, and the columns 0 should be hashed: + | VertexID | player.name | player.age | team.name | bachelor.name | bachelor.speciality | node | + | "Tim Duncan" | "Tim Duncan" | 42 | EMPTY | "Tim Duncan" | "psychology" | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | When executing query: """ GO FROM hash("Tim Duncan") OVER like YIELD like._dst as id | - FETCH PROP ON * $-.id YIELD VERTEX + FETCH PROP ON * $-.id YIELD VERTEX as node """ - Then the result should be, in any order: - | VERTEX | - | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | - | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + Then the result should be, in any order, and the columns 0 should be hashed: + | VertexID | node | + | "Manu Ginobili" | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + | "Tony Parker" | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | When executing query: """ FETCH PROP ON * hash('NON EXIST VERTEX ID'), hash('Boris Diaw') yield player.name, id(vertex) diff --git a/tests/tck/features/fetch/FetchVertices.strVid.feature b/tests/tck/features/fetch/FetchVertices.strVid.feature index 7e0de9f3e8c..835ee535e1f 100644 --- a/tests/tck/features/fetch/FetchVertices.strVid.feature +++ b/tests/tck/features/fetch/FetchVertices.strVid.feature @@ -32,14 +32,14 @@ Feature: Fetch String Vertices FETCH PROP ON bachelor 'Tim Duncan' """ Then the result should be, in any order: - | VERTEX | + | vertices_ | | ("Tim Duncan":bachelor{name:"Tim Duncan",speciality:"psychology"}) | When executing query: """ FETCH PROP ON player 'Boris Diaw' """ Then the result should be, in any order: - | VERTEX | + | vertices_ | | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | Scenario: Fetch Vertices works with ORDER BY @@ -137,7 +137,7 @@ Feature: Fetch String Vertices FETCH PROP ON * 'NON EXIST VERTEX ID' """ Then the result should be, in any order: - | VERTEX | + | vertices_ | Scenario: Fetch prop on * When executing query: @@ -303,7 +303,7 @@ Feature: Fetch String Vertices Scenario: Fetch and Yield id(v) When executing query: """ - FETCH PROP ON player 'Boris Diaw', 'Tony Parker' | YIELD id($-.`VERTEX`) as id + FETCH PROP ON player 'Boris Diaw', 'Tony Parker' | YIELD id($-.vertices_) as id """ Then the result should be, in any order: | id | @@ -314,13 +314,13 @@ Feature: Fetch String Vertices Scenario: Output fetch result to graph traverse When executing query: """ - FETCH PROP ON player 'NON EXIST VERTEX ID' | go from id($-.VERTEX) over like yield like._dst + FETCH PROP ON player 'NON EXIST VERTEX ID' | go from id($-.vertices_) over like yield like._dst """ Then the result should be, in any order: | like._dst | When executing query: """ - FETCH PROP ON player "Tim Duncan" | go from id($-.`VERTEX`) over like yield like._dst + FETCH PROP ON player "Tim Duncan" | go from id($-.vertices_) over like yield like._dst """ Then the result should be, in any order: | like._dst | @@ -328,7 +328,7 @@ Feature: Fetch String Vertices | "Tony Parker" | When executing query: """ - FETCH PROP ON player "Tim Duncan", "Yao Ming" | go from id($-.VERTEX) over like yield like._dst + FETCH PROP ON player "Tim Duncan", "Yao Ming" | go from id($-.vertices_) over like yield like._dst """ Then the result should be, in any order: | like._dst | @@ -346,7 +346,7 @@ Feature: Fetch String Vertices | "Tony Parker" | When executing query: """ - $var = FETCH PROP ON player "Tim Duncan", "Yao Ming"; go from id($var.VERTEX) over like yield like._dst + $var = FETCH PROP ON player "Tim Duncan", "Yao Ming"; go from id($var.vertices_) over like yield like._dst """ Then the result should be, in any order: | like._dst | @@ -463,34 +463,34 @@ Feature: Fetch String Vertices | "Boris Diaw" | "Boris Diaw" | 36 | When executing query: """ - FETCH PROP ON * 'Boris Diaw' YIELD id(vertex), player.age, vertex + FETCH PROP ON * 'Boris Diaw' YIELD id(vertex), player.age, vertex as node """ Then the result should be, in any order: - | id(VERTEX) | player.age | VERTEX | - | "Boris Diaw" | 36 | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | + | VertexID | id(VERTEX) | player.age | node | + | "Boris Diaw" | "Boris Diaw" | 36 | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | When executing query: """ - FETCH PROP ON * 'Boris Diaw' YIELD vertex + FETCH PROP ON * 'Boris Diaw' YIELD vertex as node """ Then the result should be, in any order: - | VERTEX | - | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | + | VertexID | node | + | "Boris Diaw" | ("Boris Diaw":player{name:"Boris Diaw", age:36}) | When executing query: """ - FETCH PROP ON * "Tim Duncan" YIELD player.name, player.age, team.name, bachelor.name, bachelor.speciality, vertex + FETCH PROP ON * "Tim Duncan" YIELD player.name, player.age, team.name, bachelor.name, bachelor.speciality, vertex as node """ Then the result should be, in any order: - | player.name | player.age | team.name | bachelor.name | bachelor.speciality | VERTEX | - | "Tim Duncan" | 42 | EMPTY | "Tim Duncan" | "psychology" | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | + | VertexID | player.name | player.age | team.name | bachelor.name | bachelor.speciality | node | + | "Tim Duncan" | "Tim Duncan" | 42 | EMPTY | "Tim Duncan" | "psychology" | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | When executing query: """ GO FROM "Tim Duncan" OVER like YIELD like._dst as id | - FETCH PROP ON * $-.id YIELD VERTEX + FETCH PROP ON * $-.id YIELD node """ Then the result should be, in any order: - | VERTEX | - | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | - | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | VertexID | node | + | "Manu Ginobili" | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + | "Tony Parker" | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | When executing query: """ FETCH PROP ON * 'NON EXIST VERTEX ID', 'Boris Diaw' yield player.name, id(vertex) diff --git a/tests/tck/features/go/Orderby.feature b/tests/tck/features/go/Orderby.feature index 94137fa83ea..989407486a6 100644 --- a/tests/tck/features/go/Orderby.feature +++ b/tests/tck/features/go/Orderby.feature @@ -194,7 +194,7 @@ Feature: Orderby Sentence $var = GO FROM "Tony Parker" OVER like YIELD like._dst AS dst; ORDER BY $var.dst DESC | FETCH PROP ON * $-.dst """ Then the result should be, in order, with relax comparison: - | VERTEX | + | vertices_ | | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | | ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) | | ("LaMarcus Aldridge" :player{age: 33, name: "LaMarcus Aldridge"}) | diff --git a/tests/tck/features/insert/Insert.feature b/tests/tck/features/insert/Insert.feature index 9d6b6affea2..bf93863d498 100644 --- a/tests/tck/features/insert/Insert.feature +++ b/tests/tck/features/insert/Insert.feature @@ -70,7 +70,7 @@ Feature: Insert string vid of vertex and edge FETCH PROP ON * "Tom" """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ("Tom":person{name:"Tom", age:18}:interest{name:"basketball"}) | # insert vertex wrong type value When executing query: @@ -147,7 +147,7 @@ Feature: Insert string vid of vertex and edge FETCH PROP ON person "Conan" """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ('Conan') | # insert vertex with string timestamp succeeded When try to execute query: @@ -508,7 +508,7 @@ Feature: Insert string vid of vertex and edge FETCH PROP ON course "English" """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | | ('English') | # check result When executing query: diff --git a/tests/tck/features/mutate/InsertWithTimeType.feature b/tests/tck/features/mutate/InsertWithTimeType.feature index 95ebb24e0f5..6dde75b6774 100644 --- a/tests/tck/features/mutate/InsertWithTimeType.feature +++ b/tests/tck/features/mutate/InsertWithTimeType.feature @@ -142,7 +142,7 @@ Feature: Insert with time-dependent types FETCH PROP ON tag_date "test"; """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | When executing query: """ FETCH PROP ON edge_date "test_src"->"test_dst"; diff --git a/tests/tck/features/ttl/TTL.feature b/tests/tck/features/ttl/TTL.feature index 2125e948fe4..ffd176b79f4 100644 --- a/tests/tck/features/ttl/TTL.feature +++ b/tests/tck/features/ttl/TTL.feature @@ -349,7 +349,7 @@ Feature: TTLTest FETCH PROP ON person "1"; """ Then the result should be, in any order, with relax comparison: - | VERTEX | + | vertices_ | When executing query: """ FETCH PROP ON person "1" YIELD person.id as id