Skip to content

Commit 48fb25e

Browse files
authored
[BugFix][C++] Check is not nullptr before calling ToString and fix empty prefix bug (#339)
Signed-off-by: acezen <qiaozi.zwb@alibaba-inc.com>
1 parent e8a304d commit 48fb25e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

cpp/include/gar/fwd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ std::shared_ptr<EdgeInfo> CreateEdgeInfo(
114114

115115
std::shared_ptr<GraphInfo> CreateGraphInfo(
116116
const std::string& name, const VertexInfoVector& vertex_infos,
117-
const EdgeInfoVector& edge_infos, const std::string& prefix = "",
117+
const EdgeInfoVector& edge_infos, const std::string& prefix,
118118
std::shared_ptr<const InfoVersion> version = nullptr);
119119

120120
const std::shared_ptr<DataType>& boolean();

cpp/src/graph_info.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class VertexInfo::Impl {
176176
property_groups_(std::move(property_groups)),
177177
prefix_(prefix),
178178
version_(std::move(version)) {
179+
if (prefix_.empty()) {
180+
prefix_ = label_ + "/"; // default prefix
181+
}
179182
for (int i = 0; i < property_groups_.size(); i++) {
180183
const auto& pg = property_groups_[i];
181184
for (const auto& p : pg->GetProperties()) {
@@ -872,7 +875,9 @@ Result<std::string> EdgeInfo::Dump() const noexcept {
872875
node["property_groups"].PushBack();
873876
node["property_groups"][node["property_groups"].Size() - 1] = pg_node;
874877
}
875-
node["version"] = impl_->version_->ToString();
878+
if (impl_->version_ != nullptr) {
879+
node["version"] = impl_->version_->ToString();
880+
}
876881
std::string dump_string;
877882
::Yaml::Serialize(node, dump_string);
878883
return dump_string;

cpp/test/test_info.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ TEST_CASE("VertexInfo") {
225225
auto invalid_vertex_info2 =
226226
CreateVertexInfo(label, 0, {pg}, "test_vertex/", version);
227227
REQUIRE(invalid_vertex_info2->IsValidated() == false);
228+
// check if prefix empty
229+
auto vertex_info_empty_prefix =
230+
CreateVertexInfo(label, chunk_size, {pg}, "", version);
231+
REQUIRE(vertex_info_empty_prefix->IsValidated() == true);
228232
}
229233

230234
SECTION("Dump") {
@@ -246,6 +250,9 @@ prefix: test_vertex
246250
version: gar/v1
247251
)";
248252
REQUIRE(dump_result.value() == expected);
253+
auto vertex_info_empty_version =
254+
CreateVertexInfo(label, chunk_size, {pg}, "test_vertex/");
255+
REQUIRE(vertex_info_empty_version->Dump().status().ok());
249256
}
250257

251258
SECTION("AddPropertyGroup") {
@@ -377,6 +384,11 @@ TEST_CASE("EdgeInfo") {
377384
src_label, edge_label, dst_label, chunk_size, src_chunk_size, 0,
378385
directed, {adj_list}, {pg}, "test_edge/", version);
379386
REQUIRE(invalid_edge_info6->IsValidated() == false);
387+
// check if prefix empty
388+
auto edge_info_with_empty_prefix = CreateEdgeInfo(
389+
src_label, edge_label, dst_label, chunk_size, src_chunk_size,
390+
dst_chunk_size, directed, {adj_list}, {pg}, "", version);
391+
REQUIRE(edge_info_with_empty_prefix->IsValidated() == true);
380392
}
381393

382394
SECTION("Dump") {
@@ -408,6 +420,10 @@ src_label: person
408420
version: gar/v1
409421
)";
410422
REQUIRE(dump_result.value() == expected);
423+
auto edge_info_empty_version =
424+
CreateEdgeInfo(src_label, edge_label, dst_label, chunk_size,
425+
src_chunk_size, dst_chunk_size, directed, {}, {});
426+
REQUIRE(edge_info_empty_version->Dump().status().ok());
411427
}
412428

413429
SECTION("AddAdjacentList") {
@@ -512,6 +528,10 @@ TEST_CASE("GraphInfo") {
512528
auto invalid_graph_info3 =
513529
CreateGraphInfo(name, {vertex_info}, {edge_info}, "", version);
514530
REQUIRE(invalid_graph_info3->IsValidated() == false);
531+
// check if prefix empty, graph_info with empty prefix is invalid
532+
auto graph_info_with_empty_prefix =
533+
CreateGraphInfo(name, {vertex_info}, {edge_info}, "", version);
534+
REQUIRE(graph_info_with_empty_prefix->IsValidated() == false);
515535
}
516536

517537
SECTION("Dump") {
@@ -526,6 +546,9 @@ version: gar/v1
526546
- test_vertex.vertex.yaml
527547
)";
528548
REQUIRE(dump_result.value() == expected);
549+
auto graph_info_empty_version =
550+
CreateGraphInfo(name, {vertex_info}, {edge_info}, "test_graph/");
551+
REQUIRE(graph_info_empty_version->Dump().status().ok());
529552
}
530553

531554
SECTION("AddVertex") {

0 commit comments

Comments
 (0)