From 498cf3e18b21e687808c6ff58e8e0185c2c9cbae Mon Sep 17 00:00:00 2001 From: Diwen Zhu Date: Fri, 16 Dec 2022 01:13:41 +0800 Subject: [PATCH 1/6] organize an example pagerank app employing the gar library (#44) --- .gitignore | 3 + README.rst | 1 + examples/pagerank/CMakeLists.txt | 23 ++++ examples/pagerank/README.rst | 60 +++++++++++ examples/pagerank/cmake/apache-arrow.cmake | 92 ++++++++++++++++ examples/pagerank/pagerank.cc | 116 +++++++++++++++++++++ 6 files changed, 295 insertions(+) create mode 100644 examples/pagerank/CMakeLists.txt create mode 100644 examples/pagerank/README.rst create mode 100644 examples/pagerank/cmake/apache-arrow.cmake create mode 100644 examples/pagerank/pagerank.cc diff --git a/.gitignore b/.gitignore index 0c4a1b713..2aea7c86e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ spark/target/ # docs /docs/_build/ +# examples +/examples/*/build + diff --git a/README.rst b/README.rst index 08809a14f..beba6be2c 100644 --- a/README.rst +++ b/README.rst @@ -209,6 +209,7 @@ target linked with GraphAr C++ shared library. target_compile_features(my_example PRIVATE cxx_std_17) target_link_libraries(my_example PRIVATE ${GAR_LIBRARIES}) +Please refer to `examples/pagerank` for details. Contributing to GraphAr ----------------------- diff --git a/examples/pagerank/CMakeLists.txt b/examples/pagerank/CMakeLists.txt new file mode 100644 index 000000000..775cc5434 --- /dev/null +++ b/examples/pagerank/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 2.8) + +# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: +if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") + cmake_policy(SET CMP0135 NEW) +endif() + +project(Pagerank) + +find_package(Threads REQUIRED) +find_package(gar REQUIRED) + +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +include(apache-arrow) +build_arrow() + +include_directories(BEFORE SYSTEM ${ARROW_INCLUDE_DIR}) + +include_directories(${GAR_INCLUDE_DIRS}) + +add_executable(pagerank pagerank.cc) +target_compile_features(pagerank PRIVATE cxx_std_17) +target_link_libraries(pagerank PRIVATE ${GAR_LIBRARIES}) \ No newline at end of file diff --git a/examples/pagerank/README.rst b/examples/pagerank/README.rst new file mode 100644 index 000000000..ef143903c --- /dev/null +++ b/examples/pagerank/README.rst @@ -0,0 +1,60 @@ +A PageRank Example +------------------- + +This example demonstrates how to compute the PageRank of an input graph using GAR and write back the values as a new property of the graph. + +Integrate GAR +^^^^^^^^^^^^^^^^^^ + +To include GAR C++ library, add the following commands in the CMakeLists.txt: + +.. code-block:: cmake + + find_package(gar REQUIRED) + include_directories(${GAR_INCLUDE_DIRS}) + target_link_libraries(pagerank PRIVATE ${GAR_LIBRARIES}) + + +Build the Project +^^^^^^^^^^^^^^^^^^ + +.. code-block:: shell + + mkdir build && cd build + cmake .. + make + + +Prepare the input graph +^^^^^^^^^^^^^^^^^^^^^^^^ + +Copy the ldbc_sample graph from test + +.. code-block:: shell + + copy -r ${project_dir}/test/gar-test/ldbc_sample /tmp/ + + +Run the example +^^^^^^^^^^^^^^^^ + +.. code-block:: shell + + ./pagerank + +The output looks like: + +.. code-block:: shell + + num_vertices: 903 + iter 0 + iter 1 + iter 2 + iter 3 + iter 4 + iter 5 + iter 6 + iter 7 + iter 8 + iter 9 + Done diff --git a/examples/pagerank/cmake/apache-arrow.cmake b/examples/pagerank/cmake/apache-arrow.cmake new file mode 100644 index 000000000..633abd87a --- /dev/null +++ b/examples/pagerank/cmake/apache-arrow.cmake @@ -0,0 +1,92 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# This cmake file is referred and derived from +# https://github.com/apache/arrow/blob/master/matlab/CMakeLists.txt + + +# Build the Arrow C++ libraries. +function(build_arrow) + set(one_value_args) + set(multi_value_args) + + cmake_parse_arguments(ARG + "${options}" + "${one_value_args}" + "${multi_value_args}" + ${ARGN}) + if (ARG_UNPARSED_ARGUMENTS) + message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}") + endif () + + find_package(Threads) + # If Arrow needs to be built, the default location will be within the build tree. + set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-prefix") + + set(ARROW_STATIC_LIBRARY_DIR "${ARROW_PREFIX}/lib") + + set(ARROW_STATIC_LIB_FILENAME + "${CMAKE_STATIC_LIBRARY_PREFIX}arrow${CMAKE_STATIC_LIBRARY_SUFFIX}") + set(ARROW_STATIC_LIB "${ARROW_STATIC_LIBRARY_DIR}/${ARROW_STATIC_LIB_FILENAME}") + set(PARQUET_STATIC_LIB_FILENAME + "${CMAKE_STATIC_LIBRARY_PREFIX}parquet${CMAKE_STATIC_LIBRARY_SUFFIX}") + set(PARQUET_STATIC_LIB "${ARROW_STATIC_LIBRARY_DIR}/${PARQUET_STATIC_LIB_FILENAME}" CACHE INTERNAL "parquet lib") + set(ARROW_BUNDLED_DEPS_STATIC_LIB_FILENAME + "${CMAKE_STATIC_LIBRARY_PREFIX}arrow_bundled_dependencies${CMAKE_STATIC_LIBRARY_SUFFIX}") + set(ARROW_BUNDLED_DEPS_STATIC_LIB + "${ARROW_STATIC_LIBRARY_DIR}/${ARROW_BUNDLED_DEPS_STATIC_LIB_FILENAME}" CACHE INTERNAL "bundled deps lib") + + set(ARROW_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-build") + set(ARROW_CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${ARROW_PREFIX}" + "-DARROW_BUILD_STATIC=ON" "-DARROW_BUILD_SHARED=OFF" + "-DARROW_DEPENDENCY_SOURCE=BUNDLED" "-DARROW_DEPENDENCY_USE_SHARED=OFF" + "-DCMAKE_INSTALL_LIBDIR=lib" "-Dxsimd_SOURCE=BUNDLED" + "-DARROW_PARQUET=ON" "-DARROW_WITH_RE2=OFF" + "-DARROW_WITH_UTF8PROC=OFF" "-DARROW_WITH_RE2=OFF" + "-DARROW_FILESYSTEM=ON" "-DARROW_CSV=ON" "-DARROW_PYTHON=OFF" + "-DARROW_BUILD_BENCHMAKRS=OFF" "-DARROW_BUILD_TESTS=OFF" + "-DARROW_BUILD_INTEGRATION=OFF" "-DBoost_SOURCE=BUNDLED" + "-DARROW_ORC=ON" "-DARROW_COMPUTE=ON" + "-DARROW_DATASET=ON" "-DARROW_WITH_SNAPPY=OFF" "-DARROW_WITH_LZ4=OFF" + "-DARROW_WITH_ZSTD=ON" "-DARROW_WITH_ZLIB=OFF" "-DARROW_WITH_BROTLI=OFF" "-DARROW_WITH_BZ2=OFF") + + set(ARROW_INCLUDE_DIR "${ARROW_PREFIX}/include" CACHE INTERNAL "arrow include directory") + set(ARROW_BUILD_BYPRODUCTS "${ARROW_STATIC_LIB}" "${PARQUET_STATIC_LIB}") + + include(ExternalProject) + externalproject_add(arrow_ep + URL https://www.apache.org/dyn/closer.lua?action=download&filename=arrow/arrow-9.0.0/apache-arrow-9.0.0.tar.gz + SOURCE_SUBDIR cpp + BINARY_DIR "${ARROW_BINARY_DIR}" + CMAKE_ARGS "${ARROW_CMAKE_ARGS}" + BUILD_BYPRODUCTS "${ARROW_BUILD_BYPRODUCTS}") + + set(ARROW_LIBRARY_TARGET arrow_static) + set(PARQUET_LIBRARY_TARGET parquet_static) + + file(MAKE_DIRECTORY "${ARROW_INCLUDE_DIR}") + add_library(${ARROW_LIBRARY_TARGET} STATIC IMPORTED) + add_library(${PARQUET_LIBRARY_TARGET} STATIC IMPORTED) + set_target_properties(${ARROW_LIBRARY_TARGET} + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ARROW_INCLUDE_DIR} + IMPORTED_LOCATION ${ARROW_STATIC_LIB}) + set_target_properties(${PARQUET_LIBRARY_TARGET} + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ARROW_INCLUDE_DIR} + IMPORTED_LOCATION ${PARQUET_STATIC_LIB}) + + add_dependencies(${ARROW_LIBRARY_TARGET} arrow_ep) +endfunction() diff --git a/examples/pagerank/pagerank.cc b/examples/pagerank/pagerank.cc new file mode 100644 index 000000000..9116fecfc --- /dev/null +++ b/examples/pagerank/pagerank.cc @@ -0,0 +1,116 @@ +/** Copyright 2022 Alibaba Group Holding Limited. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include +#include + +#include "arrow/api.h" +#include "arrow/filesystem/api.h" + +#include "gar/graph.h" +#include "gar/graph_info.h" +#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 = "/tmp/ldbc_sample/parquet/ldbc_sample.graph.yml"; + auto graph_info = GraphArchive::GraphInfo::Load(path).value(); + + // construct vertices collection + std::string label = "person"; + auto maybe_vertices = + GraphArchive::ConstructVerticesCollection(graph_info, label); + auto& vertices = maybe_vertices.value(); + int num_vertices = vertices.size(); + std::cout << "num_vertices: " << num_vertices << std::endl; + + // construct edges collection + std::string src_label = "person", edge_label = "knows", dst_label = "person"; + auto maybe_edges = GraphArchive::ConstructEdgesCollection( + graph_info, src_label, edge_label, dst_label, + GraphArchive::AdjListType::ordered_by_source); + auto& edges = std::get>(maybe_edges.value()); + + // run pagerank algorithm + const double damping = 0.85; + const int max_iters = 10; + std::vector pr_curr(num_vertices); + std::vector pr_next(num_vertices); + std::vector out_degree(num_vertices); + for (GraphArchive::IdType i = 0; i < num_vertices; i++) { + pr_curr[i] = 1 / static_cast(num_vertices); + pr_next[i] = 0; + out_degree[i] = 0; + } + auto it_begin = edges.begin(), it_end = edges.end(); + for (auto it = it_begin; it != it_end; ++it) { + GraphArchive::IdType src = it.source(); + out_degree[src]++; + } + for (int iter = 0; iter < max_iters; iter++) { + std::cout << "iter " << iter << std::endl; + for (auto it = it_begin; it != it_end; ++it) { + GraphArchive::IdType src = it.source(), dst = it.destination(); + pr_next[dst] += pr_curr[src] / out_degree[src]; + } + for (GraphArchive::IdType i = 0; i < num_vertices; i++) { + pr_next[i] = damping * pr_next[i] + + (1 - damping) * (1 / static_cast(num_vertices)); + if (out_degree[i] == 0) + pr_next[i] += damping * pr_curr[i]; + pr_curr[i] = pr_next[i]; + pr_next[i] = 0; + } + } + + // extend the original vertex info and write results to gar using writer + // construct property group + GraphArchive::Property pagerank = { + "pagerank", GraphArchive::DataType(GraphArchive::Type::DOUBLE), false}; + std::vector property_vector = {pagerank}; + GraphArchive::PropertyGroup group(property_vector, + GraphArchive::FileType::PARQUET); + // extend the vertex_info + auto maybe_vertex_info = graph_info.GetVertexInfo(label); + auto vertex_info = maybe_vertex_info.value(); + auto maybe_extend_info = vertex_info.Extend(group); + 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-pagerank.vertex.yml").ok()); + // construct vertex property writer + GraphArchive::VertexPropertyWriter writer(extend_info, "/tmp/"); + // convert results to arrow::Table + std::vector> arrays; + std::vector> schema_vector; + schema_vector.push_back(arrow::field( + pagerank.name, + GraphArchive::DataType::DataTypeToArrowDataType(pagerank.type))); + arrow::DoubleBuilder array_builder; + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(pr_curr).ok()); + std::shared_ptr array = array_builder.Finish().ValueOrDie(); + arrays.push_back(array); + auto schema = std::make_shared(schema_vector); + std::shared_ptr table = arrow::Table::Make(schema, arrays); + // dump the results through writer + assert(writer.WriteTable(table, group, 0).ok()); + + std::cout << "Done" << std::endl; + return 0; +} From 095e137dd8c4b0ed7fb881f800fbe9b2499e848f Mon Sep 17 00:00:00 2001 From: Diwen Zhu Date: Sun, 18 Dec 2022 18:15:43 +0800 Subject: [PATCH 2/6] move test_examples to examples --- CMakeLists.txt | 24 +-- docs/applications/bgl.rst | 2 +- docs/applications/out-of-core.rst | 14 +- docs/user-guide/getting-started.rst | 4 +- .../bfs_father_example.cc | 48 +++--- .../bfs_pull_example.cc | 30 ++-- .../bfs_push_example.cc | 30 ++-- .../bfs_stream_example.cc | 30 ++-- .../bgl_example.cc | 46 +++--- .../cc_push_example.cc | 32 ++-- .../cc_stream_example.cc | 30 ++-- examples/config.h | 25 ++++ .../construct_info_example.cc | 138 +++++++++--------- examples/pagerank/CMakeLists.txt | 23 --- examples/pagerank/README.rst | 60 -------- examples/pagerank/cmake/apache-arrow.cmake | 92 ------------ examples/pagerank/pagerank.cc | 116 --------------- .../pagerank_example.cc | 30 ++-- 18 files changed, 248 insertions(+), 526 deletions(-) rename test/test_example/test_bfs_father_example.cc => examples/bfs_father_example.cc (82%) rename test/test_example/test_bfs_pull_example.cc => examples/bfs_pull_example.cc (84%) rename test/test_example/test_bfs_push_example.cc => examples/bfs_push_example.cc (84%) rename test/test_example/test_bfs_stream_example.cc => examples/bfs_stream_example.cc (83%) rename test/test_example/test_bgl_example.cc => examples/bgl_example.cc (85%) rename test/test_example/test_cc_push_example.cc => examples/cc_push_example.cc (87%) rename test/test_example/test_cc_stream_example.cc => examples/cc_stream_example.cc (85%) create mode 100644 examples/config.h rename test/test_example/test_construct_info_example.cc => examples/construct_info_example.cc (68%) delete mode 100644 examples/pagerank/CMakeLists.txt delete mode 100644 examples/pagerank/README.rst delete mode 100644 examples/pagerank/cmake/apache-arrow.cmake delete mode 100644 examples/pagerank/pagerank.cc rename test/test_example/test_pagerank_example.cc => examples/pagerank_example.cc (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96b1ef57a..1c32d2b12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,21 @@ endmacro() build_gar() +# ------------------------------------------------------------------------------ +# build example +# ------------------------------------------------------------------------------ +find_package(Boost REQUIRED COMPONENTS graph) + +file(GLOB EXAMPLE_FILES RELATIVE "${PROJECT_SOURCE_DIR}/examples" "${PROJECT_SOURCE_DIR}/examples/*.cc") + foreach(f ${EXAMPLE_FILES}) + string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${f}) + set(E_NAME ${CMAKE_MATCH_1}) + message(STATUS "Found example - " ${E_NAME}) + add_executable(${E_NAME} examples/${E_NAME}.cc) + target_include_directories(${E_NAME} PRIVATE examples ${PROJECT_SOURCE_DIR}/include $) + include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) + target_link_libraries(${E_NAME} PRIVATE gar) + endforeach() # ------------------------------------------------------------------------------ # Install @@ -255,15 +270,6 @@ if (BUILD_TESTS) add_test(test_arrow_chunk_reader SRCS test/test_arrow_chunk_reader.cc) add_test(test_graph SRCS test/test_graph.cc) - add_test(test_construct_info_example SRCS test/test_example/test_construct_info_example.cc) - add_test(test_bgl_example SRCS test/test_example/test_bgl_example.cc) - add_test(test_cc_push_example SRCS test/test_example/test_cc_push_example.cc) - add_test(test_cc_stream_example SRCS test/test_example/test_cc_stream_example.cc) - add_test(test_pagerank_example SRCS test/test_example/test_pagerank_example.cc) - add_test(test_bfs_push_example SRCS test/test_example/test_bfs_push_example.cc) - add_test(test_bfs_pull_example SRCS test/test_example/test_bfs_pull_example.cc) - add_test(test_bfs_stream_example SRCS test/test_example/test_bfs_stream_example.cc) - add_test(test_bfs_father_example SRCS test/test_example/test_bfs_father_example.cc) # enable_testing() endif() diff --git a/docs/applications/bgl.rst b/docs/applications/bgl.rst index 2c4f17424..47fcaedcf 100644 --- a/docs/applications/bgl.rst +++ b/docs/applications/bgl.rst @@ -90,4 +90,4 @@ Finally, we could use a **VerticesBuilder** of GraphAr to write the results to n builder.Dump(); -.. _test_bgl_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_bgl_example.cc +.. _test_bgl_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bgl_example.cc diff --git a/docs/applications/out-of-core.rst b/docs/applications/out-of-core.rst index c96bff54b..8d8cb4f0c 100644 --- a/docs/applications/out-of-core.rst +++ b/docs/applications/out-of-core.rst @@ -107,16 +107,16 @@ Meanwhile, BFS could be implemented in a **push**-style which only traverses the In some cases, it is required to record the path of BFS, that is, to maintain each vertex's predecessor (also called *father*) in the traversing tree rather than only recording the distance. The implementation of BFS with recording fathers can be found at `test_bfs_father_example.cc`_. -.. _test_pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_pagerank_example.cc +.. _test_pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/pagerank_example.cc -.. _test_cc_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_cc_stream_example.cc +.. _test_cc_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/cc_stream_example.cc -.. _test_cc_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_cc_push_example.cc +.. _test_cc_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/cc_push_example.cc -.. _test_bfs_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_bfs_stream_example.cc +.. _test_bfs_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_stream_example.cc -.. _test_bfs_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_bfs_push_example.cc +.. _test_bfs_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_push_example.cc -.. _test_bfs_pull_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_bfs_pull_example.cc +.. _test_bfs_pull_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_pull_example.cc -.. _test_bfs_father_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_bfs_father_example.cc +.. _test_bfs_father_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_father_example.cc diff --git a/docs/user-guide/getting-started.rst b/docs/user-guide/getting-started.rst index 84a0ee924..0a30b4f87 100644 --- a/docs/user-guide/getting-started.rst +++ b/docs/user-guide/getting-started.rst @@ -194,6 +194,6 @@ Please refer to `more examples <../applications/out-of-core.html>`_ for learning .. _./edge/person_knows_person/ordered_by_source/offset/part0: https://github.com/GraphScope/gar-test/blob/main/ldbc_sample/csv/edge/person_knows_person/ordered_by_source/offset/part0 -.. _example program: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_construct_info_example.cc +.. _example program: https://github.com/alibaba/GraphAr/blob/main/examples/construct_info_example.cc -.. _test_pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/test/test_example/test_pagerank_example.cc +.. _test_pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/pagerank_example.cc diff --git a/test/test_example/test_bfs_father_example.cc b/examples/bfs_father_example.cc similarity index 82% rename from test/test_example/test_bfs_father_example.cc rename to examples/bfs_father_example.cc index 450440bc0..28507bd4c 100644 --- a/test/test_example/test_bfs_father_example.cc +++ b/examples/bfs_father_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -17,17 +17,15 @@ 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" #include "gar/writer/arrow_chunk_writer.h" #include "gar/writer/edges_builder.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_bfs_with_father_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -35,10 +33,10 @@ TEST_CASE("test_bfs_with_father_example") { // get the person vertices of graph std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -48,7 +46,7 @@ TEST_CASE("test_bfs_with_father_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::unordered_by_source); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -93,16 +91,16 @@ TEST_CASE("test_bfs_with_father_example") { // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(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 @@ -114,20 +112,20 @@ TEST_CASE("test_bfs_with_father_example") { father.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(father.type))); arrow::Int32Builder array_builder1; - REQUIRE(array_builder1.Reserve(num_vertices).ok()); - REQUIRE(array_builder1.AppendValues(distance).ok()); + assert(array_builder1.Reserve(num_vertices).ok()); + assert(array_builder1.AppendValues(distance).ok()); std::shared_ptr array1 = array_builder1.Finish().ValueOrDie(); arrays.push_back(array1); arrow::Int64Builder array_builder2; - REQUIRE(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) { - REQUIRE(array_builder2.AppendNull().ok()); + assert(array_builder2.AppendNull().ok()); } else { auto it = vertices.find(pre[i]); auto father_id = it.property("id").value(); - REQUIRE(array_builder2.Append(father_id).ok()); + assert(array_builder2.Append(father_id).ok()); } } std::shared_ptr array2 = array_builder2.Finish().ValueOrDie(); @@ -136,7 +134,7 @@ TEST_CASE("test_bfs_with_father_example") { auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); // construct a new graph src_label = "person"; @@ -148,14 +146,14 @@ TEST_CASE("test_bfs_with_father_example") { GAR_NAMESPACE::EdgeInfo new_edge_info(src_label, edge_label, dst_label, edge_chunk_size, src_chunk_size, dst_chunk_size, directed, version); - REQUIRE(new_edge_info + assert(new_edge_info .AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_source, GAR_NAMESPACE::FileType::CSV) .ok()); - REQUIRE(new_edge_info.IsValidated()); + assert(new_edge_info.IsValidated()); // save & dump - REQUIRE(!new_edge_info.Dump().has_error()); - REQUIRE(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); @@ -163,7 +161,7 @@ TEST_CASE("test_bfs_with_father_example") { if (i == root || pre[i] == -1) continue; GAR_NAMESPACE::builder::Edge e(pre[i], i); - REQUIRE(edges_builder.AddEdge(e).ok()); + assert(edges_builder.AddEdge(e).ok()); } - REQUIRE(edges_builder.Dump().ok()); + assert(edges_builder.Dump().ok()); } diff --git a/test/test_example/test_bfs_pull_example.cc b/examples/bfs_pull_example.cc similarity index 84% rename from test/test_example/test_bfs_pull_example.cc rename to examples/bfs_pull_example.cc index 511860600..2ab9da4d4 100644 --- a/test/test_example/test_bfs_pull_example.cc +++ b/examples/bfs_pull_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -16,16 +16,14 @@ 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" #include "gar/writer/arrow_chunk_writer.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_bfs_using_pull_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -33,10 +31,10 @@ TEST_CASE("test_bfs_using_pull_example") { // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -46,7 +44,7 @@ TEST_CASE("test_bfs_using_pull_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_dest); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -92,15 +90,15 @@ TEST_CASE("test_bfs_using_pull_example") { GAR_NAMESPACE::FileType::PARQUET); // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(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 @@ -109,12 +107,12 @@ TEST_CASE("test_bfs_using_pull_example") { schema_vector.push_back(arrow::field( bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type))); arrow::Int32Builder array_builder; - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(distance).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(distance).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } diff --git a/test/test_example/test_bfs_push_example.cc b/examples/bfs_push_example.cc similarity index 84% rename from test/test_example/test_bfs_push_example.cc rename to examples/bfs_push_example.cc index 7159efea0..8899b1d68 100644 --- a/test/test_example/test_bfs_push_example.cc +++ b/examples/bfs_push_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -16,16 +16,14 @@ 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" #include "gar/writer/arrow_chunk_writer.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_bfs_using_push_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -33,10 +31,10 @@ TEST_CASE("test_bfs_using_push_example") { // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -46,7 +44,7 @@ TEST_CASE("test_bfs_using_push_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_source); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -91,15 +89,15 @@ TEST_CASE("test_bfs_using_push_example") { GAR_NAMESPACE::FileType::PARQUET); // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(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 @@ -108,12 +106,12 @@ TEST_CASE("test_bfs_using_push_example") { schema_vector.push_back(arrow::field( bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type))); arrow::Int32Builder array_builder; - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(distance).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(distance).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } diff --git a/test/test_example/test_bfs_stream_example.cc b/examples/bfs_stream_example.cc similarity index 83% rename from test/test_example/test_bfs_stream_example.cc rename to examples/bfs_stream_example.cc index 8db4000ca..e3e992e03 100644 --- a/test/test_example/test_bfs_stream_example.cc +++ b/examples/bfs_stream_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -16,16 +16,14 @@ 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" #include "gar/writer/arrow_chunk_writer.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_bfs_using_stream_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -33,10 +31,10 @@ TEST_CASE("test_bfs_using_stream_example") { // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -46,7 +44,7 @@ TEST_CASE("test_bfs_using_stream_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::unordered_by_source); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -82,15 +80,15 @@ TEST_CASE("test_bfs_using_stream_example") { GAR_NAMESPACE::FileType::PARQUET); // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(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 @@ -99,12 +97,12 @@ TEST_CASE("test_bfs_using_stream_example") { schema_vector.push_back(arrow::field( bfs.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(bfs.type))); arrow::Int32Builder array_builder; - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(distance).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(distance).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } diff --git a/test/test_example/test_bgl_example.cc b/examples/bgl_example.cc similarity index 85% rename from test/test_example/test_bgl_example.cc rename to examples/bgl_example.cc index 5c2f09cbd..aa30ba1ff 100644 --- a/test/test_example/test_bgl_example.cc +++ b/examples/bgl_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -20,30 +20,28 @@ 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" #include "gar/writer/arrow_chunk_writer.h" #include "gar/writer/vertices_builder.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_bgl_cc_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; auto graph_info = GAR_NAMESPACE::GraphInfo::Load(path).value(); - REQUIRE(graph_info.GetAllVertexInfo().size() == 1); - REQUIRE(graph_info.GetAllEdgeInfo().size() == 1); + assert(graph_info.GetAllVertexInfo().size() == 1); + assert(graph_info.GetAllEdgeInfo().size() == 1); // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -53,7 +51,7 @@ TEST_CASE("test_bgl_cc_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_source); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -117,11 +115,11 @@ TEST_CASE("test_bgl_cc_example") { GAR_NAMESPACE::InfoVersion version(1); GAR_NAMESPACE::VertexInfo new_info(vertex_label, chunk_size, version, vertex_prefix); - REQUIRE(new_info.AddPropertyGroup(group).ok()); + assert(new_info.AddPropertyGroup(group).ok()); // dump new vertex info - REQUIRE(new_info.IsValidated()); - REQUIRE(new_info.Dump().status().ok()); - REQUIRE(new_info.Save("/tmp/cc_result.vertex.yml").ok()); + assert(new_info.IsValidated()); + assert(new_info.Dump().status().ok()); + assert(new_info.Save("/tmp/cc_result.vertex.yml").ok()); // construct vertices builder GAR_NAMESPACE::builder::VerticesBuilder builder(new_info, "/tmp/"); // add vertices to the builder @@ -131,22 +129,22 @@ TEST_CASE("test_bgl_cc_example") { vertex.AddProperty(cc.name, component[index[v]]); builder.AddVertex(vertex); } - REQUIRE(builder.GetNum() == num_vertices); + assert(builder.GetNum() == num_vertices); // dump the results through builder - REQUIRE(builder.Dump().ok()); + assert(builder.Dump().ok()); // method 2 for writing results: extend the original vertex info and write // results using writer extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(extend_info.Save("/tmp/person-new.vertex.yml").ok()); + assert(extend_info.IsValidated()); + assert(extend_info.Dump().status().ok()); + assert(extend_info.Save("/tmp/person-new.vertex.yml").ok()); // construct vertex property writer GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/"); // convert results to arrow::Table @@ -156,12 +154,12 @@ TEST_CASE("test_bgl_cc_example") { cc.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(cc.type))); arrow::MemoryPool* pool = arrow::default_memory_pool(); typename arrow::TypeTraits::BuilderType array_builder(pool); - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(component).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(component).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } diff --git a/test/test_example/test_cc_push_example.cc b/examples/cc_push_example.cc similarity index 87% rename from test/test_example/test_cc_push_example.cc rename to examples/cc_push_example.cc index 6eadc0a17..6fcff5c58 100644 --- a/test/test_example/test_cc_push_example.cc +++ b/examples/cc_push_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -17,16 +17,14 @@ 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" #include "gar/writer/arrow_chunk_writer.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_cc_using_push_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -34,10 +32,10 @@ TEST_CASE("test_cc_using_push_example") { // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -47,13 +45,13 @@ TEST_CASE("test_cc_using_push_example") { auto expect1 = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_source); - REQUIRE(!expect1.has_error()); + assert(!expect1.has_error()); auto& edges1 = std::get>(expect1.value()); auto expect2 = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_dest); - REQUIRE(!expect2.has_error()); + assert(!expect2.has_error()); auto& edges2 = std::get>(expect2.value()); @@ -126,15 +124,15 @@ TEST_CASE("test_cc_using_push_example") { GAR_NAMESPACE::FileType::PARQUET); // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(extend_info.Save("/tmp/person-new-cc-push.vertex.yml").ok()); + assert(extend_info.IsValidated()); + assert(extend_info.Dump().status().ok()); + assert(extend_info.Save("/tmp/person-new-cc-push.vertex.yml").ok()); // construct vertex property writer GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/"); // convert results to arrow::Table @@ -143,12 +141,12 @@ TEST_CASE("test_cc_using_push_example") { schema_vector.push_back(arrow::field( cc.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(cc.type))); arrow::Int64Builder array_builder; - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(component).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(component).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } diff --git a/test/test_example/test_cc_stream_example.cc b/examples/cc_stream_example.cc similarity index 85% rename from test/test_example/test_cc_stream_example.cc rename to examples/cc_stream_example.cc index 0f33c1288..7162fdfa6 100644 --- a/test/test_example/test_cc_stream_example.cc +++ b/examples/cc_stream_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -17,16 +17,14 @@ 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" #include "gar/writer/arrow_chunk_writer.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_cc_using_stream_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -34,10 +32,10 @@ TEST_CASE("test_cc_using_stream_example") { // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -47,7 +45,7 @@ TEST_CASE("test_cc_using_stream_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_source); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -93,15 +91,15 @@ TEST_CASE("test_cc_using_stream_example") { GAR_NAMESPACE::FileType::PARQUET); // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(extend_info.Save("/tmp/person-new.vertex.yml").ok()); + assert(extend_info.IsValidated()); + assert(extend_info.Dump().status().ok()); + assert(extend_info.Save("/tmp/person-new.vertex.yml").ok()); // construct vertex property writer GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/"); // convert results to arrow::Table @@ -110,12 +108,12 @@ TEST_CASE("test_cc_using_stream_example") { schema_vector.push_back(arrow::field( cc.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(cc.type))); arrow::Int64Builder array_builder; - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(component).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(component).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } diff --git a/examples/config.h b/examples/config.h new file mode 100644 index 000000000..23c6dc7bc --- /dev/null +++ b/examples/config.h @@ -0,0 +1,25 @@ +/** Copyright 2022 Alibaba Group Holding Limited. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include + +#ifndef TEST_CONFIG_H_ +#define TEST_CONFIG_H_ + +static const std::string TEST_DATA_DIR = // NOLINT + std::filesystem::path(__FILE__).parent_path().parent_path().string() + "/test/gar-test"; + +#endif // TEST_CONFIG_H_ diff --git a/test/test_example/test_construct_info_example.cc b/examples/construct_info_example.cc similarity index 68% rename from test/test_example/test_construct_info_example.cc rename to examples/construct_info_example.cc index 94ced9252..9b5ca20c9 100644 --- a/test/test_example/test_construct_info_example.cc +++ b/examples/construct_info_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -15,21 +15,19 @@ limitations under the License. #include "gar/graph_info.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_construct_info_example") { +int main(int argc, char* argv[]) { /*------------------construct graph info------------------*/ std::string name = "graph", prefix = "file:///tmp/"; GAR_NAMESPACE::InfoVersion version(1); GAR_NAMESPACE::GraphInfo graph_info(name, version, prefix); // validate - REQUIRE(graph_info.GetName() == name); - REQUIRE(graph_info.GetPrefix() == prefix); + assert(graph_info.GetName() == name); + assert(graph_info.GetPrefix() == prefix); const auto& vertex_infos = graph_info.GetAllVertexInfo(); const auto& edge_infos = graph_info.GetAllEdgeInfo(); - REQUIRE(vertex_infos.size() == 0); - REQUIRE(edge_infos.size() == 0); + assert(vertex_infos.size() == 0); + assert(edge_infos.size() == 0); /*------------------construct vertex info------------------*/ std::string vertex_label = "person", vertex_prefix = "vertex/person/"; @@ -37,9 +35,9 @@ TEST_CASE("test_construct_info_example") { GAR_NAMESPACE::VertexInfo vertex_info(vertex_label, chunk_size, version, vertex_prefix); // validate - REQUIRE(vertex_info.GetLabel() == vertex_label); - REQUIRE(vertex_info.GetChunkSize() == chunk_size); - REQUIRE(vertex_info.GetPropertyGroups().size() == 0); + assert(vertex_info.GetLabel() == vertex_label); + assert(vertex_info.GetChunkSize() == chunk_size); + assert(vertex_info.GetPropertyGroups().size() == 0); // construct properties and property groups GAR_NAMESPACE::Property id = { @@ -59,39 +57,39 @@ TEST_CASE("test_construct_info_example") { GAR_NAMESPACE::FileType::ORC); // add property groups to vertex info & validate - REQUIRE(vertex_info.AddPropertyGroup(group1).ok()); - REQUIRE(vertex_info.GetPropertyGroups()[0] == group1); - REQUIRE(vertex_info.ContainProperty(id.name)); - REQUIRE(!vertex_info.ContainProperty(firstName.name)); - REQUIRE(vertex_info.ContainPropertyGroup(group1)); - REQUIRE(!vertex_info.ContainPropertyGroup(group2)); - REQUIRE(vertex_info.IsPrimaryKey(id.name).value()); - REQUIRE(!vertex_info.IsPrimaryKey(gender.name).status().ok()); - REQUIRE(vertex_info.GetPropertyType(id.name).value() == id.type); - REQUIRE(vertex_info.GetFilePath(group1, 0).value() == + assert(vertex_info.AddPropertyGroup(group1).ok()); + assert(vertex_info.GetPropertyGroups()[0] == group1); + assert(vertex_info.ContainProperty(id.name)); + assert(!vertex_info.ContainProperty(firstName.name)); + assert(vertex_info.ContainPropertyGroup(group1)); + assert(!vertex_info.ContainPropertyGroup(group2)); + assert(vertex_info.IsPrimaryKey(id.name).value()); + 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/part0/chunk0"); // extend property groups & validate auto result = vertex_info.Extend(group2); - REQUIRE(result.status().ok()); + assert(result.status().ok()); vertex_info = result.value(); - REQUIRE(vertex_info.ContainProperty(firstName.name)); - REQUIRE(vertex_info.ContainPropertyGroup(group2)); - REQUIRE(vertex_info.GetPropertyGroup(firstName.name) == group2); - REQUIRE(!vertex_info.IsPrimaryKey(gender.name).value()); - REQUIRE(vertex_info.IsValidated()); + assert(vertex_info.ContainProperty(firstName.name)); + assert(vertex_info.ContainPropertyGroup(group2)); + assert(vertex_info.GetPropertyGroup(firstName.name) == group2); + assert(!vertex_info.IsPrimaryKey(gender.name).value()); + assert(vertex_info.IsValidated()); // save & dump - REQUIRE(!vertex_info.Dump().has_error()); - REQUIRE(vertex_info.Save("/tmp/person.vertex.yml").ok()); + assert(!vertex_info.Dump().has_error()); + assert(vertex_info.Save("/tmp/person.vertex.yml").ok()); /*------------------add vertex info to graph------------------*/ graph_info.AddVertex(vertex_info); - REQUIRE(graph_info.GetAllVertexInfo().size() == 1); - REQUIRE(graph_info.GetVertexInfo(vertex_label).status().ok()); - REQUIRE(graph_info.GetVertexPropertyGroup(vertex_label, id.name).value() == + assert(graph_info.GetAllVertexInfo().size() == 1); + assert(graph_info.GetVertexInfo(vertex_label).status().ok()); + assert(graph_info.GetVertexPropertyGroup(vertex_label, id.name).value() == group1); - REQUIRE( + assert( graph_info.GetVertexPropertyGroup(vertex_label, firstName.name).value() == group2); graph_info.AddVertexInfoPath("person.vertex.yml"); @@ -104,36 +102,36 @@ TEST_CASE("test_construct_info_example") { GAR_NAMESPACE::EdgeInfo edge_info( src_label, edge_label, dst_label, edge_chunk_size, src_chunk_size, dst_chunk_size, directed, version, edge_prefix); - REQUIRE(edge_info.GetSrcLabel() == src_label); - REQUIRE(edge_info.GetEdgeLabel() == edge_label); - REQUIRE(edge_info.GetDstLabel() == dst_label); - REQUIRE(edge_info.GetChunkSize() == edge_chunk_size); - REQUIRE(edge_info.GetSrcChunkSize() == src_chunk_size); - REQUIRE(edge_info.GetDstChunkSize() == dst_chunk_size); - REQUIRE(edge_info.IsDirected() == directed); + assert(edge_info.GetSrcLabel() == src_label); + assert(edge_info.GetEdgeLabel() == edge_label); + assert(edge_info.GetDstLabel() == dst_label); + assert(edge_info.GetChunkSize() == edge_chunk_size); + assert(edge_info.GetSrcChunkSize() == src_chunk_size); + assert(edge_info.GetDstChunkSize() == dst_chunk_size); + assert(edge_info.IsDirected() == directed); // add adj list & validate - REQUIRE(!edge_info.ContainAdjList( + assert(!edge_info.ContainAdjList( GAR_NAMESPACE::AdjListType::unordered_by_source)); - REQUIRE(edge_info + assert(edge_info .AddAdjList(GAR_NAMESPACE::AdjListType::unordered_by_source, GAR_NAMESPACE::FileType::PARQUET) .ok()); - REQUIRE(edge_info.ContainAdjList( + assert(edge_info.ContainAdjList( GAR_NAMESPACE::AdjListType::unordered_by_source)); - REQUIRE(edge_info + assert(edge_info .AddAdjList(GAR_NAMESPACE::AdjListType::ordered_by_dest, GAR_NAMESPACE::FileType::PARQUET) .ok()); - REQUIRE( + assert( edge_info.GetAdjListFileType(GAR_NAMESPACE::AdjListType::ordered_by_dest) .value() == GAR_NAMESPACE::FileType::PARQUET); - REQUIRE( + assert( edge_info .GetAdjListFilePath(0, 0, GAR_NAMESPACE::AdjListType::ordered_by_dest) .value() == "edge/person_knows_person/ordered_by_dest/adj_list/part0/chunk0"); - REQUIRE(edge_info + assert(edge_info .GetAdjListOffsetFilePath( 0, GAR_NAMESPACE::AdjListType::ordered_by_dest) .value() == @@ -146,71 +144,71 @@ TEST_CASE("test_construct_info_example") { std::vector property_vector_3 = {creationDate}; GAR_NAMESPACE::PropertyGroup group3(property_vector_3, GAR_NAMESPACE::FileType::PARQUET); - REQUIRE(!edge_info.ContainPropertyGroup( + assert(!edge_info.ContainPropertyGroup( group3, GAR_NAMESPACE::AdjListType::unordered_by_source)); - REQUIRE(!edge_info.ContainProperty(creationDate.name)); - REQUIRE(edge_info + assert(!edge_info.ContainProperty(creationDate.name)); + assert(edge_info .AddPropertyGroup(group3, GAR_NAMESPACE::AdjListType::unordered_by_source) .ok()); - REQUIRE(edge_info.ContainPropertyGroup( + assert(edge_info.ContainPropertyGroup( group3, GAR_NAMESPACE::AdjListType::unordered_by_source)); - REQUIRE(edge_info.ContainProperty(creationDate.name)); - REQUIRE( + assert(edge_info.ContainProperty(creationDate.name)); + assert( edge_info .GetPropertyGroups(GAR_NAMESPACE::AdjListType::unordered_by_source) .value()[0] == group3); - REQUIRE(edge_info + assert(edge_info .GetPropertyGroup(creationDate.name, GAR_NAMESPACE::AdjListType::unordered_by_source) .value() == group3); - REQUIRE(!edge_info + assert(!edge_info .GetPropertyGroup(creationDate.name, GAR_NAMESPACE::AdjListType::ordered_by_source) .status() .ok()); - REQUIRE( + assert( edge_info .GetPropertyFilePath( group3, GAR_NAMESPACE::AdjListType::unordered_by_source, 0, 0) .value() == "edge/person_knows_person/unordered_by_source/creationDate/part0/chunk0"); - REQUIRE(edge_info.GetPropertyType(creationDate.name).value() == + assert(edge_info.GetPropertyType(creationDate.name).value() == creationDate.type); - REQUIRE(edge_info.IsPrimaryKey(creationDate.name).value() == + assert(edge_info.IsPrimaryKey(creationDate.name).value() == creationDate.is_primary); // extend & validate auto res1 = edge_info.ExtendAdjList(GAR_NAMESPACE::AdjListType::ordered_by_source, GAR_NAMESPACE::FileType::PARQUET); - REQUIRE(res1.status().ok()); + assert(res1.status().ok()); edge_info = res1.value(); - REQUIRE(edge_info + assert(edge_info .GetAdjListFileType(GAR_NAMESPACE::AdjListType::ordered_by_source) .value() == GAR_NAMESPACE::FileType::PARQUET); auto res2 = edge_info.ExtendPropertyGroup( group3, GAR_NAMESPACE::AdjListType::ordered_by_source); - REQUIRE(res2.status().ok()); - REQUIRE(edge_info.IsValidated()); + assert(res2.status().ok()); + assert(edge_info.IsValidated()); // save & dump - REQUIRE(!edge_info.Dump().has_error()); - REQUIRE(edge_info.Save("/tmp/person_knows_person.edge.yml").ok()); + assert(!edge_info.Dump().has_error()); + assert(edge_info.Save("/tmp/person_knows_person.edge.yml").ok()); /*------------------add edge info to graph------------------*/ graph_info.AddEdge(edge_info); graph_info.AddEdgeInfoPath("person_knows_person.edge.yml"); - REQUIRE(graph_info.GetAllEdgeInfo().size() == 1); - REQUIRE( + assert(graph_info.GetAllEdgeInfo().size() == 1); + assert( graph_info.GetEdgeInfo(src_label, edge_label, dst_label).status().ok()); - REQUIRE(graph_info + assert(graph_info .GetEdgePropertyGroup( src_label, edge_label, dst_label, creationDate.name, GAR_NAMESPACE::AdjListType::unordered_by_source) .value() == group3); - REQUIRE(graph_info.IsValidated()); + assert(graph_info.IsValidated()); // save & dump - REQUIRE(!graph_info.Dump().has_error()); - REQUIRE(graph_info.Save("/tmp/ldbc_sample.graph.yml").ok()); + assert(!graph_info.Dump().has_error()); + assert(graph_info.Save("/tmp/ldbc_sample.graph.yml").ok()); } diff --git a/examples/pagerank/CMakeLists.txt b/examples/pagerank/CMakeLists.txt deleted file mode 100644 index 775cc5434..000000000 --- a/examples/pagerank/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: -if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") - cmake_policy(SET CMP0135 NEW) -endif() - -project(Pagerank) - -find_package(Threads REQUIRED) -find_package(gar REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -include(apache-arrow) -build_arrow() - -include_directories(BEFORE SYSTEM ${ARROW_INCLUDE_DIR}) - -include_directories(${GAR_INCLUDE_DIRS}) - -add_executable(pagerank pagerank.cc) -target_compile_features(pagerank PRIVATE cxx_std_17) -target_link_libraries(pagerank PRIVATE ${GAR_LIBRARIES}) \ No newline at end of file diff --git a/examples/pagerank/README.rst b/examples/pagerank/README.rst deleted file mode 100644 index ef143903c..000000000 --- a/examples/pagerank/README.rst +++ /dev/null @@ -1,60 +0,0 @@ -A PageRank Example -------------------- - -This example demonstrates how to compute the PageRank of an input graph using GAR and write back the values as a new property of the graph. - -Integrate GAR -^^^^^^^^^^^^^^^^^^ - -To include GAR C++ library, add the following commands in the CMakeLists.txt: - -.. code-block:: cmake - - find_package(gar REQUIRED) - include_directories(${GAR_INCLUDE_DIRS}) - target_link_libraries(pagerank PRIVATE ${GAR_LIBRARIES}) - - -Build the Project -^^^^^^^^^^^^^^^^^^ - -.. code-block:: shell - - mkdir build && cd build - cmake .. - make - - -Prepare the input graph -^^^^^^^^^^^^^^^^^^^^^^^^ - -Copy the ldbc_sample graph from test - -.. code-block:: shell - - copy -r ${project_dir}/test/gar-test/ldbc_sample /tmp/ - - -Run the example -^^^^^^^^^^^^^^^^ - -.. code-block:: shell - - ./pagerank - -The output looks like: - -.. code-block:: shell - - num_vertices: 903 - iter 0 - iter 1 - iter 2 - iter 3 - iter 4 - iter 5 - iter 6 - iter 7 - iter 8 - iter 9 - Done diff --git a/examples/pagerank/cmake/apache-arrow.cmake b/examples/pagerank/cmake/apache-arrow.cmake deleted file mode 100644 index 633abd87a..000000000 --- a/examples/pagerank/cmake/apache-arrow.cmake +++ /dev/null @@ -1,92 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# This cmake file is referred and derived from -# https://github.com/apache/arrow/blob/master/matlab/CMakeLists.txt - - -# Build the Arrow C++ libraries. -function(build_arrow) - set(one_value_args) - set(multi_value_args) - - cmake_parse_arguments(ARG - "${options}" - "${one_value_args}" - "${multi_value_args}" - ${ARGN}) - if (ARG_UNPARSED_ARGUMENTS) - message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}") - endif () - - find_package(Threads) - # If Arrow needs to be built, the default location will be within the build tree. - set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-prefix") - - set(ARROW_STATIC_LIBRARY_DIR "${ARROW_PREFIX}/lib") - - set(ARROW_STATIC_LIB_FILENAME - "${CMAKE_STATIC_LIBRARY_PREFIX}arrow${CMAKE_STATIC_LIBRARY_SUFFIX}") - set(ARROW_STATIC_LIB "${ARROW_STATIC_LIBRARY_DIR}/${ARROW_STATIC_LIB_FILENAME}") - set(PARQUET_STATIC_LIB_FILENAME - "${CMAKE_STATIC_LIBRARY_PREFIX}parquet${CMAKE_STATIC_LIBRARY_SUFFIX}") - set(PARQUET_STATIC_LIB "${ARROW_STATIC_LIBRARY_DIR}/${PARQUET_STATIC_LIB_FILENAME}" CACHE INTERNAL "parquet lib") - set(ARROW_BUNDLED_DEPS_STATIC_LIB_FILENAME - "${CMAKE_STATIC_LIBRARY_PREFIX}arrow_bundled_dependencies${CMAKE_STATIC_LIBRARY_SUFFIX}") - set(ARROW_BUNDLED_DEPS_STATIC_LIB - "${ARROW_STATIC_LIBRARY_DIR}/${ARROW_BUNDLED_DEPS_STATIC_LIB_FILENAME}" CACHE INTERNAL "bundled deps lib") - - set(ARROW_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-build") - set(ARROW_CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${ARROW_PREFIX}" - "-DARROW_BUILD_STATIC=ON" "-DARROW_BUILD_SHARED=OFF" - "-DARROW_DEPENDENCY_SOURCE=BUNDLED" "-DARROW_DEPENDENCY_USE_SHARED=OFF" - "-DCMAKE_INSTALL_LIBDIR=lib" "-Dxsimd_SOURCE=BUNDLED" - "-DARROW_PARQUET=ON" "-DARROW_WITH_RE2=OFF" - "-DARROW_WITH_UTF8PROC=OFF" "-DARROW_WITH_RE2=OFF" - "-DARROW_FILESYSTEM=ON" "-DARROW_CSV=ON" "-DARROW_PYTHON=OFF" - "-DARROW_BUILD_BENCHMAKRS=OFF" "-DARROW_BUILD_TESTS=OFF" - "-DARROW_BUILD_INTEGRATION=OFF" "-DBoost_SOURCE=BUNDLED" - "-DARROW_ORC=ON" "-DARROW_COMPUTE=ON" - "-DARROW_DATASET=ON" "-DARROW_WITH_SNAPPY=OFF" "-DARROW_WITH_LZ4=OFF" - "-DARROW_WITH_ZSTD=ON" "-DARROW_WITH_ZLIB=OFF" "-DARROW_WITH_BROTLI=OFF" "-DARROW_WITH_BZ2=OFF") - - set(ARROW_INCLUDE_DIR "${ARROW_PREFIX}/include" CACHE INTERNAL "arrow include directory") - set(ARROW_BUILD_BYPRODUCTS "${ARROW_STATIC_LIB}" "${PARQUET_STATIC_LIB}") - - include(ExternalProject) - externalproject_add(arrow_ep - URL https://www.apache.org/dyn/closer.lua?action=download&filename=arrow/arrow-9.0.0/apache-arrow-9.0.0.tar.gz - SOURCE_SUBDIR cpp - BINARY_DIR "${ARROW_BINARY_DIR}" - CMAKE_ARGS "${ARROW_CMAKE_ARGS}" - BUILD_BYPRODUCTS "${ARROW_BUILD_BYPRODUCTS}") - - set(ARROW_LIBRARY_TARGET arrow_static) - set(PARQUET_LIBRARY_TARGET parquet_static) - - file(MAKE_DIRECTORY "${ARROW_INCLUDE_DIR}") - add_library(${ARROW_LIBRARY_TARGET} STATIC IMPORTED) - add_library(${PARQUET_LIBRARY_TARGET} STATIC IMPORTED) - set_target_properties(${ARROW_LIBRARY_TARGET} - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ARROW_INCLUDE_DIR} - IMPORTED_LOCATION ${ARROW_STATIC_LIB}) - set_target_properties(${PARQUET_LIBRARY_TARGET} - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ARROW_INCLUDE_DIR} - IMPORTED_LOCATION ${PARQUET_STATIC_LIB}) - - add_dependencies(${ARROW_LIBRARY_TARGET} arrow_ep) -endfunction() diff --git a/examples/pagerank/pagerank.cc b/examples/pagerank/pagerank.cc deleted file mode 100644 index 9116fecfc..000000000 --- a/examples/pagerank/pagerank.cc +++ /dev/null @@ -1,116 +0,0 @@ -/** Copyright 2022 Alibaba Group Holding Limited. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include -#include - -#include "arrow/api.h" -#include "arrow/filesystem/api.h" - -#include "gar/graph.h" -#include "gar/graph_info.h" -#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 = "/tmp/ldbc_sample/parquet/ldbc_sample.graph.yml"; - auto graph_info = GraphArchive::GraphInfo::Load(path).value(); - - // construct vertices collection - std::string label = "person"; - auto maybe_vertices = - GraphArchive::ConstructVerticesCollection(graph_info, label); - auto& vertices = maybe_vertices.value(); - int num_vertices = vertices.size(); - std::cout << "num_vertices: " << num_vertices << std::endl; - - // construct edges collection - std::string src_label = "person", edge_label = "knows", dst_label = "person"; - auto maybe_edges = GraphArchive::ConstructEdgesCollection( - graph_info, src_label, edge_label, dst_label, - GraphArchive::AdjListType::ordered_by_source); - auto& edges = std::get>(maybe_edges.value()); - - // run pagerank algorithm - const double damping = 0.85; - const int max_iters = 10; - std::vector pr_curr(num_vertices); - std::vector pr_next(num_vertices); - std::vector out_degree(num_vertices); - for (GraphArchive::IdType i = 0; i < num_vertices; i++) { - pr_curr[i] = 1 / static_cast(num_vertices); - pr_next[i] = 0; - out_degree[i] = 0; - } - auto it_begin = edges.begin(), it_end = edges.end(); - for (auto it = it_begin; it != it_end; ++it) { - GraphArchive::IdType src = it.source(); - out_degree[src]++; - } - for (int iter = 0; iter < max_iters; iter++) { - std::cout << "iter " << iter << std::endl; - for (auto it = it_begin; it != it_end; ++it) { - GraphArchive::IdType src = it.source(), dst = it.destination(); - pr_next[dst] += pr_curr[src] / out_degree[src]; - } - for (GraphArchive::IdType i = 0; i < num_vertices; i++) { - pr_next[i] = damping * pr_next[i] + - (1 - damping) * (1 / static_cast(num_vertices)); - if (out_degree[i] == 0) - pr_next[i] += damping * pr_curr[i]; - pr_curr[i] = pr_next[i]; - pr_next[i] = 0; - } - } - - // extend the original vertex info and write results to gar using writer - // construct property group - GraphArchive::Property pagerank = { - "pagerank", GraphArchive::DataType(GraphArchive::Type::DOUBLE), false}; - std::vector property_vector = {pagerank}; - GraphArchive::PropertyGroup group(property_vector, - GraphArchive::FileType::PARQUET); - // extend the vertex_info - auto maybe_vertex_info = graph_info.GetVertexInfo(label); - auto vertex_info = maybe_vertex_info.value(); - auto maybe_extend_info = vertex_info.Extend(group); - 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-pagerank.vertex.yml").ok()); - // construct vertex property writer - GraphArchive::VertexPropertyWriter writer(extend_info, "/tmp/"); - // convert results to arrow::Table - std::vector> arrays; - std::vector> schema_vector; - schema_vector.push_back(arrow::field( - pagerank.name, - GraphArchive::DataType::DataTypeToArrowDataType(pagerank.type))); - arrow::DoubleBuilder array_builder; - assert(array_builder.Reserve(num_vertices).ok()); - assert(array_builder.AppendValues(pr_curr).ok()); - std::shared_ptr array = array_builder.Finish().ValueOrDie(); - arrays.push_back(array); - auto schema = std::make_shared(schema_vector); - std::shared_ptr table = arrow::Table::Make(schema, arrays); - // dump the results through writer - assert(writer.WriteTable(table, group, 0).ok()); - - std::cout << "Done" << std::endl; - return 0; -} diff --git a/test/test_example/test_pagerank_example.cc b/examples/pagerank_example.cc similarity index 85% rename from test/test_example/test_pagerank_example.cc rename to examples/pagerank_example.cc index 9b9935fc0..042439196 100644 --- a/test/test_example/test_pagerank_example.cc +++ b/examples/pagerank_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software +Unless assertd by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and @@ -17,16 +17,14 @@ limitations under the License. #include "arrow/api.h" #include "arrow/filesystem/api.h" -#include "../config.h" +#include "config.h" #include "gar/graph.h" #include "gar/graph_info.h" #include "gar/reader/arrow_chunk_reader.h" #include "gar/writer/arrow_chunk_writer.h" -#define CATCH_CONFIG_MAIN -#include -TEST_CASE("test_pagerank_example") { +int main(int argc, char* argv[]) { // read file and construct graph info std::string path = TEST_DATA_DIR + "/ldbc_sample/parquet/ldbc_sample.graph.yml"; @@ -34,10 +32,10 @@ TEST_CASE("test_pagerank_example") { // construct vertices collection std::string label = "person"; - REQUIRE(graph_info.GetVertexInfo(label).status().ok()); + assert(graph_info.GetVertexInfo(label).status().ok()); auto maybe_vertices = GAR_NAMESPACE::ConstructVerticesCollection(graph_info, label); - REQUIRE(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; @@ -47,7 +45,7 @@ TEST_CASE("test_pagerank_example") { auto maybe_edges = GAR_NAMESPACE::ConstructEdgesCollection( graph_info, src_label, edge_label, dst_label, GAR_NAMESPACE::AdjListType::ordered_by_source); - REQUIRE(!maybe_edges.has_error()); + assert(!maybe_edges.has_error()); auto& edges = std::get>(maybe_edges.value()); @@ -92,15 +90,15 @@ TEST_CASE("test_pagerank_example") { GAR_NAMESPACE::FileType::PARQUET); // extend the vertex_info auto maybe_vertex_info = graph_info.GetVertexInfo(label); - REQUIRE(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); - REQUIRE(maybe_extend_info.status().ok()); + assert(maybe_extend_info.status().ok()); auto extend_info = maybe_extend_info.value(); // dump the extened vertex info - REQUIRE(extend_info.IsValidated()); - REQUIRE(extend_info.Dump().status().ok()); - REQUIRE(extend_info.Save("/tmp/person-new-pagerank.vertex.yml").ok()); + assert(extend_info.IsValidated()); + assert(extend_info.Dump().status().ok()); + assert(extend_info.Save("/tmp/person-new-pagerank.vertex.yml").ok()); // construct vertex property writer GAR_NAMESPACE::VertexPropertyWriter writer(extend_info, "/tmp/"); // convert results to arrow::Table @@ -110,12 +108,12 @@ TEST_CASE("test_pagerank_example") { pagerank.name, GAR_NAMESPACE::DataType::DataTypeToArrowDataType(pagerank.type))); arrow::DoubleBuilder array_builder; - REQUIRE(array_builder.Reserve(num_vertices).ok()); - REQUIRE(array_builder.AppendValues(pr_curr).ok()); + assert(array_builder.Reserve(num_vertices).ok()); + assert(array_builder.AppendValues(pr_curr).ok()); std::shared_ptr array = array_builder.Finish().ValueOrDie(); arrays.push_back(array); auto schema = std::make_shared(schema_vector); std::shared_ptr table = arrow::Table::Make(schema, arrays); // dump the results through writer - REQUIRE(writer.WriteTable(table, group, 0).ok()); + assert(writer.WriteTable(table, group, 0).ok()); } From 1d09b4d100ac9e50ac8bb13b56857889f576a6cf Mon Sep 17 00:00:00 2001 From: Diwen Zhu Date: Mon, 19 Dec 2022 19:57:59 +0800 Subject: [PATCH 3/6] add cmake exmaple option --- CMakeLists.txt | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c32d2b12..0a11dc989 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ project(graph-archive LANGUAGES C CXX VERSION ${GAR_VERSION}) option(NAMESPACE "User specific namespace, default if GraphArchive" OFF) option(BUILD_TESTS "Build unit test" OFF) +option(BUILD_EXAMPLES "Build examples" OFF) if (NAMESPACE) add_definitions(-DGAR_NAMESPACE=${NAMESPACE}) @@ -194,18 +195,20 @@ build_gar() # ------------------------------------------------------------------------------ # build example # ------------------------------------------------------------------------------ -find_package(Boost REQUIRED COMPONENTS graph) - -file(GLOB EXAMPLE_FILES RELATIVE "${PROJECT_SOURCE_DIR}/examples" "${PROJECT_SOURCE_DIR}/examples/*.cc") - foreach(f ${EXAMPLE_FILES}) - string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${f}) - set(E_NAME ${CMAKE_MATCH_1}) - message(STATUS "Found example - " ${E_NAME}) - add_executable(${E_NAME} examples/${E_NAME}.cc) - target_include_directories(${E_NAME} PRIVATE examples ${PROJECT_SOURCE_DIR}/include $) - include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - target_link_libraries(${E_NAME} PRIVATE gar) - endforeach() +if (BUILD_EXAMPLES) + find_package(Boost REQUIRED COMPONENTS graph) + + file(GLOB EXAMPLE_FILES RELATIVE "${PROJECT_SOURCE_DIR}/examples" "${PROJECT_SOURCE_DIR}/examples/*.cc") + foreach(f ${EXAMPLE_FILES}) + string(REGEX MATCH "^(.*)\\.[^.]*$" dummy ${f}) + set(E_NAME ${CMAKE_MATCH_1}) + message(STATUS "Found example - " ${E_NAME}) + add_executable(${E_NAME} examples/${E_NAME}.cc) + target_include_directories(${E_NAME} PRIVATE examples ${PROJECT_SOURCE_DIR}/include $) + include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) + target_link_libraries(${E_NAME} PRIVATE gar ${Boost_LIBRARIES}) + endforeach() +endif() # ------------------------------------------------------------------------------ # Install From c1596c30b52fec6f3284a88d824d670c1933b4a2 Mon Sep 17 00:00:00 2001 From: Diwen Zhu Date: Tue, 20 Dec 2022 10:25:21 +0800 Subject: [PATCH 4/6] minor fix --- examples/bfs_father_example.cc | 2 +- examples/bfs_pull_example.cc | 2 +- examples/bfs_push_example.cc | 2 +- examples/bfs_stream_example.cc | 2 +- examples/bgl_example.cc | 2 +- examples/cc_push_example.cc | 2 +- examples/cc_stream_example.cc | 2 +- examples/construct_info_example.cc | 2 +- examples/pagerank_example.cc | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/bfs_father_example.cc b/examples/bfs_father_example.cc index 28507bd4c..ecf9f6c2d 100644 --- a/examples/bfs_father_example.cc +++ b/examples/bfs_father_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/bfs_pull_example.cc b/examples/bfs_pull_example.cc index 2ab9da4d4..267ea67bf 100644 --- a/examples/bfs_pull_example.cc +++ b/examples/bfs_pull_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/bfs_push_example.cc b/examples/bfs_push_example.cc index 8899b1d68..bbe28378d 100644 --- a/examples/bfs_push_example.cc +++ b/examples/bfs_push_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/bfs_stream_example.cc b/examples/bfs_stream_example.cc index e3e992e03..0e2880926 100644 --- a/examples/bfs_stream_example.cc +++ b/examples/bfs_stream_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/bgl_example.cc b/examples/bgl_example.cc index aa30ba1ff..a1ff634f5 100644 --- a/examples/bgl_example.cc +++ b/examples/bgl_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/cc_push_example.cc b/examples/cc_push_example.cc index 6fcff5c58..587d171ff 100644 --- a/examples/cc_push_example.cc +++ b/examples/cc_push_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/cc_stream_example.cc b/examples/cc_stream_example.cc index 7162fdfa6..06baa4a64 100644 --- a/examples/cc_stream_example.cc +++ b/examples/cc_stream_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/construct_info_example.cc b/examples/construct_info_example.cc index 9b5ca20c9..b3d3a880b 100644 --- a/examples/construct_info_example.cc +++ b/examples/construct_info_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and diff --git a/examples/pagerank_example.cc b/examples/pagerank_example.cc index 042439196..0df5a4b0e 100644 --- a/examples/pagerank_example.cc +++ b/examples/pagerank_example.cc @@ -6,7 +6,7 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -Unless assertd by applicable law or agreed to in writing, software +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and From 8350fa226674e13d4c7f65594ff34fcd68fefcfe Mon Sep 17 00:00:00 2001 From: Diwen Zhu Date: Tue, 20 Dec 2022 10:27:32 +0800 Subject: [PATCH 5/6] fix filename --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index beba6be2c..da3816357 100644 --- a/README.rst +++ b/README.rst @@ -209,7 +209,7 @@ target linked with GraphAr C++ shared library. target_compile_features(my_example PRIVATE cxx_std_17) target_link_libraries(my_example PRIVATE ${GAR_LIBRARIES}) -Please refer to `examples/pagerank` for details. +Please refer to `examples/pagerank_example.cc` for details. Contributing to GraphAr ----------------------- From c522cb2de62be516c014e37f67cd4322536d5aae Mon Sep 17 00:00:00 2001 From: Diwen Zhu Date: Tue, 20 Dec 2022 11:14:40 +0800 Subject: [PATCH 6/6] fix filenames in doc --- docs/applications/bgl.rst | 4 ++-- docs/applications/out-of-core.rst | 24 ++++++++++++------------ docs/user-guide/getting-started.rst | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/applications/bgl.rst b/docs/applications/bgl.rst index 47fcaedcf..c7e2bc70e 100644 --- a/docs/applications/bgl.rst +++ b/docs/applications/bgl.rst @@ -5,7 +5,7 @@ The `Boost Graph Library (BGL) `_. -The source code of CC based on BGL can be found at `test_bgl_example.cc`_. In this program, the graph information file is first read to get the metadata: +The source code of CC based on BGL can be found at `bgl_example.cc`_. In this program, the graph information file is first read to get the metadata: .. code:: C++ @@ -90,4 +90,4 @@ Finally, we could use a **VerticesBuilder** of GraphAr to write the results to n builder.Dump(); -.. _test_bgl_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bgl_example.cc +.. _bgl_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bgl_example.cc diff --git a/docs/applications/out-of-core.rst b/docs/applications/out-of-core.rst index 8d8cb4f0c..10271cbda 100644 --- a/docs/applications/out-of-core.rst +++ b/docs/applications/out-of-core.rst @@ -14,7 +14,7 @@ These algorithms represent for different compute patterns and are usually buildi PageRank ------------------------ -`PageRank (PR) `_ is an algorithm used by Google Search to rank web pages in their search engine results. The source code of PageRank based on GraphAr located at `test_pagerank_example.cc`_, and the explanations can be found in the `Getting Started <../user-guide/getting-started.html#a-pagerank-example>`_ page. +`PageRank (PR) `_ is an algorithm used by Google Search to rank web pages in their search engine results. The source code of PageRank based on GraphAr located at `pagerank_example.cc`_, and the explanations can be found in the `Getting Started <../user-guide/getting-started.html#a-pagerank-example>`_ page. Connected Components ------------------------ @@ -54,7 +54,7 @@ This algorithm can be implemented based on streaming the edges via GraphAr's rea if (!flag) break; } -The file `test_cc_stream_example.cc`_ located inside the source tree contains the complete implementation for this algorithm. Also, we can only process active vertices (the vertices which are updated in the last iteration) and the corresponding edges, since an inactive vertex does not need to update its neighbors for this iteration. Please refer to `test_cc_push_example.cc`_ for the complete code. +The file `cc_stream_example.cc`_ located inside the source tree contains the complete implementation for this algorithm. Also, we can only process active vertices (the vertices which are updated in the last iteration) and the corresponding edges, since an inactive vertex does not need to update its neighbors for this iteration. Please refer to `cc_push_example.cc`_ for the complete code. .. tip:: @@ -96,27 +96,27 @@ An out-of-core BFS algorithm could be implemented based on streaming the graph d if (count == 0) break; } -The above algorithm is implemented based on streaming all edges for each iteration, the source code can be found at `test_bfs_stream_example.cc`_. +The above algorithm is implemented based on streaming all edges for each iteration, the source code can be found at `bfs_stream_example.cc`_. -Meanwhile, BFS could be implemented in a **push**-style which only traverses the edges that from active vertices for each iteration, which is typically more efficient on real-world graphs. This implementation can be found at `test_bfs_push_example.cc`_. Similarly, we provide a BFS implementation in a **pull**-style which only traverses the edges that lead to not visited vertices (i.e., the vertices that have not been traversed), as shown in `test_bfs_pull_example.cc`_. +Meanwhile, BFS could be implemented in a **push**-style which only traverses the edges that from active vertices for each iteration, which is typically more efficient on real-world graphs. This implementation can be found at `bfs_push_example.cc`_. Similarly, we provide a BFS implementation in a **pull**-style which only traverses the edges that lead to not visited vertices (i.e., the vertices that have not been traversed), as shown in `bfs_pull_example.cc`_. .. tip:: In common cases of graph processing, the **push**-style is more efficient when the set of active vertices is very sparse, while the **pull**-style fits when it is dense. -In some cases, it is required to record the path of BFS, that is, to maintain each vertex's predecessor (also called *father*) in the traversing tree rather than only recording the distance. The implementation of BFS with recording fathers can be found at `test_bfs_father_example.cc`_. +In some cases, it is required to record the path of BFS, that is, to maintain each vertex's predecessor (also called *father*) in the traversing tree rather than only recording the distance. The implementation of BFS with recording fathers can be found at `bfs_father_example.cc`_. -.. _test_pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/pagerank_example.cc +.. _pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/pagerank_example.cc -.. _test_cc_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/cc_stream_example.cc +.. _cc_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/cc_stream_example.cc -.. _test_cc_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/cc_push_example.cc +.. _cc_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/cc_push_example.cc -.. _test_bfs_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_stream_example.cc +.. _bfs_stream_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_stream_example.cc -.. _test_bfs_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_push_example.cc +.. _bfs_push_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_push_example.cc -.. _test_bfs_pull_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_pull_example.cc +.. _bfs_pull_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_pull_example.cc -.. _test_bfs_father_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_father_example.cc +.. _bfs_father_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/bfs_father_example.cc diff --git a/docs/user-guide/getting-started.rst b/docs/user-guide/getting-started.rst index 0a30b4f87..83f1b61bf 100644 --- a/docs/user-guide/getting-started.rst +++ b/docs/user-guide/getting-started.rst @@ -174,7 +174,7 @@ A PageRank Example `````````````````` Here we will go through an example of out-of-core graph analytic algorithms based on GAR using PageRank as an example. Please look `here `_ if you want a detailed explanation of the PageRank algorithm. -The source code can be found at `test_pagerank_example.cc`_. In this program, we first read the graph information file to get its metadata; and then, construct the vertex collection as well as the edge collection as the handle to access the graph; next, a PageRank algorithm is implemented with data for vertices cached in memory while edges are streamed through disk I/O; finally, we extend the vertex information with type "person" to include a new property named "pagerank" (a new vertex information file named *person-new-pagerank.vertex.yml* is saved) and uses the **VerticesBuilder** to write the results to new generated files. +The source code can be found at `pagerank_example.cc`_. In this program, we first read the graph information file to get its metadata; and then, construct the vertex collection as well as the edge collection as the handle to access the graph; next, a PageRank algorithm is implemented with data for vertices cached in memory while edges are streamed through disk I/O; finally, we extend the vertex information with type "person" to include a new property named "pagerank" (a new vertex information file named *person-new-pagerank.vertex.yml* is saved) and uses the **VerticesBuilder** to write the results to new generated files. Please refer to `more examples <../applications/out-of-core.html>`_ for learning about other scenarios of working with GraphAr. @@ -196,4 +196,4 @@ Please refer to `more examples <../applications/out-of-core.html>`_ for learning .. _example program: https://github.com/alibaba/GraphAr/blob/main/examples/construct_info_example.cc -.. _test_pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/pagerank_example.cc +.. _pagerank_example.cc: https://github.com/alibaba/GraphAr/blob/main/examples/pagerank_example.cc