Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 15, 2021
1 parent b3fac95 commit 02490a3
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 84 deletions.
6 changes: 1 addition & 5 deletions src/graph/planner/ngql/FetchVerticesPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/graph/planner/ngql/FetchVerticesPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions src/graph/planner/ngql/GoPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 18 additions & 15 deletions src/graph/validator/FetchVerticesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/graph/validator/test/FetchVerticesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
gv->setColNames({nebula::kVid, "person.name", "person.age"});
// project
auto yieldColumns = std::make_unique<YieldColumns>();
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;
Expand Down Expand Up @@ -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>();
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;
Expand Down Expand Up @@ -403,7 +403,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
gv->setColNames({nebula::kVid, "person.name", "person.age"});
// project
auto yieldColumns = std::make_unique<YieldColumns>();
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;
Expand All @@ -417,7 +417,7 @@ TEST_F(FetchVerticesValidatorTest, FetchVerticesProp) {
gv->setColNames({nebula::kVid, "person.name", "person.age"});
// project
auto yieldColumns = std::make_unique<YieldColumns>();
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;
Expand Down
15 changes: 11 additions & 4 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,6 @@ expression
| reduce_expression {
$$ = $1;
}
| KW_VERTEX {
$$ = VertexExpression::make(qctx->objPool());
}
;

constant_expression
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/fetch/FetchEmpty.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -40,15 +40,15 @@ 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:
"""
GO FROM "1" OVER zero_prop_edge YIELD zero_prop_edge._dst as id |
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

Expand Down
42 changes: 21 additions & 21 deletions tests/tck/features/fetch/FetchVertices.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions tests/tck/features/fetch/FetchVertices.strVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 |
Expand All @@ -314,21 +314,21 @@ 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 |
| "Manu Ginobili" |
| "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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/go/Orderby.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"}) |
Expand Down
Loading

0 comments on commit 02490a3

Please sign in to comment.