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

[C++] Add edge count file in GraphAr #132

Merged
merged 9 commits into from
Apr 13, 2023
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
7 changes: 3 additions & 4 deletions cpp/examples/bfs_father_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ limitations under the License.
#include "gar/writer/arrow_chunk_writer.h"
#include "gar/writer/edges_builder.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down Expand Up @@ -147,9 +146,9 @@ int main(int argc, char* argv[]) {
edge_chunk_size, src_chunk_size,
dst_chunk_size, directed, version);
assert(new_edge_info
.AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_source,
GAR_NAMESPACE::FileType::CSV)
.ok());
.AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_source,
GAR_NAMESPACE::FileType::CSV)
.ok());
assert(new_edge_info.IsValidated());
// save & dump
assert(!new_edge_info.Dump().has_error());
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/bfs_pull_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ limitations under the License.
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/writer/arrow_chunk_writer.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/bfs_push_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ limitations under the License.
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/writer/arrow_chunk_writer.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/bfs_stream_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ limitations under the License.
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/writer/arrow_chunk_writer.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/bgl_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ limitations under the License.
#include "gar/writer/arrow_chunk_writer.h"
#include "gar/writer/vertices_builder.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/cc_push_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ limitations under the License.
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/writer/arrow_chunk_writer.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/cc_stream_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ limitations under the License.
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/writer/arrow_chunk_writer.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ static const std::string TEST_DATA_DIR = // NOLINT
.parent_path()
.parent_path()
.string() +
"/test/gar-test";
"/testing";

#endif // TEST_CONFIG_H_
74 changes: 35 additions & 39 deletions cpp/examples/construct_info_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.

#include "gar/graph_info.h"


int main(int argc, char* argv[]) {
/*------------------construct graph info------------------*/
std::string name = "graph", prefix = "file:///tmp/";
Expand Down Expand Up @@ -67,7 +66,7 @@ int main(int argc, char* argv[]) {
assert(!vertex_info.IsPrimaryKey(gender.name).status().ok());
assert(vertex_info.GetPropertyType(id.name).value() == id.type);
assert(vertex_info.GetFilePath(group1, 0).value() ==
"vertex/person/id/chunk0");
"vertex/person/id/chunk0");

// extend property groups & validate
auto result = vertex_info.Extend(group2);
Expand All @@ -88,7 +87,7 @@ int main(int argc, char* argv[]) {
assert(graph_info.GetVertexInfos().size() == 1);
assert(graph_info.GetVertexInfo(vertex_label).status().ok());
assert(graph_info.GetVertexPropertyGroup(vertex_label, id.name).value() ==
group1);
group1);
assert(
graph_info.GetVertexPropertyGroup(vertex_label, firstName.name).value() ==
group2);
Expand All @@ -114,28 +113,27 @@ int main(int argc, char* argv[]) {
assert(!edge_info.ContainAdjList(
GAR_NAMESPACE::AdjListType::unordered_by_source));
assert(edge_info
.AddAdjList(GAR_NAMESPACE::AdjListType::unordered_by_source,
GAR_NAMESPACE::FileType::PARQUET)
.ok());
.AddAdjList(GAR_NAMESPACE::AdjListType::unordered_by_source,
GAR_NAMESPACE::FileType::PARQUET)
.ok());
assert(edge_info.ContainAdjList(
GAR_NAMESPACE::AdjListType::unordered_by_source));
assert(edge_info
.AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_dest,
GAR_NAMESPACE::FileType::PARQUET)
.ok());
assert(
edge_info.GetFileType(GAR_NAMESPACE::AdjListType::ordered_by_dest)
.value() == GAR_NAMESPACE::FileType::PARQUET);
.AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_dest,
GAR_NAMESPACE::FileType::PARQUET)
.ok());
assert(edge_info.GetFileType(GAR_NAMESPACE::AdjListType::ordered_by_dest)
.value() == GAR_NAMESPACE::FileType::PARQUET);
assert(
edge_info
.GetAdjListFilePath(0, 0, GAR_NAMESPACE::AdjListType::ordered_by_dest)
.value() ==
"edge/person_knows_person/ordered_by_dest/adj_list/part0/chunk0");
assert(edge_info
.GetAdjListOffsetFilePath(
0, GAR_NAMESPACE::AdjListType::ordered_by_dest)
.value() ==
"edge/person_knows_person/ordered_by_dest/offset/part0/chunk0");
.GetAdjListOffsetFilePath(
0, GAR_NAMESPACE::AdjListType::ordered_by_dest)
.value() ==
"edge/person_knows_person/ordered_by_dest/offset/chunk0");

