Skip to content

Commit

Permalink
[BugFix] [C++] Make examples to generate result files under build typ…
Browse files Browse the repository at this point in the history
…e of release (#173)
  • Loading branch information
lixueclaire authored May 26, 2023
1 parent e6a59f4 commit 68e77ab
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 186 deletions.
5 changes: 3 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,11 @@ endif()
# Format code & cpplint
# ------------------------------------------------------------------------------
file(GLOB_RECURSE FILES_NEED_FORMAT "include/gar/*.h" "src/*.cc"
"test/*.h" "test/*.cc")
"test/*.h" "test/*.cc"
"examples/*.h" "examples/*.cc")
file(GLOB_RECURSE FILES_NEED_LINT "include/gar/*.h" "src/*.cc"
"test/*.h" "test/*.cc"
)
"examples/*.h" "examples/*.cc")

add_custom_target(gar-clformat
COMMAND clang-format --style=file -i ${FILES_NEED_FORMAT}
Expand Down
42 changes: 21 additions & 21 deletions cpp/examples/bfs_father_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.

#include "arrow/api.h"

#include "config.h"
#include "./config.h"
#include "gar/graph.h"
#include "gar/graph_info.h"
#include "gar/reader/arrow_chunk_reader.h"
Expand All @@ -32,10 +32,10 @@ int main(int argc, char* argv[]) {

// get the person vertices of graph
std::string label = "person";
assert(graph_info.GetVertexInfo(label).status().ok());
ASSERT(graph_info.GetVertexInfo(label).status().ok());
auto maybe_vertices =
GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label);
assert(maybe_vertices.status().ok());
ASSERT(maybe_vertices.status().ok());
auto& vertices = maybe_vertices.value();
int num_vertices = vertices.size();
std::cout << "num_vertices: " << num_vertices << std::endl;
Expand All @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) {
auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection(
graph_info, src_label, edge_label, dst_label,
GAR_NAMESPACE::AdjListType::unordered_by_source);
assert(!maybe_edges.has_error());
ASSERT(!maybe_edges.has_error());
auto& edges = std::get<GAR_NAMESPACE::EdgesCollection<
GAR_NAMESPACE::AdjListType::unordered_by_source>>(maybe_edges.value());

Expand Down Expand Up @@ -90,16 +90,16 @@ int main(int argc, char* argv[]) {

// extend the vertex_info
auto maybe_vertex_info = graph_info.GetVertexInfo(label);
assert(maybe_vertex_info.status().ok());
ASSERT(maybe_vertex_info.status().ok());
auto vertex_info = maybe_vertex_info.value();
auto maybe_extend_info = vertex_info.Extend(group);
assert(maybe_extend_info.status().ok());
ASSERT(maybe_extend_info.status().ok());
auto extend_info = maybe_extend_info.value();

// dump the extened vertex info
assert(extend_info.IsValidated());
assert(extend_info.Dump().status().ok());
assert(extend_info.Save("/tmp/person-new-bfs-father.vertex.yml").ok());
ASSERT(extend_info.IsValidated());
ASSERT(extend_info.Dump().status().ok());
ASSERT(extend_info.Save("/tmp/person-new-bfs-father.vertex.yml").ok());
// construct vertex property writer
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "file:///tmp/");
// convert results to arrow::Table
Expand All @@ -111,20 +111,20 @@ int main(int argc, char* argv[]) {
father.name,
GAR_NAMESPACE::DataType::DataTypeToArrowDataType(father.type)));
arrow::Int32Builder array_builder1;
assert(array_builder1.Reserve(num_vertices).ok());
assert(array_builder1.AppendValues(distance).ok());
ASSERT(array_builder1.Reserve(num_vertices).ok());
ASSERT(array_builder1.AppendValues(distance).ok());
std::shared_ptr<arrow::Array> array1 = array_builder1.Finish().ValueOrDie();
arrays.push_back(array1);

