This is an automated email from the ASF dual-hosted git repository.
xiaokang 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 284fd445 fix(c++): replace assert with SkipWithError in benchmarks
(#794)
284fd445 is described below
commit 284fd44581a7ef2e28ba90a39806ffd1164e9f79
Author: Xiaokang Yang <[email protected]>
AuthorDate: Fri Oct 17 10:53:55 2025 +0800
fix(c++): replace assert with SkipWithError in benchmarks (#794)
* change assert to ASSERT
* remove assert
* replace assert with skipWithError in benchmarks
* replace assert with skipWithError in benchmarks
---
cpp/benchmarks/arrow_chunk_reader_benchmark.cc | 231 ++++++++++++-------------
cpp/benchmarks/benchmark_util.h | 6 +
cpp/benchmarks/graph_info_benchmark.cc | 5 +-
cpp/src/graphar/high-level/vertices_builder.h | 4 +-
4 files changed, 119 insertions(+), 127 deletions(-)
diff --git a/cpp/benchmarks/arrow_chunk_reader_benchmark.cc
b/cpp/benchmarks/arrow_chunk_reader_benchmark.cc
index 24fd4fc3..3f8e7fd7 100644
--- a/cpp/benchmarks/arrow_chunk_reader_benchmark.cc
+++ b/cpp/benchmarks/arrow_chunk_reader_benchmark.cc
@@ -32,10 +32,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
CreateVertexPropertyArrowChunkReader)
graph_info_->GetVertexInfo("person")->GetPropertyGroup("firstName");
auto maybe_reader =
VertexPropertyArrowChunkReader::Make(graph_info_, "person", gp);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
}
}
@@ -45,10 +42,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
CreateAdjListArrowChunkReader)
auto maybe_reader =
AdjListArrowChunkReader::Make(graph_info_, "person", "knows", "person",
AdjListType::ordered_by_source);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
}
}
@@ -58,10 +52,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
CreateAdjListOffsetArrowChunkReader)
auto maybe_reader = AdjListOffsetArrowChunkReader::Make(
graph_info_, "person", "knows", "person",
AdjListType::ordered_by_source);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
}
}
@@ -71,10 +62,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
CreateAdjListPropertyArrowChunkReader)
auto maybe_reader = AdjListPropertyArrowChunkReader::Make(
graph_info_, "person", "knows", "person", "creationDate",
AdjListType::ordered_by_source);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
}
}
@@ -82,15 +70,15 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
AdjListArrowChunkReaderReadChunk)
(::benchmark::State& state) { // NOLINT
auto maybe_reader = AdjListArrowChunkReader::Make(
graph_info_, "person", "knows", "person",
AdjListType::ordered_by_source);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk().status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk();
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -98,15 +86,15 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
AdjListOffsetArrowChunkReaderReadChunk)
(::benchmark::State& state) { // NOLINT
auto maybe_reader = AdjListOffsetArrowChunkReader::Make(
graph_info_, "person", "knows", "person",
AdjListType::ordered_by_source);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk().status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk();
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -115,15 +103,15 @@ BENCHMARK_DEFINE_F(BenchmarkFixture,
AdjListPropertyArrowChunkReaderReadChunk)
auto maybe_reader = AdjListPropertyArrowChunkReader::Make(
graph_info_, "person", "knows", "person", "creationDate",
AdjListType::ordered_by_source);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk().status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk();
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -134,15 +122,15 @@ BENCHMARK_DEFINE_F(
auto gp =
graph_info_->GetVertexInfo("person")->GetPropertyGroup("firstName");
auto maybe_reader =
VertexPropertyArrowChunkReader::Make(graph_info_, "person", gp);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V1).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V1);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
// select one columns and internal ID column
@@ -152,15 +140,15 @@ BENCHMARK_DEFINE_F(
(::benchmark::State& state) { // NOLINT
auto maybe_reader =
VertexPropertyArrowChunkReader::Make(graph_info_, "person", "firstName");
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V1).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V1);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -171,15 +159,15 @@ BENCHMARK_DEFINE_F(
(::benchmark::State& state) { // NOLINT
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
graph_info_, "person", {"firstName", "lastName"},
SelectType::PROPERTIES);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V1).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V1);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -190,15 +178,15 @@ BENCHMARK_DEFINE_F(
auto gp =
graph_info_->GetVertexInfo("person")->GetPropertyGroup("firstName");
auto maybe_reader =
VertexPropertyArrowChunkReader::Make(graph_info_, "person", gp);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V2).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V2);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
// select one columns and internal ID column
@@ -208,15 +196,15 @@ BENCHMARK_DEFINE_F(
(::benchmark::State& state) { // NOLINT
auto maybe_reader =
VertexPropertyArrowChunkReader::Make(graph_info_, "person", "firstName");
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V2).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V2);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -227,15 +215,15 @@ BENCHMARK_DEFINE_F(
(::benchmark::State& state) { // NOLINT
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
graph_info_, "person", {"firstName", "lastName"},
SelectType::PROPERTIES);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V2).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V2);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -247,15 +235,15 @@ BENCHMARK_DEFINE_F(
second_graph_info_->GetVertexInfo("organisation")->GetPropertyGroup("id");
auto maybe_reader = VertexPropertyArrowChunkReader::Make(second_graph_info_,
"organisation", gp);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V1).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V1);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
// select one columns and internal ID column
@@ -265,15 +253,15 @@ BENCHMARK_DEFINE_F(
(::benchmark::State& state) { // NOLINT
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
second_graph_info_, "organisation", "id");
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V1).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V1);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -285,15 +273,15 @@ BENCHMARK_DEFINE_F(
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
second_graph_info_, "organisation", {"id", "name"},
SelectType::PROPERTIES);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V1).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V1);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -305,15 +293,15 @@ BENCHMARK_DEFINE_F(
second_graph_info_->GetVertexInfo("organisation")->GetPropertyGroup("id");
auto maybe_reader = VertexPropertyArrowChunkReader::Make(second_graph_info_,
"organisation", gp);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V2).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V2);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
// select one columns and internal ID column
@@ -323,15 +311,15 @@ BENCHMARK_DEFINE_F(
(::benchmark::State& state) { // NOLINT
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
second_graph_info_, "organisation", "id");
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V2).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V2);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -343,15 +331,15 @@ BENCHMARK_DEFINE_F(
auto maybe_reader = VertexPropertyArrowChunkReader::Make(
second_graph_info_, "organisation", {"id", "name"},
SelectType::PROPERTIES);
- if (maybe_reader.has_error()) {
- state.SkipWithError(maybe_reader.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_reader.status());
auto reader = maybe_reader.value();
for (auto _ : state) {
- assert(reader->seek(0).ok());
- assert(reader->GetChunk(GetChunkVersion::V2).status().ok());
- assert(reader->next_chunk().ok());
+ auto st = reader->seek(0);
+ SKIP_WITH_ERROR_STATUS(state, st);
+ auto chunk_result = reader->GetChunk(GetChunkVersion::V2);
+ SKIP_WITH_ERROR_STATUS(state, chunk_result.status());
+ auto next_result = reader->next_chunk();
+ SKIP_WITH_ERROR_STATUS(state, next_result);
}
}
@@ -362,7 +350,6 @@ BENCHMARK_REGISTER_F(BenchmarkFixture,
AdjListPropertyArrowChunkReaderReadChunk);
BENCHMARK_REGISTER_F(BenchmarkFixture, AdjListArrowChunkReaderReadChunk);
BENCHMARK_REGISTER_F(BenchmarkFixture, AdjListOffsetArrowChunkReaderReadChunk);
-BENCHMARK_REGISTER_F(BenchmarkFixture, AdjListOffsetArrowChunkReaderReadChunk);
BENCHMARK_REGISTER_F(
BenchmarkFixture,
VertexPropertyArrowChunkReaderReadChunk_firstGraph_AllColumns_V1);
diff --git a/cpp/benchmarks/benchmark_util.h b/cpp/benchmarks/benchmark_util.h
index 6c0494ff..80dfb008 100644
--- a/cpp/benchmarks/benchmark_util.h
+++ b/cpp/benchmarks/benchmark_util.h
@@ -27,6 +27,12 @@
#include "graphar/api/info.h"
+#define SKIP_WITH_ERROR_STATUS(state, status) \
+ if (!status.ok()) { \
+ state.SkipWithError(status.message().c_str()); \
+ return; \
+ }
+
namespace graphar {
class BenchmarkFixture : public ::benchmark::Fixture {
diff --git a/cpp/benchmarks/graph_info_benchmark.cc
b/cpp/benchmarks/graph_info_benchmark.cc
index efc3c752..5115fbdc 100644
--- a/cpp/benchmarks/graph_info_benchmark.cc
+++ b/cpp/benchmarks/graph_info_benchmark.cc
@@ -28,10 +28,7 @@ static void CreateGraphInfo(::benchmark::State& state, //
NOLINT
const std::string& path) {
for (auto _ : state) {
auto maybe_graph_info = GraphInfo::Load(path);
- if (maybe_graph_info.has_error()) {
- state.SkipWithError(maybe_graph_info.status().message().c_str());
- return;
- }
+ SKIP_WITH_ERROR_STATUS(state, maybe_graph_info.status());
}
}
diff --git a/cpp/src/graphar/high-level/vertices_builder.h
b/cpp/src/graphar/high-level/vertices_builder.h
index b044c59a..b60ebd11 100644
--- a/cpp/src/graphar/high-level/vertices_builder.h
+++ b/cpp/src/graphar/high-level/vertices_builder.h
@@ -102,7 +102,9 @@ class Vertex {
}
empty_ = false;
if (cardinalities_.find(name) != cardinalities_.end()) {
- assert(cardinalities_[name] == cardinality);
+ if (cardinalities_[name] != cardinality) {
+ throw std::runtime_error("Cardinality mismatch for property: " + name);
+ }
auto property_value_list =
std::any_cast<std::vector<std::any>>(properties_[name]);
property_value_list.push_back(val);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]