// add property group & validate
GAR_NAMESPACE::Property creationDate = {
Expand All @@ -148,45 +146,43 @@ int main(int argc, char* argv[]) {
group3, GAR_NAMESPACE::AdjListType::unordered_by_source));
assert(!edge_info.ContainProperty(creationDate.name));
assert(edge_info
.AddPropertyGroup(group3,
GAR_NAMESPACE::AdjListType::unordered_by_source)
.ok());
.AddPropertyGroup(group3,
GAR_NAMESPACE::AdjListType::unordered_by_source)
.ok());
assert(edge_info.ContainPropertyGroup(
group3, GAR_NAMESPACE::AdjListType::unordered_by_source));
assert(edge_info.ContainProperty(creationDate.name));
assert(
edge_info
.GetPropertyGroups(GAR_NAMESPACE::AdjListType::unordered_by_source)
.value()[0] == group3);
assert(edge_info
.GetPropertyGroup(creationDate.name,
GAR_NAMESPACE::AdjListType::unordered_by_source)
.value() == group3);
.GetPropertyGroups(GAR_NAMESPACE::AdjListType::unordered_by_source)
.value()[0] == group3);
assert(edge_info
.GetPropertyGroup(creationDate.name,
GAR_NAMESPACE::AdjListType::unordered_by_source)
.value() == group3);
assert(!edge_info
.GetPropertyGroup(creationDate.name,
GAR_NAMESPACE::AdjListType::ordered_by_source)
.status()
.ok());
.GetPropertyGroup(creationDate.name,
GAR_NAMESPACE::AdjListType::ordered_by_source)
.status()
.ok());
assert(
edge_info
.GetPropertyFilePath(
group3, GAR_NAMESPACE::AdjListType::unordered_by_source, 0, 0)
.value() ==
"edge/person_knows_person/unordered_by_source/creationDate/part0/chunk0");
assert(edge_info.GetPropertyType(creationDate.name).value() ==
creationDate.type);
creationDate.type);
assert(edge_info.IsPrimaryKey(creationDate.name).value() ==
creationDate.is_primary);
creationDate.is_primary);

// extend & validate
auto res1 =
edge_info.ExtendAdjList(GAR_NAMESPACE::AdjListType::ordered_by_source,
GAR_NAMESPACE::FileType::PARQUET);
assert(res1.status().ok());
edge_info = res1.value();
assert(edge_info
.GetFileType(GAR_NAMESPACE::AdjListType::ordered_by_source)
.value() == GAR_NAMESPACE::FileType::PARQUET);
assert(edge_info.GetFileType(GAR_NAMESPACE::AdjListType::ordered_by_source)
.value() == GAR_NAMESPACE::FileType::PARQUET);
auto res2 = edge_info.ExtendPropertyGroup(
group3, GAR_NAMESPACE::AdjListType::ordered_by_source);
assert(res2.status().ok());
Expand All @@ -202,10 +198,10 @@ int main(int argc, char* argv[]) {
assert(
graph_info.GetEdgeInfo(src_label, edge_label, dst_label).status().ok());
assert(graph_info
.GetEdgePropertyGroup(
src_label, edge_label, dst_label, creationDate.name,
GAR_NAMESPACE::AdjListType::unordered_by_source)
.value() == group3);
.GetEdgePropertyGroup(
src_label, edge_label, dst_label, creationDate.name,
GAR_NAMESPACE::AdjListType::unordered_by_source)
.value() == group3);
assert(graph_info.IsValidated());

