Skip to content

Commit

Permalink
fix limit/offset (vesoft-inc#2428)
Browse files Browse the repository at this point in the history
Co-authored-by: dutor <[email protected]>
  • Loading branch information
czpmango and dutor authored Jan 6, 2021
1 parent 8a59997 commit 46f4a5f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/graph/test/GoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ TEST_P(GoTest, OneStepOutBound) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto &player = players_["Boris Diaw"];
auto *fmt = "GO FROM %ld OVER serve YIELD "
"$^.player.name, serve.start_year, serve.end_year, $$.team.name"
" | LIMIT 1 OFFSET 2";
auto query = folly::stringPrintf(fmt, player.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);

std::vector<std::string> expectedColNames{
{"$^.player.name"}, {"serve.start_year"}, {"serve.end_year"}, {"$$.team.name"}
};
ASSERT_TRUE(verifyColNames(resp, expectedColNames));

std::vector<std::tuple<std::string, int64_t, int64_t, std::string>> expected = {
{player.name(), 2012, 2016, "Spurs"},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto &player = players_["Rajon Rondo"];
Expand Down
7 changes: 3 additions & 4 deletions src/graph/test/GroupByLimitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,18 @@ TEST_F(GroupByLimitTest, LimitTest) {
cpp2::ExecutionResponse resp;
auto &player = players_["Marco Belinelli"];
auto *fmt = "GO FROM %ld OVER serve YIELD $$.team.name AS name | "
"ORDER BY $-.name | LIMIT 2,2";
"ORDER BY $-.name | LIMIT 2,1";
auto query = folly::stringPrintf(fmt, player.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<std::string>> expected = {
{"Hawks"},
{"Hornets"},
};
ASSERT_TRUE(verifyResult(resp, expected, false));

// use OFFSET
auto *fmt1 = "GO FROM %ld OVER serve YIELD $$.team.name AS name | "
"ORDER BY $-.name | LIMIT 2 OFFSET 2";
"ORDER BY $-.name | LIMIT 1 OFFSET 2";
query = folly::stringPrintf(fmt1, player.vid());
code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
Expand All @@ -232,7 +231,7 @@ TEST_F(GroupByLimitTest, LimitTest) {
{
cpp2::ExecutionResponse resp;
auto &player = players_["Danny Green"];
auto *fmt = "GO FROM %ld OVER serve YIELD $$.team.name AS name | LIMIT 1 OFFSET 0";
auto *fmt = "GO FROM %ld OVER serve YIELD $$.team.name AS name | LIMIT 0 OFFSET 1";
auto query = folly::stringPrintf(fmt, player.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ limit_sentence
| KW_LIMIT INTEGER KW_OFFSET INTEGER {
ifOutOfRange($2, @2);
ifOutOfRange($4, @4);
$$ = new LimitSentence($2, $4);
$$ = new LimitSentence($4, $2);
}
;

Expand Down

0 comments on commit 46f4a5f

Please sign in to comment.