Skip to content

Commit

Permalink
fix test error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 8, 2021
1 parent a2e08b6 commit 5374ced
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 41 deletions.
26 changes: 14 additions & 12 deletions src/graph/validator/GetSubgraphValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ Status GetSubgraphValidator::validateImpl() {
NG_RETURN_IF_ERROR(validateOutBound(gsSentence->out()));
NG_RETURN_IF_ERROR(validateBothInOutBound(gsSentence->both()));
NG_RETURN_IF_ERROR(validateYield(gsSentence->yield()));
// set output col & type
if (subgraphCtx_->steps.steps() == 0) {
outputs_.emplace_back(kVertices, Value::Type::VERTEX);
} else {
outputs_.emplace_back(kVertices, Value::Type::VERTEX);
outputs_.emplace_back(kEdges, Value::Type::EDGE);
}
return Status::OK();
}

Expand Down Expand Up @@ -108,28 +101,37 @@ Status GetSubgraphValidator::validateBothInOutBound(BothInOutClause* out) {

Status GetSubgraphValidator::validateYield(YieldClause* yield) {
auto pool = qctx_->objPool();
if (yield == nullptr) {
// version 3.0: return Status::SemanticError("No Yield Clause");
auto* yieldColumns = new YieldColumns();
auto* vertex = new YieldColumn(VertexExpression::make(pool));
yieldColumns->addColumn(vertex);
if (subgraphCtx_->steps.steps() != 0) {
auto* edge = new YieldColumn(EdgeExpression::make(pool));
yieldColumns->addColumn(edge);
}
yield = pool->add(new YieldClause(yieldColumns));
}
auto size = yield->columns().size();
outputs_.reserve(size);
YieldColumns* newCols = qctx_->objPool()->add(new YieldColumns());

for (const auto& col : yield->columns()) {
if (col->expr()->kind() == Expression::Kind::kVertex) {
subgraphCtx_->getVertexProp = true;
auto* newCol = new YieldColumn(InputPropertyExpression::make(pool, col->name()), col->name());
auto* newCol = new YieldColumn(InputPropertyExpression::make(pool, "VERTEX"), col->name());
newCols->addColumn(newCol);
} else if (col->expr()->kind() == Expression::Kind::kEdge) {
if (subgraphCtx_->steps.steps() == 0) {
return Status::SemanticError("Get Subgraph 0 STEPS only support YIELD vertex");
}
subgraphCtx_->getEdgeProp = true;
auto* newCol = new YieldColumn(InputPropertyExpression::make(pool, col->name()), col->name());
auto* newCol = new YieldColumn(InputPropertyExpression::make(pool, "EDGE"), col->name());
newCols->addColumn(newCol);
} else {
return Status::SemanticError("Get Subgraph only support YIELD vertex OR edge");
}
auto type = deduceExprType(col->expr());
NG_RETURN_IF_ERROR(type);
outputs_.emplace_back(col->name(), type.value());
outputs_.emplace_back(col->name(), Value::Type::LIST);
}
subgraphCtx_->yieldExpr = newCols;
subgraphCtx_->colNames = getOutColNames();
Expand Down
32 changes: 15 additions & 17 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -658,12 +658,6 @@ expression
| reduce_expression {
$$ = $1;
}
| KW_VERTEX {
$$ = VertexExpression::make(qctx->objPool());
}
| KW_EDGE {
$$ = EdgeExpression::make(qctx->objPool());
}
;

constant_expression
Expand Down Expand Up @@ -1355,7 +1349,21 @@ yield_columns
;

yield_column
: expression {
: KW_VERTEX {
$$ = new YieldColumn(VertexExpression::make(qctx->objPool()));
}
| KW_VERTEX KW_AS name_label {
$$ = new YieldColumn(VertexExpression::make(qctx->objPool()), *$3);
delete $3;
}
| KW_EDGE {
$$ = new YieldColumn(EdgeExpression::make(qctx->objPool()));
}
| KW_EDGE KW_AS name_label{
$$ = new YieldColumn(EdgeExpression::make(qctx->objPool()), *$3);
delete $3;
}
| expression {
$$ = new YieldColumn($1);
}
| expression KW_AS name_label {
Expand Down Expand Up @@ -2053,16 +2061,6 @@ both_in_out_clause

get_subgraph_sentence
: KW_GET KW_SUBGRAPH opt_with_properites step_clause from_clause in_bound_clause out_bound_clause both_in_out_clause yield_clause {
if ($9 == nullptr) {
auto* yieldColumns = new YieldColumns();
auto* vertex = new YieldColumn(VertexExpression::make(qctx->objPool()));
yieldColumns->addColumn(vertex);
if ($4->steps() != 0) {
auto* edge = new YieldColumn(EdgeExpression::make(qctx->objPool()));
yieldColumns->addColumn(edge);
}
$9 = new YieldClause(yieldColumns);
}
$$ = new GetSubgraphSentence($3, $4, $5, $6, $7, $8, $9);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/tck/features/bugfix/SubgraphBeforePipe.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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 |
| VERTEX | EDGE |
| [("Tim Duncan")] | <[edge1]> |

Scenario: subgraph as variable with limit
Expand Down Expand Up @@ -65,19 +65,19 @@ 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 |
| VERTEX | EDGE |
| [("Tim Duncan")] | <[edge1]> |

# TODO: access to the output of get subgraph.
# Currently _vertices is a reserved keyword.
# Currently VERTEX is a reserved keyword.
#
# Scenario: two steps subgraph with limit
# When executing query:
# """
# (root@nebula) [nba]> $a = GET SUBGRAPH WITH PROP 3 STEPS FROM 'Paul George' OUT serve BOTH like | yield COUNT($a._vertices)
# (root@nebula) [nba]> $a = GET SUBGRAPH WITH PROP 3 STEPS FROM 'Paul George' OUT serve BOTH like | yield COUNT($a.VERTEX)
# """
# Then the result should be, in any order, with relax comparison:
# | COUNT($a._vertices) |
# | COUNT($a.VERTEX) |
# | 4 |
Scenario: two steps subgraph with limit
When executing query:
Expand Down Expand Up @@ -157,7 +157,7 @@ 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 |
| VERTEX | EDGE |
| [("Tim Duncan")] | <[edge1]> |
| <[vertex2]> | <[edge2]> |

Expand All @@ -173,7 +173,7 @@ 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 |
| VERTEX | EDGE |
| [("Paul George")] | <[edge1]> |
| [("Russell Westbrook"), ("Pacers"), ("Thunders")] | <[edge2]> |
When executing query:
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/subgraph/subgraph.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Feature: Integer Vid subgraph
Then a SemanticError should be raised at runtime: Get Subgraph only support YIELD vertex OR edge
When executing query:
"""
GET SUBGRAPH 0 STEPS WITH PROP FROM hash("Tim Duncan") YIELD edge
GET SUBGRAPH WITH PROP 0 STEPS FROM hash("Tim Duncan") YIELD edge
"""
Then a SemanticError should be raised at runtime: Get Subgraph 0 STEPS only support YIELD vertex
When executing query:
Expand Down
9 changes: 5 additions & 4 deletions tests/tck/features/subgraph/subgraph.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
@jmq
Feature: subgraph

Background:
Expand Down Expand Up @@ -30,7 +31,7 @@ Feature: subgraph
Then a SemanticError should be raised at runtime: Get Subgraph only support YIELD vertex OR edge
When executing query:
"""
GET SUBGRAPH 0 STEPS WITH PROP FROM "Tim Duncan" YIELD edge
GET SUBGRAPH WITH PROP 0 STEPS FROM "Tim Duncan" YIELD edge
"""
Then a SemanticError should be raised at runtime: Get Subgraph 0 STEPS only support YIELD vertex
When executing query:
Expand Down Expand Up @@ -1032,6 +1033,6 @@ Feature: subgraph
GET SUBGRAPH 1 STEPS FROM "Tom"
"""
Then the result should be, in any order, with relax comparison:
| _vertices | _edges |
| [("Tom")] | [] |
| [] | [] |
| VERTEX | EDGE |
| [("Tom")] | [] |
| [] | [] |

0 comments on commit 5374ced

Please sign in to comment.