Skip to content

Commit

Permalink
fix yield colname
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 13, 2021
1 parent 2493d5c commit 2f9d545
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 223 deletions.
1 change: 1 addition & 0 deletions .linters/cpp/checkKeyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'KW_DESCRIBE',
'KW_DESC',
'KW_VERTEX',
'KW_VERTICES',
'KW_EDGE',
'KW_EDGES',
'KW_UPDATE',
Expand Down
4 changes: 2 additions & 2 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ Status GetSubgraphValidator::validateYield(YieldClause* yield) {
newCols->addColumn(newCol);
} else if (lowerStr == "edges" || lowerStr == "_edges") {
if (subgraphCtx_->steps.steps() == 0) {
return Status::SemanticError("Get Subgraph 0 STEPS only support YIELD VERTICES");
return Status::SemanticError("Get Subgraph 0 STEPS only support YIELD vertices");
}
subgraphCtx_->getEdgeProp = true;
auto* newCol = new YieldColumn(InputPropertyExpression::make(pool, "EDGES"), col->name());
newCols->addColumn(newCol);
} else {
return Status::SemanticError("Get Subgraph only support YIELD VERTICES OR EDGES");
return Status::SemanticError("Get Subgraph only support YIELD vertices OR edges");
}
outputs_.emplace_back(col->name(), Value::Type::LIST);
}
Expand Down
41 changes: 40 additions & 1 deletion src/graph/validator/test/GetSubgraphValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_F(GetSubgraphValidatorTest, Base) {
EXPECT_TRUE(checkResult(query, expected));
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"1\" BOTH like";
std::string query = "GET SUBGRAPH WITH PROP FROM \"1\" BOTH like YIELD vertices AS a";
std::vector<PlanNode::Kind> expected = {
PK::kProject,
PK::kDataCollect,
Expand Down Expand Up @@ -162,6 +162,45 @@ TEST_F(GetSubgraphValidatorTest, Input) {
}
}

TEST_F(GetSubgraphValidatorTest, invalidYield) {
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD vertice";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: Get Subgraph only support YIELD vertices OR edges");
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD vertices";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using vertices. near `vertices'");
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD vertices as a, edge";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using edge. near `edge'");
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD vertices as a, edges";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using edges. near `edges'");
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD path";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: Get Subgraph only support YIELD vertices OR edges");
}
{
std::string query = "GET SUBGRAPH WITH PROP FROM \"Tim Duncan\" YIELD 123";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SemanticError: Get Subgraph only support YIELD vertices OR edges");
}
}

