Skip to content

Commit

Permalink
Correct/fetch empty props (vesoft-inc#1491)
Browse files Browse the repository at this point in the history
* Fix vesoft-inc#1478
Return empty set when input empty properties.

* Add the when accept input.

* Move testing to DataTest.

Co-authored-by: dutor <440396+dutor@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and dutor committed Dec 26, 2019
1 parent f834847 commit 8213868
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/graph/FetchEdgesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ void FetchEdgesExecutor::fetchEdges() {
}

if (props.empty()) {
doError(Status::Error("No props declared."));
LOG(WARNING) << "Empty props of tag " << labelName_;
doEmptyResp();
return;
}

Expand Down
8 changes: 8 additions & 0 deletions src/graph/FetchExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,13 @@ void FetchExecutor::finishExecution(std::unique_ptr<RowSetWriter> rsWriter) {
}
doFinish(Executor::ProcessControl::kNext);
}

void FetchExecutor::doEmptyResp() {
resp_ = std::make_unique<cpp2::ExecutionResponse>();
resp_->set_column_names(std::vector<std::string>());
resp_->set_rows(std::vector<cpp2::RowValue>());
doFinish(Executor::ProcessControl::kNext);
}

} // namespace graph
} // namespace nebula
2 changes: 1 addition & 1 deletion src/graph/FetchExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FetchExecutor : public TraverseExecutor {

void finishExecution(std::unique_ptr<RowSetWriter> rsWriter);

stats::Stats* getStats() const;
void doEmptyResp();

protected:
GraphSpaceID spaceId_{INT_MIN};
Expand Down
7 changes: 6 additions & 1 deletion src/graph/FetchVerticesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Status FetchVerticesExecutor::prepareClauses() {
labelName_ = sentence_->tag();
auto result = ectx()->schemaManager()->toTagID(spaceId_, *labelName_);
if (!result.ok()) {
LOG(ERROR) << "Get Tag Id failed: " << result.status();
status = result.status();
break;
}
Expand All @@ -50,10 +51,12 @@ Status FetchVerticesExecutor::prepareClauses() {

status = prepareVids();
if (!status.ok()) {
LOG(ERROR) << "Prepare vertex id failed: " << status;
break;
}
status = prepareYield();
if (!status.ok()) {
LOG(ERROR) << "Prepare yield failed: " << status;
break;
}
} while (false);
Expand Down Expand Up @@ -97,6 +100,7 @@ void FetchVerticesExecutor::execute() {
return;
}
if (vids_.empty()) {
LOG(WARNING) << "Empty vids";
onEmptyInputs();
return;
}
Expand All @@ -107,7 +111,8 @@ void FetchVerticesExecutor::execute() {
void FetchVerticesExecutor::fetchVertices() {
auto props = getPropNames();
if (props.empty()) {
doError(Status::Error("No props declared."));
LOG(WARNING) << "Empty props";
doEmptyResp();
return;
}

Expand Down
90 changes: 90 additions & 0 deletions src/graph/test/DataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,5 +985,95 @@ TEST_F(DataTest, MatchTest) {
}
}


static inline void execute(GraphClient* client, const std::string& nGQL) {
cpp2::ExecutionResponse resp;
auto code = client->execute(nGQL, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << "Do cmd:" << nGQL << " failed";
}

class FetchEmptyPropsTest : public ::testing::Test {
protected:
void SetUp() override {
// Access the Nebula Environment
client_ = gEnv->getClient();
ASSERT_NE(client_, nullptr);

prepareSchema();
prepareData();
}

void TearDown() override {
execute(client_.get(), "DROP SPACE empty");
}

std::unique_ptr<GraphClient> client_ = nullptr;

private:
void prepareSchema() {
execute(client_.get(), "CREATE SPACE empty(partition_num=1, replica_factor=1)");

const std::vector<std::string> queries = {
"USE empty",
"CREATE TAG empty_tag()",
"CREATE EDGE empty_edge()"
};

for (auto& q : queries) {
execute(client_.get(), q);
}

sleep(FLAGS_load_data_interval_secs + 3);
}

void prepareData() {
const std::vector<std::string> queries = {
"INSERT VERTEX empty_tag() values 1:(), 2:()",
"INSERT EDGE empty_edge() values 1->2:()",
};

for (auto& q : queries) {
execute(client_.get(), q);
}
}
};

static inline void assertEmptyResult(GraphClient* client, const std::string& stmt) {
cpp2::ExecutionResponse resp;
auto code = DCHECK_NOTNULL(client)->execute(stmt, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
ASSERT_NE(resp.get_column_names(), nullptr);
ASSERT_TRUE(resp.get_column_names()->empty());
ASSERT_NE(resp.get_rows(), nullptr);
ASSERT_TRUE(resp.get_rows()->empty());
}

// #1478
// Fetch property from empty tag
TEST_F(FetchEmptyPropsTest, EmptyProps) {
{
const std::string stmt = "FETCH PROP ON empty_tag 1";
assertEmptyResult(client_.get(), stmt);
}
{
const std::string stmt = "FETCH PROP ON empty_edge 1->2";
assertEmptyResult(client_.get(), stmt);
}
}

TEST_F(FetchEmptyPropsTest, WithInput) {
{
const std::string stmt = "GO FROM 1 OVER empty_edge YIELD empty_edge._dst as id"
" | FETCH PROP ON empty_tag $-.id";
assertEmptyResult(client_.get(), stmt);
}
{
const std::string stmt =
"GO FROM 1 OVER empty_edge YIELD empty_edge._src as src, empty_edge._dst as dst"
" | FETCH PROP ON empty_edge $-.src->$-.dst";
assertEmptyResult(client_.get(), stmt);
}
}

} // namespace graph
} // namespace nebula

0 comments on commit 8213868

Please sign in to comment.