// save & dump
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/pagerank_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ limitations under the License.
#include "gar/reader/arrow_chunk_reader.h"
#include "gar/writer/arrow_chunk_writer.h"


int main(int argc, char* argv[]) {
// read file and construct graph info
std::string path =
Expand Down
72 changes: 36 additions & 36 deletions cpp/include/gar/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ class EdgesCollection<AdjListType::ordered_by_source> {
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
chunk_end_ += edge_chunk_nums[i];
}
index_converter_ =
Expand Down Expand Up @@ -692,9 +692,9 @@ class EdgesCollection<AdjListType::ordered_by_source> {
fs->GetFileNumOfDir(base_dir));
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
}
index_converter_ =
std::make_shared<util::IndexConverter>(std::move(edge_chunk_nums));
Expand Down Expand Up @@ -728,9 +728,9 @@ class EdgesCollection<AdjListType::ordered_by_source> {
chunk_begin_ = 0;
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
if (i < vertex_chunk_index) {
chunk_begin_ += edge_chunk_nums[i];
}
Expand Down Expand Up @@ -878,9 +878,9 @@ class EdgesCollection<AdjListType::ordered_by_dest> {
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
chunk_end_ += edge_chunk_nums[i];
}
index_converter_ =
Expand Down Expand Up @@ -913,9 +913,9 @@ class EdgesCollection<AdjListType::ordered_by_dest> {
fs->GetFileNumOfDir(base_dir));
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
}
index_converter_ =
std::make_shared<util::IndexConverter>(std::move(edge_chunk_nums));
Expand Down Expand Up @@ -949,9 +949,9 @@ class EdgesCollection<AdjListType::ordered_by_dest> {
chunk_begin_ = 0;
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
if (i < vertex_chunk_index) {
chunk_begin_ += edge_chunk_nums[i];
}
Expand Down Expand Up @@ -1099,9 +1099,9 @@ class EdgesCollection<AdjListType::unordered_by_source> {
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
chunk_end_ += edge_chunk_nums[i];
}
index_converter_ =
Expand Down Expand Up @@ -1134,9 +1134,9 @@ class EdgesCollection<AdjListType::unordered_by_source> {
fs->GetFileNumOfDir(base_dir));
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
}
index_converter_ =
std::make_shared<util::IndexConverter>(std::move(edge_chunk_nums));
Expand Down Expand Up @@ -1170,9 +1170,9 @@ class EdgesCollection<AdjListType::unordered_by_source> {
chunk_begin_ = 0;
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
if (i < vertex_chunk_index) {
chunk_begin_ += edge_chunk_nums[i];
}
Expand Down Expand Up @@ -1290,9 +1290,9 @@ class EdgesCollection<AdjListType::unordered_by_dest> {
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
chunk_end_ += edge_chunk_nums[i];
}
index_converter_ =
Expand Down Expand Up @@ -1325,9 +1325,9 @@ class EdgesCollection<AdjListType::unordered_by_dest> {
fs->GetFileNumOfDir(base_dir));
std::vector<IdType> edge_chunk_nums(vertex_chunk_num, 0);
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
}
index_converter_ =
std::make_shared<util::IndexConverter>(std::move(edge_chunk_nums));
Expand Down Expand Up @@ -1361,9 +1361,9 @@ class EdgesCollection<AdjListType::unordered_by_dest> {
chunk_begin_ = 0;
chunk_end_ = 0;
for (IdType i = 0; i < vertex_chunk_num; ++i) {
std::string chunk_dir = base_dir + "/part" + std::to_string(i);
GAR_ASSIGN_OR_RAISE_ERROR(edge_chunk_nums[i],
fs->GetFileNumOfDir(chunk_dir));
GAR_ASSIGN_OR_RAISE_ERROR(
edge_chunk_nums[i],
utils::GetEdgeChunkNum(prefix, edge_info, adj_list_type_, i));
if (i < vertex_chunk_index) {
chunk_begin_ += edge_chunk_nums[i];
}
Expand Down
Loading