arrow::Int64Builder array_builder2;
assert(array_builder2.Reserve(num_vertices).ok());
ASSERT(array_builder2.Reserve(num_vertices).ok());
for (int i = 0; i < num_vertices; i++) {
if (pre[i] == -1) {
assert(array_builder2.AppendNull().ok());
ASSERT(array_builder2.AppendNull().ok());
} else {
auto it = vertices.find(pre[i]);
auto father_id = it.property<int64_t>("id").value();
assert(array_builder2.Append(father_id).ok());
ASSERT(array_builder2.Append(father_id).ok());
}
}
std::shared_ptr<arrow::Array> array2 = array_builder2.Finish().ValueOrDie();
Expand All @@ -133,7 +133,7 @@ int main(int argc, char* argv[]) {
auto schema = std::make_shared<arrow::Schema>(schema_vector);
std::shared_ptr<arrow::Table> table = arrow::Table::Make(schema, arrays);
// dump the results through writer
assert(writer.WriteTable(table, group, 0).ok());
ASSERT(writer.WriteTable(table, group, 0).ok());

// construct a new graph
src_label = "person";
Expand All @@ -145,22 +145,22 @@ int main(int argc, char* argv[]) {
GAR_NAMESPACE::EdgeInfo new_edge_info(src_label, edge_label, dst_label,
edge_chunk_size, src_chunk_size,
dst_chunk_size, directed, version);
assert(new_edge_info
ASSERT(new_edge_info
.AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_source,
GAR_NAMESPACE::FileType::CSV)
.ok());
assert(new_edge_info.IsValidated());
ASSERT(new_edge_info.IsValidated());
// save & dump
assert(!new_edge_info.Dump().has_error());
assert(new_edge_info.Save("/tmp/person_bfs_person.edge.yml").ok());
ASSERT(!new_edge_info.Dump().has_error());
ASSERT(new_edge_info.Save("/tmp/person_bfs_person.edge.yml").ok());
GAR_NAMESPACE::builder::EdgesBuilder edges_builder(
new_edge_info, "file:///tmp/",
GAR_NAMESPACE::AdjListType::ordered_by_source, num_vertices);
for (int i = 0; i < num_vertices; i++) {
if (i == root || pre[i] == -1)
continue;
GAR_NAMESPACE::builder::Edge e(pre[i], i);
assert(edges_builder.AddEdge(e).ok());
ASSERT(edges_builder.AddEdge(e).ok());
}
assert(edges_builder.Dump().ok());
ASSERT(edges_builder.Dump().ok());
}
24 changes: 12 additions & 12 deletions cpp/examples/bfs_pull_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

#include "arrow/api.h"

#include "config.h"
#include "./config.h"
#include "gar/graph.h"
#include "gar/graph_info.h"
#include "gar/reader/arrow_chunk_reader.h"
Expand All @@ -30,10 +30,10 @@ int main(int argc, char* argv[]) {

// construct vertices collection
std::string label = "person";
assert(graph_info.GetVertexInfo(label).status().ok());
ASSERT(graph_info.GetVertexInfo(label).status().ok());
auto maybe_vertices =
GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label);
assert(maybe_vertices.status().ok());
ASSERT(maybe_vertices.status().ok());
auto& vertices = maybe_vertices.value();
int num_vertices = vertices.size();
std::cout << "num_vertices: " << num_vertices << std::endl;
Expand All @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) {
auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection(
graph_info, src_label, edge_label, dst_label,
GAR_NAMESPACE::AdjListType::ordered_by_dest);
assert(!maybe_edges.has_error());
ASSERT(!maybe_edges.has_error());
auto& edges = std::get<GAR_NAMESPACE::EdgesCollection<
GAR_NAMESPACE::AdjListType::ordered_by_dest>>(maybe_edges.value());

Expand Down Expand Up @@ -89,15 +89,15 @@ int main(int argc, char* argv[]) {
GAR_NAMESPACE::FileType::PARQUET);
// extend the vertex_info
auto maybe_vertex_info = graph_info.GetVertexInfo(label);
assert(maybe_vertex_info.status().ok());
ASSERT(maybe_vertex_info.status().ok());
auto vertex_info = maybe_vertex_info.value();
auto maybe_extend_info = vertex_info.Extend(group);
assert(maybe_extend_info.status().ok());
ASSERT(maybe_extend_info.status().ok());
auto extend_info = maybe_extend_info.value();
// dump the extened vertex info
assert(extend_info.IsValidated());
assert(extend_info.Dump().status().ok());
assert(extend_info.Save("/tmp/person-new-bfs-pull.vertex.yml").ok());
ASSERT(extend_info.IsValidated());
ASSERT(extend_info.Dump().status().ok());
ASSERT(extend_info.Save("/tmp/person-new-bfs-pull.vertex.yml").ok());
// construct vertex property writer
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/");
// convert results to arrow::Table
Expand All @@ -106,12 +106,12 @@ int main(int argc, char* argv[]) {
schema_vector.push_back(arrow::field(
bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type)));
arrow::Int32Builder array_builder;
assert(array_builder.Reserve(num_vertices).ok());
assert(array_builder.AppendValues(distance).ok());
ASSERT(array_builder.Reserve(num_vertices).ok());
ASSERT(array_builder.AppendValues(distance).ok());
std::shared_ptr<arrow::Array> array = array_builder.Finish().ValueOrDie();
arrays.push_back(array);
auto schema = std::make_shared<arrow::Schema>(schema_vector);
std::shared_ptr<arrow::Table> table = arrow::Table::Make(schema, arrays);
// dump the results through writer
assert(writer.WriteTable(table, group, 0).ok());
ASSERT(writer.WriteTable(table, group, 0).ok());
}
24 changes: 12 additions & 12 deletions cpp/examples/bfs_push_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

