Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Sep 18, 2021
1 parent 74e0d3c commit 2dfa9ba
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/graph/validator/LookupValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ Status LookupValidator::validateYield() {
if (lookupCtx_->isEdge) {
idxReturnCols_.emplace_back(kSrc);
idxReturnCols_.emplace_back(kDst);
idxReturnCols_.emplace_back(kType);
idxReturnCols_.emplace_back(kRank);
idxReturnCols_.emplace_back(kType);
outputs_.emplace_back(kSrcVID, vidType_);
outputs_.emplace_back(kDstVID, vidType_);
outputs_.emplace_back(kRanking, Value::Type::INT);
Expand Down
26 changes: 26 additions & 0 deletions src/graph/validator/test/LookupValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,31 @@ TEST_F(LookupValidatorTest, InvalidFilterExpression) {
EXPECT_TRUE(checkResult(query, {}));
}
}

TEST_F(LookupValidatorTest, wrongYield) {
{
std::string query = "LOOKUP ON person YIELD vertex";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using vertex. near `vertex'");
}
{
std::string query = "LOOKUP ON person YIELD vertex as node, edge";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()),
"SyntaxError: please add alias when using edge. near `edge'");
}
{
std::string query = "LOOKUP ON person YIELD edge as e";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: illegal yield clauses `EDGE AS e'");
}
{
std::string query = "LOOKUP ON person YIELD vertex as node, player.age";
auto result = checkResult(query);
EXPECT_EQ(std::string(result.message()), "SemanticError: Schema name error: player");
}
}

} // namespace graph
} // namespace nebula
1 change: 0 additions & 1 deletion tests/tck/features/lookup/LookupTag.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@jmq
Feature: Test lookup on tag index
Examples:
| where_condition |
Expand Down
46 changes: 46 additions & 0 deletions tests/tck/features/lookup/WithYield.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ Feature: Lookup with yield
| VertexID | player.name |
| 'Kobe Bryant' | 'Kobe Bryant' |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' |
When executing query:
"""
LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1
"""
Then the result should be, in any order:
| VertexID | player.name | (player.age+1) |
| 'Kobe Bryant' | 'Kobe Bryant' | 41 |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 |
When executing query:
"""
LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1, vertex as node
"""
Then the result should be, in any order:
| VertexID | player.name | (player.age+1) | node |
| 'Kobe Bryant' | 'Kobe Bryant' | 41 | ("Kobe Bryant" : player {age : 40, name : "Kobe Bryant"}) |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 | ("Dirk Nowitzki" : player {age : 40, name : "Dirk Nowitzki"}) |

Scenario: [1] tag with yield rename
When executing query:
Expand All @@ -22,6 +38,15 @@ Feature: Lookup with yield
| VertexID | name |
| 'Kobe Bryant' | 'Kobe Bryant' |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' |
When executing query:
"""
LOOKUP ON team WHERE team.name in ["76ers", "Lakers", "Spurs"] YIELD vertex AS node
"""
Then the result should be, in any order:
| VertexID | node |
| '76ers' | ("76ers" : team {name : "76ers"}) |
| 'Lakers' | ("Lakers" : team {name : "Lakers"}) |
| 'Spurs' | ("Spurs" : team {name : "Spurs"}) |

Scenario: [2] edge with yield
When executing query:
Expand All @@ -33,6 +58,15 @@ Feature: Lookup with yield
| SrcVID | DstVID | Ranking | serve.start_year |
| 'Russell Westbrook' | 'Thunders' | 0 | 2008 |
| 'Marc Gasol' | 'Grizzlies' | 0 | 2008 |
When executing query:
"""
LOOKUP ON serve WHERE serve.start_year == 2008 and serve.end_year == 2019
YIELD serve.start_year, edge as relationship
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking | serve.start_year | relationship |
| 'Russell Westbrook' | 'Thunders' | 0 | 2008 | [:serve "Russell Westbrook"->"Thunders" @0 {end_year: 2019, start_year: 2008}] |
| 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | [:serve "Marc Gasol"->"Grizzlies" @0 {end_year: 2019, start_year: 2008}] |

Scenario: [2] edge with yield rename
When executing query:
Expand All @@ -44,3 +78,15 @@ Feature: Lookup with yield
| SrcVID | DstVID | Ranking | startYear |
| 'Russell Westbrook' | 'Thunders' | 0 | 2008 |
| 'Marc Gasol' | 'Grizzlies' | 0 | 2008 |
When executing query:
"""
LOOKUP ON like WHERE like.likeness < 50 + 1 YIELD like.likeness, edge as relationship
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking | like.likeness | relationship |
| "Blake Griffin" | "Chris Paul" | 0 | -1 | [:like "Blake Griffin"->"Chris Paul" @0 {likeness: -1}] |
| "Dirk Nowitzki" | "Dwyane Wade" | 0 | 10 | [:like "Dirk Nowitzki"->"Dwyane Wade" @0 {likeness: 10}] |
| "Kyrie Irving" | "LeBron James" | 0 | 13 | [:like "Kyrie Irving"->"LeBron James" @0 {likeness: 13}] |
| "Marco Belinelli" | "Tony Parker" | 0 | 50 | [:like "Marco Belinelli"->"Tony Parker" @0 {likeness: 50}] |
| "Rajon Rondo" | "Ray Allen" | 0 | -1 | [:like "Rajon Rondo"->"Ray Allen" @0 {likeness: -1}] |
| "Ray Allen" | "Rajon Rondo" | 0 | 9 | [:like "Ray Allen"->"Rajon Rondo" @0 {likeness: 9}] |
46 changes: 46 additions & 0 deletions tests/tck/features/lookup/WithYield.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ Feature: Lookup with yield in integer vid
| VertexID | player.name |
| 'Kobe Bryant' | 'Kobe Bryant' |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' |
When executing query:
"""
LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| VertexID | player.name | (player.age+1) |
| 'Kobe Bryant' | 'Kobe Bryant' | 41 |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 |
When executing query:
"""
LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1, vertex as node
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| VertexID | player.name | (player.age+1) | node |
| 'Kobe Bryant' | 'Kobe Bryant' | 41 | ("Kobe Bryant" : player {age : 40, name : "Kobe Bryant"}) |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 | ("Dirk Nowitzki" : player {age : 40, name : "Dirk Nowitzki"}) |

Scenario: [1] tag with yield rename
When executing query:
Expand All @@ -22,6 +38,15 @@ Feature: Lookup with yield in integer vid
| VertexID | name |
| 'Kobe Bryant' | 'Kobe Bryant' |
| 'Dirk Nowitzki' | 'Dirk Nowitzki' |
When executing query:
"""
LOOKUP ON team WHERE team.name in ["76ers", "Lakers", "Spurs"] YIELD vertex AS node
"""
Then the result should be, in any order, and the columns 0 should be hashed:
| VertexID | node |
| '76ers' | ("76ers" : team {name : "76ers"}) |
| 'Lakers' | ("Lakers" : team {name : "Lakers"}) |
| 'Spurs' | ("Spurs" : team {name : "Spurs"}) |

Scenario: [2] edge with yield
When executing query:
Expand All @@ -33,6 +58,15 @@ Feature: Lookup with yield in integer vid
| SrcVID | DstVID | Ranking | serve.start_year |
| 'Russell Westbrook' | 'Thunders' | 0 | 2008 |
| 'Marc Gasol' | 'Grizzlies' | 0 | 2008 |
When executing query:
"""
LOOKUP ON serve WHERE serve.start_year == 2008 and serve.end_year == 2019
YIELD serve.start_year, edge as relationship
"""
Then the result should be, in any order, and the columns 0,1 should be hashed:
| SrcVID | DstVID | Ranking | serve.start_year | relationship |
| 'Russell Westbrook' | 'Thunders' | 0 | 2008 | [:serve "Russell Westbrook"->"Thunders" @0 {end_year: 2019, start_year: 2008}] |
| 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | [:serve "Marc Gasol"->"Grizzlies" @0 {end_year: 2019, start_year: 2008}] |

Scenario: [2] edge with yield rename
When executing query:
Expand All @@ -44,3 +78,15 @@ Feature: Lookup with yield in integer vid
| SrcVID | DstVID | Ranking | startYear |
| 'Russell Westbrook' | 'Thunders' | 0 | 2008 |
| 'Marc Gasol' | 'Grizzlies' | 0 | 2008 |
When executing query:
"""
LOOKUP ON like WHERE like.likeness < 50 + 1 YIELD like.likeness, edge as relationship
"""
Then the result should be, in any order, and the columns 0,1 should be hashed:
| SrcVID | DstVID | Ranking | like.likeness | relationship |
| "Blake Griffin" | "Chris Paul" | 0 | -1 | [:like "Blake Griffin"->"Chris Paul" @0 {likeness: -1}] |
| "Dirk Nowitzki" | "Dwyane Wade" | 0 | 10 | [:like "Dirk Nowitzki"->"Dwyane Wade" @0 {likeness: 10}] |
| "Kyrie Irving" | "LeBron James" | 0 | 13 | [:like "Kyrie Irving"->"LeBron James" @0 {likeness: 13}] |
| "Marco Belinelli" | "Tony Parker" | 0 | 50 | [:like "Marco Belinelli"->"Tony Parker" @0 {likeness: 50}] |
| "Rajon Rondo" | "Ray Allen" | 0 | -1 | [:like "Rajon Rondo"->"Ray Allen" @0 {likeness: -1}] |
| "Ray Allen" | "Rajon Rondo" | 0 | 9 | [:like "Ray Allen"->"Rajon Rondo" @0 {likeness: 9}] |

0 comments on commit 2dfa9ba

Please sign in to comment.