This is an automated email from the ASF dual-hosted git repository.
weibin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git
The following commit(s) were added to refs/heads/main by this push:
new d2e81964 fix(c++): return nullptr at GetChunk if there is no edge in
chunk (#550)
d2e81964 is described below
commit d2e8196443bb62155fe55e47752d8e259f7c4ba7
Author: Weibin Zeng <[email protected]>
AuthorDate: Thu Jul 25 11:18:40 2024 +0800
fix(c++): return nullptr at GetChunk if there is no edge in chunk (#550)
Signed-off-by: acezen <[email protected]>
---
cpp/src/graphar/arrow/chunk_reader.cc | 14 ++++++++++++++
cpp/src/graphar/arrow/chunk_reader.h | 4 ++--
cpp/test/test_arrow_chunk_reader.cc | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/cpp/src/graphar/arrow/chunk_reader.cc
b/cpp/src/graphar/arrow/chunk_reader.cc
index 099d451b..edb07ce1 100644
--- a/cpp/src/graphar/arrow/chunk_reader.cc
+++ b/cpp/src/graphar/arrow/chunk_reader.cc
@@ -368,6 +368,13 @@ Status AdjListArrowChunkReader::seek(IdType offset) {
Result<std::shared_ptr<arrow::Table>> AdjListArrowChunkReader::GetChunk() {
if (chunk_table_ == nullptr) {
+ // check if the edge num of the current vertex chunk is 0
+ GAR_ASSIGN_OR_RAISE(auto edge_num,
+ util::GetEdgeNum(prefix_, edge_info_, adj_list_type_,
+ vertex_chunk_index_));
+ if (edge_num == 0) {
+ return nullptr;
+ }
GAR_ASSIGN_OR_RAISE(auto chunk_file_path,
edge_info_->GetAdjListFilePath(
vertex_chunk_index_, chunk_index_,
adj_list_type_));
@@ -691,6 +698,13 @@ Result<std::shared_ptr<arrow::Table>>
AdjListPropertyArrowChunkReader::GetChunk() {
GAR_RETURN_NOT_OK(util::CheckFilterOptions(filter_options_,
property_group_));
if (chunk_table_ == nullptr) {
+ // check if the edge num of the current vertex chunk is 0
+ GAR_ASSIGN_OR_RAISE(auto edge_num,
+ util::GetEdgeNum(prefix_, edge_info_, adj_list_type_,
+ vertex_chunk_index_));
+ if (edge_num == 0) {
+ return nullptr;
+ }
GAR_ASSIGN_OR_RAISE(
auto chunk_file_path,
edge_info_->GetPropertyFilePath(property_group_, adj_list_type_,
diff --git a/cpp/src/graphar/arrow/chunk_reader.h
b/cpp/src/graphar/arrow/chunk_reader.h
index 89818319..cff103ee 100644
--- a/cpp/src/graphar/arrow/chunk_reader.h
+++ b/cpp/src/graphar/arrow/chunk_reader.h
@@ -198,7 +198,7 @@ class AdjListArrowChunkReader {
/**
* @brief Return the current chunk of chunk position indicator as
- * arrow::Table
+ * arrow::Table, if the chunk is empty, return nullptr.
*/
Result<std::shared_ptr<arrow::Table>> GetChunk();
@@ -400,7 +400,7 @@ class AdjListPropertyArrowChunkReader {
/**
* @brief Return the current chunk of chunk position indicator as
- * arrow::Table
+ * arrow::Table, if the chunk is empty, return nullptr.
*/
Result<std::shared_ptr<arrow::Table>> GetChunk();
diff --git a/cpp/test/test_arrow_chunk_reader.cc
b/cpp/test/test_arrow_chunk_reader.cc
index a96c9d06..3e62d4fb 100644
--- a/cpp/test/test_arrow_chunk_reader.cc
+++ b/cpp/test/test_arrow_chunk_reader.cc
@@ -458,6 +458,41 @@ TEST_CASE_METHOD(GlobalFixture, "ArrowChunkReader") {
}
}
+TEST_CASE_METHOD(GlobalFixture, "EmptyChunkTest") {
+ // read file and construct graph info
+ std::string path = test_data_dir + "/neo4j/MovieGraph.graph.yml";
+ std::string src_label = "Person", edge_label = "REVIEWED",
+ dst_label = "Movie";
+ std::string edge_property_name = "rating";
+ auto maybe_graph_info = GraphInfo::Load(path);
+ REQUIRE(maybe_graph_info.status().ok());
+ auto graph_info = maybe_graph_info.value();
+
+ SECTION("AdjListArrowChunkReader") {
+ auto maybe_reader = AdjListArrowChunkReader::Make(
+ graph_info, src_label, edge_label, dst_label,
+ AdjListType::ordered_by_source);
+ REQUIRE(maybe_reader.status().ok());
+ auto reader = maybe_reader.value();
+ auto result = reader->GetChunk();
+ REQUIRE(!result.has_error());
+ // the edge chunk is empty, should return nullptr
+ REQUIRE(result.value() == nullptr);
+ }
+
+ SECTION("AdjListPropertyArrowChunkReader") {
+ auto maybe_reader = AdjListPropertyArrowChunkReader::Make(
+ graph_info, src_label, edge_label, dst_label, edge_property_name,
+ AdjListType::ordered_by_source);
+ REQUIRE(maybe_reader.status().ok());
+ auto reader = maybe_reader.value();
+ auto result = reader->GetChunk();
+ REQUIRE(!result.has_error());
+ // the edge chunk is empty, should return nullptr
+ REQUIRE(result.value() == nullptr);
+ }
+}
+
TEST_CASE_METHOD(GlobalFixture, "JSON_TEST") {
// read file and construct graph info
std::string path = test_data_dir + "/ldbc_sample/json/LdbcSample.graph.yml";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]