#include "arrow/api.h"

#include "config.h"
#include "./config.h"
#include "gar/graph.h"
#include "gar/graph_info.h"
#include "gar/reader/arrow_chunk_reader.h"
Expand All @@ -30,10 +30,10 @@ int main(int argc, char* argv[]) {

// construct vertices collection
std::string label = "person";
assert(graph_info.GetVertexInfo(label).status().ok());
ASSERT(graph_info.GetVertexInfo(label).status().ok());
auto maybe_vertices =
GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label);
assert(maybe_vertices.status().ok());
ASSERT(maybe_vertices.status().ok());
auto& vertices = maybe_vertices.value();
int num_vertices = vertices.size();
std::cout << "num_vertices: " << num_vertices << std::endl;
Expand All @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) {
auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection(
graph_info, src_label, edge_label, dst_label,
GAR_NAMESPACE::AdjListType::ordered_by_source);
assert(!maybe_edges.has_error());
ASSERT(!maybe_edges.has_error());
auto& edges = std::get<GAR_NAMESPACE::EdgesCollection<
GAR_NAMESPACE::AdjListType::ordered_by_source>>(maybe_edges.value());

Expand Down Expand Up @@ -88,15 +88,15 @@ int main(int argc, char* argv[]) {
GAR_NAMESPACE::FileType::PARQUET);
// extend the vertex_info
auto maybe_vertex_info = graph_info.GetVertexInfo(label);
assert(maybe_vertex_info.status().ok());
ASSERT(maybe_vertex_info.status().ok());
auto vertex_info = maybe_vertex_info.value();
auto maybe_extend_info = vertex_info.Extend(group);
assert(maybe_extend_info.status().ok());
ASSERT(maybe_extend_info.status().ok());
auto extend_info = maybe_extend_info.value();
// dump the extened vertex info
assert(extend_info.IsValidated());
assert(extend_info.Dump().status().ok());
assert(extend_info.Save("/tmp/person-new-bfs-push.vertex.yml").ok());
ASSERT(extend_info.IsValidated());
ASSERT(extend_info.Dump().status().ok());
ASSERT(extend_info.Save("/tmp/person-new-bfs-push.vertex.yml").ok());
// construct vertex property writer
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/");
// convert results to arrow::Table
Expand All @@ -105,12 +105,12 @@ int main(int argc, char* argv[]) {
schema_vector.push_back(arrow::field(
bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type)));
arrow::Int32Builder array_builder;
assert(array_builder.Reserve(num_vertices).ok());
assert(array_builder.AppendValues(distance).ok());
ASSERT(array_builder.Reserve(num_vertices).ok());
ASSERT(array_builder.AppendValues(distance).ok());
std::shared_ptr<arrow::Array> array = array_builder.Finish().ValueOrDie();
arrays.push_back(array);
auto schema = std::make_shared<arrow::Schema>(schema_vector);
std::shared_ptr<arrow::Table> table = arrow::Table::Make(schema, arrays);
// dump the results through writer
assert(writer.WriteTable(table, group, 0).ok());
ASSERT(writer.WriteTable(table, group, 0).ok());
}
24 changes: 12 additions & 12 deletions cpp/examples/bfs_stream_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