TEST_F(GetSubgraphValidatorTest, RefNotExist) {
{
std::string query = "GET SUBGRAPH WITH PROP FROM $-.id";
Expand Down
29 changes: 20 additions & 9 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static constexpr size_t kCommentLengthLimit = 256;
%token KW_BOOL KW_INT8 KW_INT16 KW_INT32 KW_INT64 KW_INT KW_FLOAT KW_DOUBLE
%token KW_STRING KW_FIXED_STRING KW_TIMESTAMP KW_DATE KW_TIME KW_DATETIME
%token KW_GO KW_AS KW_TO KW_USE KW_SET KW_FROM KW_WHERE KW_ALTER
%token KW_MATCH KW_INSERT KW_VALUES KW_YIELD KW_RETURN KW_CREATE KW_VERTEX
%token KW_MATCH KW_INSERT KW_VALUES KW_YIELD KW_RETURN KW_CREATE KW_VERTEX KW_VERTICES
%token KW_EDGE KW_EDGES KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE KW_DELETE KW_FIND
%token KW_TAG KW_TAGS KW_UNION KW_INTERSECT KW_MINUS
%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_DESC KW_SHOW KW_HOST KW_HOSTS KW_PART KW_PARTS KW_ADD
Expand Down Expand Up @@ -444,7 +444,6 @@ unreserved_keyword
| KW_DBA { $$ = new std::string("dba"); }
| KW_GUEST { $$ = new std::string("guest"); }
| KW_GROUP { $$ = new std::string("group"); }
| KW_PATH { $$ = new std::string("path"); }
| KW_DATA { $$ = new std::string("data"); }
| KW_LEADER { $$ = new std::string("leader"); }
| KW_UUID { $$ = new std::string("uuid"); }
Expand Down Expand Up @@ -491,6 +490,7 @@ unreserved_keyword
| KW_BOTH { $$ = new std::string("both"); }
| KW_OUT { $$ = new std::string("out"); }
| KW_SUBGRAPH { $$ = new std::string("subgraph"); }
| KW_PATH { $$ = new std::string("path"); }
| KW_THEN { $$ = new std::string("then"); }
| KW_ELSE { $$ = new std::string("else"); }
| KW_END { $$ = new std::string("end"); }
Expand Down Expand Up @@ -1350,21 +1350,32 @@ yield_columns

yield_column
: KW_VERTEX {
$$ = new YieldColumn(VertexExpression::make(qctx->objPool()));
$$ = nullptr;
throw nebula::GraphParser::syntax_error(@1, "please add alias when using vertex.");
}
| KW_VERTEX KW_AS name_label {
$$ = new YieldColumn(VertexExpression::make(qctx->objPool()), *$3);
delete $3;
$$ = new YieldColumn(VertexExpression::make(qctx->objPool()), *$3);
delete $3;
}
| KW_VERTICES {
$$ = nullptr;
throw nebula::GraphParser::syntax_error(@1, "please add alias when using vertices.");
}
| KW_VERTICES KW_AS name_label {
$$ = new YieldColumn(LabelExpression::make(qctx->objPool(), "VERTICES"), *$3);
delete $3;
}
| KW_EDGE {
$$ = new YieldColumn(EdgeExpression::make(qctx->objPool()));
$$ = nullptr;
throw nebula::GraphParser::syntax_error(@1, "please add alias when using edge.");
}
| KW_EDGE KW_AS name_label {
$$ = new YieldColumn(EdgeExpression::make(qctx->objPool()), *$3);
delete $3;
$$ = new YieldColumn(EdgeExpression::make(qctx->objPool()), *$3);
delete $3;
}
| KW_EDGES {
$$ = new YieldColumn(LabelExpression::make(qctx->objPool(), "EDGES"));
$$ = nullptr;
throw nebula::GraphParser::syntax_error(@1, "please add alias when using edges.");
}
| KW_EDGES KW_AS name_label {
$$ = new YieldColumn(LabelExpression::make(qctx->objPool(), "EDGES"), *$3);
Expand Down
3 changes: 2 additions & 1 deletion src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
"DESCRIBE" { return TokenType::KW_DESCRIBE; }
"DESC" { return TokenType::KW_DESC; }
"VERTEX" { return TokenType::KW_VERTEX; }
"VERTICES" { return TokenType::KW_VERTICES; }
"EDGE" { return TokenType::KW_EDGE; }
"EDGES" { return TokenType::KW_EDGES; }
"UPDATE" { return TokenType::KW_UPDATE; }
Expand Down Expand Up @@ -188,7 +189,6 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
"ACCOUNT" { return TokenType::KW_ACCOUNT; }
"JOBS" { return TokenType::KW_JOBS; }
"JOB" { return TokenType::KW_JOB; }
"PATH" { return TokenType::KW_PATH; }
"BIDIRECT" { return TokenType::KW_BIDIRECT; }
"STATS" { return TokenType::KW_STATS; }
"STATUS" { return TokenType::KW_STATUS; }
Expand All @@ -205,6 +205,7 @@ IP_OCTET ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
"STORAGE" { return TokenType::KW_STORAGE; }
"SHORTEST" { return TokenType::KW_SHORTEST; }
"NOLOOP" { return TokenType::KW_NOLOOP; }
"PATH" { return TokenType::KW_PATH; }
"OUT" { return TokenType::KW_OUT; }
"BOTH" { return TokenType::KW_BOTH; }
"SUBGRAPH" { return TokenType::KW_SUBGRAPH; }
Expand Down
30 changes: 15 additions & 15 deletions tests/tck/features/bugfix/SubgraphBeforePipe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Test get subgraph before pipe
Scenario: subgraph with limit
When executing query:
"""
GET SUBGRAPH WITH PROP FROM 'Tim Duncan' YIELD VERTICES, EDGES | LIMIT 1
GET SUBGRAPH WITH PROP FROM 'Tim Duncan' YIELD VERTICES as nodes, EDGES as relationships | LIMIT 1
"""
Then define some list variables:
| edge1 |
Expand All @@ -35,13 +35,13 @@ Feature: Test get subgraph before pipe
| [:teammate "Tim Duncan"->"Manu Ginobili"@0] |
| [:teammate "Tim Duncan"->"Tony Parker"@0] |
Then the result should be, in any order, with relax comparison:
| VERTICES | EDGES |
| [("Tim Duncan")] | <[edge1]> |
| nodes | relationships |
| [("Tim Duncan")] | <[edge1]> |

Scenario: subgraph as variable with limit
When executing query:
"""
$a = GET SUBGRAPH WITH PROP FROM 'Tim Duncan' YIELD VERTICES, EDGES| LIMIT 1
$a = GET SUBGRAPH WITH PROP FROM 'Tim Duncan' YIELD VERTICES as nodes, edges as relationships | LIMIT 1
"""
Then define some list variables:
| edge1 |
Expand All @@ -65,8 +65,8 @@ Feature: Test get subgraph before pipe
| [:teammate "Tim Duncan"->"Manu Ginobili"@0] |
| [:teammate "Tim Duncan"->"Tony Parker"@0] |
Then the result should be, in any order, with relax comparison:
| VERTICES | EDGES |
| [("Tim Duncan")] | <[edge1]> |
| nodes | relationships |
| [("Tim Duncan")] | <[edge1]> |

# TODO: access to the output of get subgraph.
# Currently VERTEX is a reserved keyword.
Expand All @@ -82,7 +82,7 @@ Feature: Test get subgraph before pipe
Scenario: two steps subgraph with limit
When executing query:
"""
GET SUBGRAPH WITH PROP 2 STEPS FROM 'Tim Duncan' YIELD VERTICES, EDGES | LIMIT 2
GET SUBGRAPH WITH PROP 2 STEPS FROM 'Tim Duncan' YIELD VERTICES as nodes, EDGES as relationships | LIMIT 2
"""
Then define some list variables:
| edge1 | vertex2 | edge2 |
Expand Down Expand Up @@ -157,14 +157,14 @@ Feature: Test get subgraph before pipe
| | | [:serve "Tiago Splitter"->"76ers"@0] |
| | | [:serve "Tiago Splitter"->"Hawks"@0] |
Then the result should be, in any order, with relax comparison:
| VERTICES | EDGES |
| [("Tim Duncan")] | <[edge1]> |
| <[vertex2]> | <[edge2]> |
| nodes | relationships |
| [("Tim Duncan")] | <[edge1]> |
| <[vertex2]> | <[edge2]> |

Scenario: three steps subgraph with property + direction + limit
When executing query:
"""
GET SUBGRAPH WITH PROP 3 STEPS FROM 'Paul George' OUT serve BOTH like YIELD VERTICES, EDGES| LIMIT 2
GET SUBGRAPH WITH PROP 3 STEPS FROM 'Paul George' OUT serve BOTH like YIELD vertices as nodes, edges as relationships | LIMIT 2
"""
Then define some list variables:
| edge1 | edge2 |
Expand All @@ -173,12 +173,12 @@ Feature: Test get subgraph before pipe
| [:serve "Paul George"->"Thunders"@0] | [:serve "Russell Westbrook"->"Thunders"@0] |
| [:like "Paul George"->"Russell Westbrook"@0] | [:like "Russell Westbrook"->"James Harden"@0] |
Then the result should be, in any order, with relax comparison:
| VERTICES | EDGES |
| [("Paul George")] | <[edge1]> |
| [("Russell Westbrook"), ("Pacers"), ("Thunders")] | <[edge2]> |
| nodes | relationships |
| [("Paul George")] | <[edge1]> |
| [("Russell Westbrook"), ("Pacers"), ("Thunders")] | <[edge2]> |
When executing query:
"""
GET SUBGRAPH WITH PROP 3 STEPS FROM 'Paul George' OUT serve BOTH like | YIELD COUNT(*)
GET SUBGRAPH WITH PROP 3 STEPS FROM 'Paul George' OUT serve BOTH like YIELD vertices as a, edges as b | YIELD COUNT(*)
"""
Then the result should be, in any order, with relax comparison:
| COUNT(*) |
Expand Down
Loading

0 comments on commit 2f9d545

Please sign in to comment.