Skip to content

Commit

Permalink
Fix delete vertex check wrong vid type (vesoft-inc#917)
Browse files Browse the repository at this point in the history
* fix delete vertex use ref vid

* fix fmt
  • Loading branch information
laura-ding authored Apr 2, 2021
1 parent e4a9681 commit 67523d8
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/validator/MutateValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ Status DeleteVerticesValidator::validateImpl() {
vidRef_ = sentence->vertices()->ref();
auto type = deduceExprType(vidRef_);
NG_RETURN_IF_ERROR(type);
if (type.value() != Value::Type::STRING) {
if (type.value() != vidType_) {
std::stringstream ss;
ss << "The vid should be string type, "
<< "but input is `" << type.value() << "'";
ss << "The vid `" << vidRef_->toString() << "' should be type of `" << vidType_
<< "', but was`" << type.value() << "'";
return Status::SemanticError(ss.str());
}
} else {
Expand Down
54 changes: 54 additions & 0 deletions tests/tck/features/delete/DeleteEdge.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,57 @@ Feature: Delete int vid of edge
| $^.person.name | friend.intimacy | friend._dst |
| "Zhangsan" | 50 | "Jack" |
Then drop the used space

Scenario: delete edges use pipe
Given load "nba_int_vid" csv data to a new space
# test delete with pipe wrong vid type
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like YIELD (string)like._src as id | DELETE EDGE like $-.id->$-.id
"""
Then a ExecutionError should be raised at runtime: Wrong srcId type `STRING`, value
# delete with pipe, get result by go
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Tony Parker" |
| "Tim Duncan" |
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like
YIELD like._src as src, like._dst as dst, like._rank as rank
| DELETE EDGE like $-.src->$-.dst @ $-.rank
"""
Then the execution should be successful
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like
"""
Then the result should be, in any order:
| like._dst |
# delete with var, get result by go
When executing query:
"""
GO FROM hash("Russell Westbrook") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Paul George" |
| "James Harden" |
When executing query:
"""
$var = GO FROM hash("Russell Westbrook") OVER like YIELD
like._src as src, like._dst as dst, like._rank as rank;
DELETE EDGE like $var.src -> $var.dst @ $var.rank
"""
Then the execution should be successful
When executing query:
"""
GO FROM hash("Russell Westbrook") OVER like
"""
Then the result should be, in any order:
| like._dst |
And drop the used space
2 changes: 1 addition & 1 deletion tests/tck/features/delete/DeleteEdge.feature
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Feature: Delete string vid of edge
| "Zhangsan" | 50 | "Jack" |
Then drop the used space

Scenario: delete edges for 2.0 syntax
Scenario: delete edges use pipe
Given load "nba" csv data to a new space
# test delete with pipe wrong vid type
When executing query:
Expand Down
114 changes: 114 additions & 0 deletions tests/tck/features/delete/DeleteVertex.IntVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,118 @@ Feature: Delete int vid of vertex
"""
Then the result should be, in any order:
| VertexID | player.name | player.age |

Scenario: delete int vertex by pipe successed
Given load "nba_int_vid" csv data to a new space
# test delete with pipe wrong vid type
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like YIELD (string)like._src as id | DELETE VERTEX $-.id
"""
Then a SemanticError should be raised at runtime:
# delete with pipe, get result by go
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Tony Parker" |
| "Tim Duncan" |
When executing query:
"""
GO FROM hash("Tony Parker") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "LaMarcus Aldridge" |
| "Manu Ginobili" |
| "Tim Duncan" |
When executing query:
"""
GO FROM hash("Tim Duncan") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Tony Parker" |
| "Manu Ginobili" |
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like YIELD like._dst as id | DELETE VERTEX $-.id
"""
Then the execution should be successful
When executing query:
"""
GO FROM hash("Boris Diaw") OVER like
"""
Then the result should be, in any order:
| like._dst |
When executing query:
"""
GO FROM hash("Tony Parker") OVER like
"""
Then the result should be, in any order:
| like._dst |
When executing query:
"""
GO FROM hash("Tim Duncan") OVER like
"""
Then the result should be, in any order:
| like._dst |

Scenario: delete with pipe failed, because of the wrong vid type
When executing query:
"""
USE nba_int_vid;YIELD "Tom" as id | DELETE VERTEX $-.id;
"""
Then a SemanticError should be raised at runtime: The vid `$-.id' should be type of `INT', but was`STRING'
Then drop the used space

Scenario: delete with var, get result by go
Given load "nba_int_vid" csv data to a new space
When executing query:
"""
GO FROM hash("Russell Westbrook") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Paul George" |
| "James Harden" |
When executing query:
"""
GO FROM hash("Paul George") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Russell Westbrook" |
When executing query:
"""
GO FROM hash("James Harden") OVER like
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| like._dst |
| "Russell Westbrook" |
When executing query:
"""
$var = GO FROM hash("Russell Westbrook") OVER like YIELD like._dst as id; DELETE VERTEX $var.id
"""
Then the execution should be successful
When executing query:
"""
GO FROM hash("Russell Westbrook") OVER like
"""
Then the result should be, in any order:
| like._dst |
When executing query:
"""
GO FROM hash("Paul George") OVER like
"""
Then the result should be, in any order:
| like._dst |
When executing query:
"""
GO FROM hash("Russell Westbrook") OVER like
"""
Then the result should be, in any order:
| like._dst |
Then drop the used space
8 changes: 5 additions & 3 deletions tests/tck/features/delete/DeleteVertex.feature
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ Feature: Delete string vid of vertex
| VertexID | player.name | player.age |
Then drop the used space

Scenario: delete vertex by pipe
Scenario: delete string vertex by pipe
Given load "nba" csv data to a new space
# test delete with pipe wrong vid type
When executing query:
"""
GO FROM "Boris Diaw" OVER like YIELD like._type as id | DELETE VERTEX $-.id
"""
Then a SemanticError should be raised at runtime: The vid should be string type, but input is `INT'
Then a SemanticError should be raised at runtime:
# delete with pipe, get result by go
When executing query:
"""
Expand Down Expand Up @@ -255,7 +255,9 @@ Feature: Delete string vid of vertex
"""
Then the result should be, in any order:
| like._dst |
# delete with var, get result by go

Scenario: delete with var, get result by go
Given load "nba" csv data to a new space
When executing query:
"""
GO FROM "Russell Westbrook" OVER like
Expand Down

0 comments on commit 67523d8

Please sign in to comment.