#include "arrow/api.h"

#include "config.h"
#include "./config.h"
#include "gar/graph.h"
#include "gar/graph_info.h"
#include "gar/reader/arrow_chunk_reader.h"
Expand All @@ -30,10 +30,10 @@ int main(int argc, char* argv[]) {

// construct vertices collection
std::string label = "person";
assert(graph_info.GetVertexInfo(label).status().ok());
ASSERT(graph_info.GetVertexInfo(label).status().ok());
auto maybe_vertices =
GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label);
assert(maybe_vertices.status().ok());
ASSERT(maybe_vertices.status().ok());
auto& vertices = maybe_vertices.value();
int num_vertices = vertices.size();
std::cout << "num_vertices: " << num_vertices << std::endl;
Expand All @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) {
auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection(
graph_info, src_label, edge_label, dst_label,
GAR_NAMESPACE::AdjListType::unordered_by_source);
assert(!maybe_edges.has_error());
ASSERT(!maybe_edges.has_error());
auto& edges = std::get<GAR_NAMESPACE::EdgesCollection<
GAR_NAMESPACE::AdjListType::unordered_by_source>>(maybe_edges.value());

Expand Down Expand Up @@ -79,15 +79,15 @@ int main(int argc, char* argv[]) {
GAR_NAMESPACE::FileType::PARQUET);
// extend the vertex_info
auto maybe_vertex_info = graph_info.GetVertexInfo(label);
assert(maybe_vertex_info.status().ok());
ASSERT(maybe_vertex_info.status().ok());
auto vertex_info = maybe_vertex_info.value();
auto maybe_extend_info = vertex_info.Extend(group);
assert(maybe_extend_info.status().ok());
ASSERT(maybe_extend_info.status().ok());
auto extend_info = maybe_extend_info.value();
// dump the extened vertex info
assert(extend_info.IsValidated());
assert(extend_info.Dump().status().ok());
assert(extend_info.Save("/tmp/person-new-bfs-stream.vertex.yml").ok());
ASSERT(extend_info.IsValidated());
ASSERT(extend_info.Dump().status().ok());
ASSERT(extend_info.Save("/tmp/person-new-bfs-stream.vertex.yml").ok());
// construct vertex property writer
GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/");
// convert results to arrow::Table
Expand All @@ -96,12 +96,12 @@ int main(int argc, char* argv[]) {
schema_vector.push_back(arrow::field(
bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type)));
arrow::Int32Builder array_builder;
assert(array_builder.Reserve(num_vertices).ok());
assert(array_builder.AppendValues(distance).ok());
ASSERT(array_builder.Reserve(num_vertices).ok());
ASSERT(array_builder.AppendValues(distance).ok());
std::shared_ptr<arrow::Array> array = array_builder.Finish().ValueOrDie();
arrays.push_back(array);
auto schema = std::make_shared<arrow::Schema>(schema_vector);
std::shared_ptr<arrow::Table> table = arrow::Table::Make(schema, arrays);
// dump the results through writer
assert(writer.WriteTable(table, group, 0).ok());
ASSERT(writer.WriteTable(table, group, 0).ok());
}
Loading

0 comments on commit 68e77ab

Please sign in to comment.