Skip to content

Commit

Permalink
Fixed bug on variable reference (vesoft-inc#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
dutor authored Jul 12, 2019
1 parent c6d3d76 commit 4954b21
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
14 changes: 8 additions & 6 deletions src/graph/AssignmentExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ Status AssignmentExecutor::prepare() {

var_ = sentence_->var();
executor_ = TraverseExecutor::makeTraverseExecutor(sentence_->sentence(), ectx());
status = executor_->prepare();
if (!status.ok()) {
FLOG_ERROR("Prepare executor `%s' failed: %s",
executor_->name(), status.toString().c_str());
return status;
}

auto onError = [this] (Status s) {
DCHECK(onError_);
onError_(std::move(s));
Expand All @@ -48,6 +43,13 @@ Status AssignmentExecutor::prepare() {
executor_->setOnFinish(onFinish);
executor_->setOnResult(onResult);

status = executor_->prepare();
if (!status.ok()) {
FLOG_ERROR("Prepare executor `%s' failed: %s",
executor_->name(), status.toString().c_str());
return status;
}

return Status::OK();
}

Expand Down
26 changes: 11 additions & 15 deletions src/graph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ set(GRAPH_TEST_LIBS
$<TARGET_OBJECTS:thrift_obj>
)

add_library(graph_test_common_obj OBJECT
TestMain.cpp
TestEnv.cpp
TestBase.cpp
)


add_executable(
session_manager_test
Expand All @@ -43,11 +49,9 @@ nebula_add_test(session_manager_test)

add_executable(
query_engine_test
TestMain.cpp
TestEnv.cpp
TestBase.cpp
YieldTest.cpp
SchemaTest.cpp
$<TARGET_OBJECTS:graph_test_common_obj>
$<TARGET_OBJECTS:client_cpp_obj>
$<TARGET_OBJECTS:adHocSchema_obj>
${GRAPH_TEST_LIBS}
Expand All @@ -64,10 +68,8 @@ nebula_add_test(query_engine_test)

add_executable(
go_test
TestMain.cpp
TestEnv.cpp
TestBase.cpp
GoTest.cpp
$<TARGET_OBJECTS:graph_test_common_obj>
$<TARGET_OBJECTS:client_cpp_obj>
$<TARGET_OBJECTS:adHocSchema_obj>
${GRAPH_TEST_LIBS}
Expand All @@ -84,10 +86,8 @@ nebula_add_test(go_test)

add_executable(
graph_http_test
TestMain.cpp
TestEnv.cpp
TestBase.cpp
GraphHttpHandlerTest.cpp
$<TARGET_OBJECTS:graph_test_common_obj>
$<TARGET_OBJECTS:graph_http_handler>
$<TARGET_OBJECTS:client_cpp_obj>
$<TARGET_OBJECTS:ws_obj>
Expand All @@ -109,10 +109,8 @@ nebula_add_test(graph_http_test)

add_executable(
data_test
TestMain.cpp
TestEnv.cpp
TestBase.cpp
DataTest.cpp
$<TARGET_OBJECTS:graph_test_common_obj>
$<TARGET_OBJECTS:client_cpp_obj>
$<TARGET_OBJECTS:adHocSchema_obj>
${GRAPH_TEST_LIBS}
Expand All @@ -128,10 +126,8 @@ nebula_add_test(data_test)

add_executable(
order_by_test
TestMain.cpp
TestEnv.cpp
TestBase.cpp
OrderByTest.cpp
$<TARGET_OBJECTS:graph_test_common_obj>
$<TARGET_OBJECTS:client_cpp_obj>
$<TARGET_OBJECTS:adHocSchema_obj>
${GRAPH_TEST_LIBS}
Expand Down
37 changes: 37 additions & 0 deletions src/graph/test/GoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,43 @@ TEST_F(GoTest, OneStepOutBound) {
}
}


TEST_F(GoTest, AssignmentSimple) {
{
cpp2::ExecutionResponse resp;
auto &player = players_["Tracy McGrady"];
auto *fmt = "$var = GO FROM %ld OVER like; "
"GO FROM $var.id OVER like";
auto query = folly::stringPrintf(fmt, player.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<uint64_t>> expected = {
{players_["Kobe Bryant"].vid()},
{players_["Grant Hill"].vid()},
{players_["Rudy Gay"].vid()},
};
}
}


TEST_F(GoTest, AssignmentPipe) {
{
cpp2::ExecutionResponse resp;
auto &player = players_["Tracy McGrady"];
auto *fmt = "$var = (GO FROM %ld OVER like | GO FROM $- OVER like);"
"GO FROM $var OVER like";
auto query = folly::stringPrintf(fmt, player.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::tuple<uint64_t>> expected = {
{players_["Kobe Bryant"].vid()},
{players_["Grant Hill"].vid()},
{players_["Tony Parker"].vid()},
{players_["Tim Duncan"].vid()},
};
}
}

// REVERSELY not supported yet
TEST_F(GoTest, DISABLED_OneStepInBound) {
{
Expand Down
3 changes: 3 additions & 0 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ var_ref_expression
: VARIABLE DOT LABEL {
$$ = new VariablePropertyExpression($1, $3);
}
| VARIABLE {
$$ = new VariablePropertyExpression($1, new std::string("id"));
}
;

alias_ref_expression
Expand Down

0 comments on commit 4954b21

Please sign in to comment.