Skip to content

Commit 6e77ed7

Browse files
authored
[FEAT][C++] Not allow setting custom namespace for code clarity (#415)
Signed-off-by: acezen <qiaozi.zwb@alibaba-inc.com>
1 parent f77897e commit 6e77ed7

65 files changed

Lines changed: 391 additions & 450 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,10 @@ project(graph-archive LANGUAGES C CXX VERSION ${GAR_VERSION})
3737
# cmake options
3838
# ------------------------------------------------------------------------------
3939

40-
option(NAMESPACE "User specific namespace, default is graphar" OFF)
4140
option(BUILD_TESTS "Build unit tests" OFF)
4241
option(BUILD_EXAMPLES "Build examples" OFF)
4342
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
4443

45-
if (NAMESPACE)
46-
add_definitions(-DGAR_NAMESPACE=${NAMESPACE})
47-
else()
48-
add_definitions(-DGAR_NAMESPACE=graphar)
49-
endif()
5044
# ------------------------------------------------------------------------------
5145
# setting default cmake type to Release
5246
# ------------------------------------------------------------------------------

cpp/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ Release build:
5656
$ make -j8 # if you have 8 CPU cores, otherwise adjust, use -j`nproc` for all cores
5757
```
5858

59-
Build with a custom namespace:
60-
61-
The `namespace` is configurable. By default,
62-
it is defined in `namespace graphar`; however this can be toggled by
63-
setting `NAMESPACE` option with cmake:
64-
65-
```bash
66-
$ mkdir build
67-
$ cd build
68-
$ cmake -DNAMESPACE=MyNamespace ..
69-
$ make -j8 # if you have 8 CPU cores, otherwise adjust, use -j`nproc` for all cores
70-
```
71-
7259
Build the Apache Arrow dependency from source:
7360

7461
By default, GraphAr try to find Apache Arrow in the system. This can be configured to build Arrow dependency automatically from source:

cpp/benchmarks/arrow_chunk_reader_benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "gar/reader/arrow_chunk_reader.h"
2222
#include "gar/util/adj_list_type.h"
2323

24-
namespace GAR_NAMESPACE_INTERNAL {
24+
namespace graphar {
2525

2626
BENCHMARK_DEFINE_F(BenchmarkFixture, CreateVertexPropertyArrowChunkReader)
2727
(::benchmark::State& state) { // NOLINT
@@ -149,4 +149,4 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, VertexPropertyArrowChunkReaderReadChunk);
149149
BENCHMARK_REGISTER_F(BenchmarkFixture, AdjListArrowChunkReaderReadChunk);
150150
BENCHMARK_REGISTER_F(BenchmarkFixture, AdjListOffsetArrowChunkReaderReadChunk);
151151
BENCHMARK_REGISTER_F(BenchmarkFixture, AdjListOffsetArrowChunkReaderReadChunk);
152-
} // namespace GAR_NAMESPACE_INTERNAL
152+
} // namespace graphar

cpp/benchmarks/benchmark_util.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@
2626
#ifndef CPP_BENCHMARKS_BENCHMARK_UTIL_H_
2727
#define CPP_BENCHMARKS_BENCHMARK_UTIL_H_
2828

29-
namespace GAR_NAMESPACE_INTERNAL {
29+
namespace graphar {
3030

3131
// Return the value of the GAR_TEST_DATA environment variable or return error
3232
// Status
33-
GAR_NAMESPACE::Status GetTestResourceRoot(std::string* out) {
33+
Status GetTestResourceRoot(std::string* out) {
3434
const char* c_root = std::getenv("GAR_TEST_DATA");
3535
if (!c_root) {
36-
return GAR_NAMESPACE::Status::IOError(
36+
return Status::IOError(
3737
"Test resources not found, set GAR_TEST_DATA to <repo root>/testing");
3838
}
3939
// FIXME(@acezen): This is a hack to get around the fact that the testing
4040
*out = std::string(c_root);
41-
return GAR_NAMESPACE::Status::OK();
41+
return Status::OK();
4242
}
4343

4444
class BenchmarkFixture : public ::benchmark::Fixture {
4545
public:
4646
void SetUp(const ::benchmark::State& state) override {
4747
std::string root;
48-
GAR_NAMESPACE::Status status = GetTestResourceRoot(&root);
48+
Status status = GetTestResourceRoot(&root);
4949
path_ = root + "/ldbc_sample/parquet/ldbc_sample.graph.yml";
5050
auto maybe_graph_info = GraphInfo::Load(path_);
5151
graph_info_ = maybe_graph_info.value();
@@ -57,6 +57,6 @@ class BenchmarkFixture : public ::benchmark::Fixture {
5757
std::string path_;
5858
std::shared_ptr<GraphInfo> graph_info_;
5959
};
60-
} // namespace GAR_NAMESPACE_INTERNAL
60+
} // namespace graphar
6161

6262
#endif // CPP_BENCHMARKS_BENCHMARK_UTIL_H_

cpp/benchmarks/graph_info_benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "./benchmark_util.h"
2020
#include "gar/graph_info.h"
2121

22-
namespace GAR_NAMESPACE_INTERNAL {
22+
namespace graphar {
2323

2424
static void CreateGraphInfo(::benchmark::State& state, // NOLINT
2525
const std::string& path) {
@@ -38,4 +38,4 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, InitialGraphInfo)
3838
}
3939
BENCHMARK_REGISTER_F(BenchmarkFixture, InitialGraphInfo);
4040

41-
} // namespace GAR_NAMESPACE_INTERNAL
41+
} // namespace graphar

cpp/examples/bfs_father_example.cc

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,36 @@ int main(int argc, char* argv[]) {
2929
// read file and construct graph info
3030
std::string path =
3131
TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml";
32-
auto graph_info = GAR_NAMESPACE::GraphInfo::Load(path).value();
32+
auto graph_info = graphar::GraphInfo::Load(path).value();
3333

3434
// get the person vertices of graph
3535
std::string label = "person";
3636
ASSERT(graph_info->GetVertexInfo(label) != nullptr);
37-
auto maybe_vertices =
38-
GAR_NAMESPACE::VerticesCollection::Make(graph_info, label);
37+
auto maybe_vertices = graphar::VerticesCollection::Make(graph_info, label);
3938
ASSERT(maybe_vertices.status().ok());
4039
auto vertices = maybe_vertices.value();
4140
int num_vertices = vertices->size();
4241
std::cout << "num_vertices: " << num_vertices << std::endl;
4342

4443
// get the "person_knows_person" edges of graph
4544
std::string src_label = "person", edge_label = "knows", dst_label = "person";
46-
auto maybe_edges = GAR_NAMESPACE::EdgesCollection::Make(
45+
auto maybe_edges = graphar::EdgesCollection::Make(
4746
graph_info, src_label, edge_label, dst_label,
48-
GAR_NAMESPACE::AdjListType::unordered_by_source);
47+
graphar::AdjListType::unordered_by_source);
4948
ASSERT(!maybe_edges.has_error());
5049
auto& edges = maybe_edges.value();
5150

5251
// run bfs algorithm
53-
GAR_NAMESPACE::IdType root = 0;
52+
graphar::IdType root = 0;
5453
std::vector<int32_t> distance(num_vertices);
55-
std::vector<GAR_NAMESPACE::IdType> pre(num_vertices);
56-
for (GAR_NAMESPACE::IdType i = 0; i < num_vertices; i++) {
54+
std::vector<graphar::IdType> pre(num_vertices);
55+
for (graphar::IdType i = 0; i < num_vertices; i++) {
5756
distance[i] = (i == root ? 0 : -1);
5857
pre[i] = (i == root ? root : -1);
5958
}
6059
auto it_begin = edges->begin(), it_end = edges->end();
6160
for (int iter = 0;; iter++) {
62-
GAR_NAMESPACE::IdType count = 0;
61+
graphar::IdType count = 0;
6362
for (auto it = it_begin; it != it_end; ++it) {
6463
auto src = it.source(), dst = it.destination();
6564
if (distance[src] == iter && distance[dst] == -1) {
@@ -80,11 +79,11 @@ int main(int argc, char* argv[]) {
8079
// Append the bfs result to the vertex info as a property group
8180
// and write to file
8281
// construct property group
83-
GAR_NAMESPACE::Property bfs("bfs", GAR_NAMESPACE::int32(), false);
84-
GAR_NAMESPACE::Property father("father", GAR_NAMESPACE::int64(), false);
85-
std::vector<GAR_NAMESPACE::Property> property_vector = {bfs, father};
86-
auto group = GAR_NAMESPACE::CreatePropertyGroup(property_vector,
87-
GAR_NAMESPACE::FileType::CSV);
82+
graphar::Property bfs("bfs", graphar::int32(), false);
83+
graphar::Property father("father", graphar::int64(), false);
84+
std::vector<graphar::Property> property_vector = {bfs, father};
85+
auto group =
86+
graphar::CreatePropertyGroup(property_vector, graphar::FileType::CSV);
8887

8988
// extend the vertex_info
9089
auto vertex_info = graph_info->GetVertexInfo(label);
@@ -97,15 +96,14 @@ int main(int argc, char* argv[]) {
9796
ASSERT(extend_info->Dump().status().ok());
9897
ASSERT(extend_info->Save("/tmp/person-new-bfs-father.vertex.yml").ok());
9998
// construct vertex property writer
100-
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "file:///tmp/");
99+
graphar::VertexPropertyWriter writer(extend_info, "file:///tmp/");
101100
// convert results to arrow::Table
102101
std::vector<std::shared_ptr<arrow::Array>> arrays;
103102
std::vector<std::shared_ptr<arrow::Field>> schema_vector;
104103
schema_vector.push_back(arrow::field(
105-
bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type)));
104+
bfs.name, graphar::DataType::DataTypeToArrowDataType(bfs.type)));
106105
schema_vector.push_back(arrow::field(
107-
father.name,
108-
GAR_NAMESPACE::DataType::DataTypeToArrowDataType(father.type)));
106+
father.name, graphar::DataType::DataTypeToArrowDataType(father.type)));
109107
arrow::Int32Builder array_builder1;
110108
ASSERT(array_builder1.Reserve(num_vertices).ok());
111109
ASSERT(array_builder1.AppendValues(distance).ok());
@@ -137,24 +135,23 @@ int main(int argc, char* argv[]) {
137135
dst_label = "person";
138136
int edge_chunk_size = 1024, src_chunk_size = 100, dst_chunk_size = 100;
139137
bool directed = true;
140-
auto version = GAR_NAMESPACE::InfoVersion::Parse("gar/v1").value();
141-
auto al = GAR_NAMESPACE::CreateAdjacentList(
142-
GAR_NAMESPACE::AdjListType::ordered_by_source,
143-
GAR_NAMESPACE::FileType::CSV);
144-
auto new_edge_info = GAR_NAMESPACE::CreateEdgeInfo(
138+
auto version = graphar::InfoVersion::Parse("gar/v1").value();
139+
auto al = graphar::CreateAdjacentList(graphar::AdjListType::ordered_by_source,
140+
graphar::FileType::CSV);
141+
auto new_edge_info = graphar::CreateEdgeInfo(
145142
src_label, edge_label, dst_label, edge_chunk_size, src_chunk_size,
146143
dst_chunk_size, directed, {al}, {}, "", version);
147144
ASSERT(new_edge_info->IsValidated());
148145
// save & dump
149146
ASSERT(!new_edge_info->Dump().has_error());
150147
ASSERT(new_edge_info->Save("/tmp/person_bfs_person.edge.yml").ok());
151-
GAR_NAMESPACE::builder::EdgesBuilder edges_builder(
152-
new_edge_info, "file:///tmp/",
153-
GAR_NAMESPACE::AdjListType::ordered_by_source, num_vertices);
148+
graphar::builder::EdgesBuilder edges_builder(
149+
new_edge_info, "file:///tmp/", graphar::AdjListType::ordered_by_source,
150+
num_vertices);
154151
for (int i = 0; i < num_vertices; i++) {
155152
if (i == root || pre[i] == -1)
156153
continue;
157-
GAR_NAMESPACE::builder::Edge e(pre[i], i);
154+
graphar::builder::Edge e(pre[i], i);
158155
ASSERT(edges_builder.AddEdge(e).ok());
159156
}
160157
ASSERT(edges_builder.Dump().ok());

cpp/examples/bfs_pull_example.cc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,42 @@ int main(int argc, char* argv[]) {
2828
// read file and construct graph info
2929
std::string path =
3030
TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml";
31-
auto graph_info = GAR_NAMESPACE::GraphInfo::Load(path).value();
31+
auto graph_info = graphar::GraphInfo::Load(path).value();
3232

3333
// construct vertices collection
3434
std::string label = "person";
3535
ASSERT(graph_info->GetVertexInfo(label) != nullptr);
36-
auto maybe_vertices =
37-
GAR_NAMESPACE::VerticesCollection::Make(graph_info, label);
36+
auto maybe_vertices = graphar::VerticesCollection::Make(graph_info, label);
3837
ASSERT(maybe_vertices.status().ok());
3938
auto& vertices = maybe_vertices.value();
4039
int num_vertices = vertices->size();
4140
std::cout << "num_vertices: " << num_vertices << std::endl;
4241

4342
// construct edges collection
4443
std::string src_label = "person", edge_label = "knows", dst_label = "person";
45-
auto maybe_edges = GAR_NAMESPACE::EdgesCollection::Make(
44+
auto maybe_edges = graphar::EdgesCollection::Make(
4645
graph_info, src_label, edge_label, dst_label,
47-
GAR_NAMESPACE::AdjListType::ordered_by_dest);
46+
graphar::AdjListType::ordered_by_dest);
4847
ASSERT(!maybe_edges.has_error());
4948
auto& edges = maybe_edges.value();
5049

5150
// run bfs algorithm
52-
GAR_NAMESPACE::IdType root = 0;
51+
graphar::IdType root = 0;
5352
std::vector<int32_t> distance(num_vertices);
54-
for (GAR_NAMESPACE::IdType i = 0; i < num_vertices; i++)
53+
for (graphar::IdType i = 0; i < num_vertices; i++)
5554
distance[i] = (i == root ? 0 : -1);
5655
auto it_begin = edges->begin(), it_end = edges->end();
5756
auto it = it_begin;
5857
for (int iter = 0;; iter++) {
59-
GAR_NAMESPACE::IdType count = 0;
58+
graphar::IdType count = 0;
6059
it.to_begin();
61-
for (GAR_NAMESPACE::IdType vid = 0; vid < num_vertices; vid++) {
60+
for (graphar::IdType vid = 0; vid < num_vertices; vid++) {
6261
if (distance[vid] == -1) {
6362
if (!it.first_dst(it, vid))
6463
continue;
6564
// if (!it.first_dst(it_begin, vid)) continue;
6665
do {
67-
GAR_NAMESPACE::IdType src = it.source(), dst = it.destination();
66+
graphar::IdType src = it.source(), dst = it.destination();
6867
if (distance[src] == iter) {
6968
distance[dst] = distance[src] + 1;
7069
count++;
@@ -83,10 +82,10 @@ int main(int argc, char* argv[]) {
8382

8483
// extend the original vertex info and write results to gar using writer
8584
// construct property group
86-
GAR_NAMESPACE::Property bfs("bfs-pull", GAR_NAMESPACE::int32(), false);
87-
std::vector<GAR_NAMESPACE::Property> property_vector = {bfs};
88-
auto group = GAR_NAMESPACE::CreatePropertyGroup(
89-
property_vector, GAR_NAMESPACE::FileType::PARQUET);
85+
graphar::Property bfs("bfs-pull", graphar::int32(), false);
86+
std::vector<graphar::Property> property_vector = {bfs};
87+
auto group =
88+
graphar::CreatePropertyGroup(property_vector, graphar::FileType::PARQUET);
9089
// extend the vertex_info
9190
auto vertex_info = graph_info->GetVertexInfo(label);
9291
auto maybe_extend_info = vertex_info->AddPropertyGroup(group);
@@ -97,12 +96,12 @@ int main(int argc, char* argv[]) {
9796
ASSERT(extend_info->Dump().status().ok());
9897
ASSERT(extend_info->Save("/tmp/person-new-bfs-pull.vertex.yml").ok());
9998
// construct vertex property writer
100-
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/");
99+
graphar::VertexPropertyWriter writer(extend_info, "/tmp/");
101100
// convert results to arrow::Table
102101
std::vector<std::shared_ptr<arrow::Array>> arrays;
103102
std::vector<std::shared_ptr<arrow::Field>> schema_vector;
104103
schema_vector.push_back(arrow::field(
105-
bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type)));
104+
bfs.name, graphar::DataType::DataTypeToArrowDataType(bfs.type)));
106105
arrow::Int32Builder array_builder;
107106
ASSERT(array_builder.Reserve(num_vertices).ok());
108107
ASSERT(array_builder.AppendValues(distance).ok());

cpp/examples/bfs_push_example.cc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,42 @@ int main(int argc, char* argv[]) {
2828
// read file and construct graph info
2929
std::string path =
3030
TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml";
31-
auto graph_info = GAR_NAMESPACE::GraphInfo::Load(path).value();
31+
auto graph_info = graphar::GraphInfo::Load(path).value();
3232

3333
// construct vertices collection
3434
std::string label = "person";
3535
ASSERT(graph_info->GetVertexInfo(label) != nullptr);
36-
auto maybe_vertices =
37-
GAR_NAMESPACE::VerticesCollection::Make(graph_info, label);
36+
auto maybe_vertices = graphar::VerticesCollection::Make(graph_info, label);
3837
ASSERT(maybe_vertices.status().ok());
3938
auto& vertices = maybe_vertices.value();
4039
int num_vertices = vertices->size();
4140
std::cout << "num_vertices: " << num_vertices << std::endl;
4241

4342
// construct edges collection
4443
std::string src_label = "person", edge_label = "knows", dst_label = "person";
45-
auto maybe_edges = GAR_NAMESPACE::EdgesCollection::Make(
44+
auto maybe_edges = graphar::EdgesCollection::Make(
4645
graph_info, src_label, edge_label, dst_label,
47-
GAR_NAMESPACE::AdjListType::ordered_by_source);
46+
graphar::AdjListType::ordered_by_source);
4847
ASSERT(!maybe_edges.has_error());
4948
auto& edges = maybe_edges.value();
5049

5150
// run bfs algorithm
52-
GAR_NAMESPACE::IdType root = 0;
51+
graphar::IdType root = 0;
5352
std::vector<int32_t> distance(num_vertices);
54-
for (GAR_NAMESPACE::IdType i = 0; i < num_vertices; i++)
53+
for (graphar::IdType i = 0; i < num_vertices; i++)
5554
distance[i] = (i == root ? 0 : -1);
5655
auto it_begin = edges->begin(), it_end = edges->end();
5756
auto it = it_begin;
5857
for (int iter = 0;; iter++) {
59-
GAR_NAMESPACE::IdType count = 0;
58+
graphar::IdType count = 0;
6059
it.to_begin();
61-
for (GAR_NAMESPACE::IdType vid = 0; vid < num_vertices; vid++) {
60+
for (graphar::IdType vid = 0; vid < num_vertices; vid++) {
6261
if (distance[vid] == iter) {
6362
if (!it.first_src(it, vid))
6463
continue;
6564
// if (!it.first_src(it_begin, vid)) continue;
6665
do {
67-
GAR_NAMESPACE::IdType src = it.source(), dst = it.destination();
66+
graphar::IdType src = it.source(), dst = it.destination();
6867
if (distance[dst] == -1) {
6968
distance[dst] = distance[src] + 1;
7069
count++;
@@ -82,10 +81,10 @@ int main(int argc, char* argv[]) {
8281

8382
// extend the original vertex info and write results to gar using writer
8483
// construct property group
85-
GAR_NAMESPACE::Property bfs("bfs-push", GAR_NAMESPACE::int32(), false);
86-
std::vector<GAR_NAMESPACE::Property> property_vector = {bfs};
87-
auto group = GAR_NAMESPACE::CreatePropertyGroup(
88-
property_vector, GAR_NAMESPACE::FileType::PARQUET);
84+
graphar::Property bfs("bfs-push", graphar::int32(), false);
85+
std::vector<graphar::Property> property_vector = {bfs};
86+
auto group =
87+
graphar::CreatePropertyGroup(property_vector, graphar::FileType::PARQUET);
8988
// extend the vertex_info
9089
auto vertex_info = graph_info->GetVertexInfo(label);
9190
auto maybe_extend_info = vertex_info->AddPropertyGroup(group);
@@ -96,12 +95,12 @@ int main(int argc, char* argv[]) {
9695
ASSERT(extend_info->Dump().status().ok());
9796
ASSERT(extend_info->Save("/tmp/person-new-bfs-push.vertex.yml").ok());
9897
// construct vertex property writer
99-
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/");
98+
graphar::VertexPropertyWriter writer(extend_info, "/tmp/");
10099
// convert results to arrow::Table
101100
std::vector<std::shared_ptr<arrow::Array>> arrays;
102101
std::vector<std::shared_ptr<arrow::Field>> schema_vector;
103102
schema_vector.push_back(arrow::field(
104-
bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type)));
103+
bfs.name, graphar::DataType::DataTypeToArrowDataType(bfs.type)));
105104
arrow::Int32Builder array_builder;
106105
ASSERT(array_builder.Reserve(num_vertices).ok());
107106
ASSERT(array_builder.AppendValues(distance).ok());

0 commit comments

Comments
 (0)