Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix][C++] Check is not nullptr before calling ToString and fix empty prefix bug #339

Merged
merged 5 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/include/gar/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::shared_ptr<EdgeInfo> CreateEdgeInfo(

std::shared_ptr<GraphInfo> CreateGraphInfo(
const std::string& name, const VertexInfoVector& vertex_infos,
const EdgeInfoVector& edge_infos, const std::string& prefix = "",
const EdgeInfoVector& edge_infos, const std::string& prefix,
std::shared_ptr<const InfoVersion> version = nullptr);

const std::shared_ptr<DataType>& boolean();
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/graph_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class VertexInfo::Impl {
property_groups_(std::move(property_groups)),
prefix_(prefix),
version_(std::move(version)) {
if (prefix_.empty()) {
prefix_ = label_ + "/"; // default prefix
}
for (int i = 0; i < property_groups_.size(); i++) {
const auto& pg = property_groups_[i];
for (const auto& p : pg->GetProperties()) {
Expand Down Expand Up @@ -872,7 +875,9 @@ Result<std::string> EdgeInfo::Dump() const noexcept {
node["property_groups"].PushBack();
node["property_groups"][node["property_groups"].Size() - 1] = pg_node;
}
node["version"] = impl_->version_->ToString();
if (impl_->version_ != nullptr) {
node["version"] = impl_->version_->ToString();
}
std::string dump_string;
::Yaml::Serialize(node, dump_string);
return dump_string;
Expand Down
23 changes: 23 additions & 0 deletions cpp/test/test_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ TEST_CASE("VertexInfo") {
auto invalid_vertex_info2 =
CreateVertexInfo(label, 0, {pg}, "test_vertex/", version);
REQUIRE(invalid_vertex_info2->IsValidated() == false);
// check if prefix empty
auto vertex_info_empty_prefix =
CreateVertexInfo(label, chunk_size, {pg}, "", version);
REQUIRE(vertex_info_empty_prefix->IsValidated() == true);
}

SECTION("Dump") {
Expand All @@ -246,6 +250,9 @@ prefix: test_vertex
version: gar/v1
)";
REQUIRE(dump_result.value() == expected);
auto vertex_info_empty_version =
CreateVertexInfo(label, chunk_size, {pg}, "test_vertex/");
REQUIRE(vertex_info_empty_version->Dump().status().ok());
}

SECTION("AddPropertyGroup") {
Expand Down Expand Up @@ -377,6 +384,11 @@ TEST_CASE("EdgeInfo") {
src_label, edge_label, dst_label, chunk_size, src_chunk_size, 0,
directed, {adj_list}, {pg}, "test_edge/", version);
REQUIRE(invalid_edge_info6->IsValidated() == false);
// check if prefix empty
auto edge_info_with_empty_prefix = CreateEdgeInfo(
src_label, edge_label, dst_label, chunk_size, src_chunk_size,
dst_chunk_size, directed, {adj_list}, {pg}, "", version);
REQUIRE(edge_info_with_empty_prefix->IsValidated() == true);
}

SECTION("Dump") {
Expand Down Expand Up @@ -408,6 +420,10 @@ src_label: person
version: gar/v1
)";
REQUIRE(dump_result.value() == expected);
auto edge_info_empty_version =
CreateEdgeInfo(src_label, edge_label, dst_label, chunk_size,
src_chunk_size, dst_chunk_size, directed, {}, {});
REQUIRE(edge_info_empty_version->Dump().status().ok());
}

SECTION("AddAdjacentList") {
Expand Down Expand Up @@ -512,6 +528,10 @@ TEST_CASE("GraphInfo") {
auto invalid_graph_info3 =
CreateGraphInfo(name, {vertex_info}, {edge_info}, "", version);
REQUIRE(invalid_graph_info3->IsValidated() == false);
// check if prefix empty, graph_info with empty prefix is invalid
auto graph_info_with_empty_prefix =
CreateGraphInfo(name, {vertex_info}, {edge_info}, "", version);
REQUIRE(graph_info_with_empty_prefix->IsValidated() == false);
}

SECTION("Dump") {
Expand All @@ -526,6 +546,9 @@ version: gar/v1
- test_vertex.vertex.yaml
)";
REQUIRE(dump_result.value() == expected);
auto graph_info_empty_version =
CreateGraphInfo(name, {vertex_info}, {edge_info}, "test_graph/");
REQUIRE(graph_info_empty_version->Dump().status().ok());
}

SECTION("AddVertex") {
Expand Down
Loading