Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 18, 2021
1 parent 0630402 commit d2dcaa0
Show file tree
Hide file tree
Showing 13 changed files with 115 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
57 changes: 36 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 All @@ -279,6 +279,21 @@ Feature: Fetch Int Vid Vertices
| "Tim Duncan" |

Scenario: Typical errors
When executing query:
"""
FETCH PROP ON player hash('Boris Diaw') YIELD vertex
"""
Then a SyntaxError should be raised at runtime: please add alias when using vertex. near `vertex'
When executing query:
"""
FETCH PROP ON player hash('Boris Diaw') YIELD edge as a
"""
Then a SemanticError should be raised at runtime: illegal yield clauses `EDGE AS a'
When executing query:
"""
FETCH PROP ON player hash('Boris Diaw') YIELD src(edge)
"""
Then a SemanticError should be raised at runtime: illegal yield clauses `src(EDGE)'
# not support get src property
When executing query:
"""
Expand Down Expand Up @@ -352,34 +367,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
Loading

0 comments on commit d2dcaa0

Please sign in to comment.