diff --git a/src/graph/ReturnExecutor.cpp b/src/graph/ReturnExecutor.cpp index 5fa1c0c3626..be8c4fb37b3 100644 --- a/src/graph/ReturnExecutor.cpp +++ b/src/graph/ReturnExecutor.cpp @@ -20,6 +20,7 @@ Status ReturnExecutor::prepare() { } void ReturnExecutor::execute() { + FLOG_INFO("Executing Return: %s", sentence_->toString().c_str()); DCHECK(onFinish_); DCHECK(onError_); DCHECK(sentence_); @@ -57,7 +58,13 @@ void ReturnExecutor::execute() { onError_(std::move(ret).status()); return; } + auto rows = ret.value(); + if (rows.empty()) { + onFinish_(Executor::ProcessControl::kNext); + return; + } resp_->set_rows(std::move(ret).value()); + // Will return if variable has values. onFinish_(Executor::ProcessControl::kReturn); } } diff --git a/src/graph/SequentialExecutor.cpp b/src/graph/SequentialExecutor.cpp index 123bd7671e3..9071daeef0b 100644 --- a/src/graph/SequentialExecutor.cpp +++ b/src/graph/SequentialExecutor.cpp @@ -51,6 +51,7 @@ Status SequentialExecutor::prepare() { DCHECK(onFinish_); respExecutorIndex_ = current; onFinish_(ctr); + break; } case Executor::ProcessControl::kNext: default: { diff --git a/src/graph/test/GoTest.cpp b/src/graph/test/GoTest.cpp index e55e249038d..1642abf3a87 100644 --- a/src/graph/test/GoTest.cpp +++ b/src/graph/test/GoTest.cpp @@ -761,5 +761,51 @@ TEST_F(GoTest, is_inCall) { ASSERT_TRUE(verifyResult(resp, expected)); } } + +TEST_F(GoTest, returnTest) { + { + cpp2::ExecutionResponse resp; + auto *fmt = "$A = GO FROM %ld OVER like YIELD like._dst AS dst;" + "$rA = YIELD $A.* WHERE $A.dst == 123;" + "RETURN $rA IF $rA IS NOT NULL;" + "GO FROM $A.dst OVER serve"; + auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid()); + auto code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"serve._dst"} + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {teams_["Spurs"].vid()}, + {teams_["Spurs"].vid()}, + {teams_["Hornets"].vid()}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + auto *fmt = "$A = GO FROM %ld OVER like YIELD like._dst AS dst;" + "$rA = YIELD $A.* WHERE 1 == 1;" + "RETURN $rA IF $rA IS NOT NULL;" + "GO FROM $A.dst OVER serve"; + auto query = folly::stringPrintf(fmt, players_["Tim Duncan"].vid()); + auto code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"$A.dst"} + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {players_["Tony Parker"].vid()}, + {players_["Manu Ginobili"].vid()}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } +} } // namespace graph } // namespace nebula