GitHub user Agwave added a comment to the discussion: fail to run example 
high_level_writer_example

CMakeLists.txt
```
cmake_minimum_required(VERSION 3.0)
project(GrapharExample)

# 查找Boost库
find_package(Boost REQUIRED COMPONENTS graph)
include_directories(${Boost_INCLUDE_DIRS})

# 查找Arrow库
find_package(Arrow REQUIRED)
include_directories(${Arrow_INCLUDE_DIRS})

# 指定gar库的头文件目录
include_directories(/usr/local/include/gar)

# 指定gar库的库文件目录
link_directories(/usr/local/lib/gar)

# 添加你的执行文件
add_executable(graphar-example main-temp.cpp)

# 链接所需的库
target_link_libraries(graphar-example
        ${Boost_LIBRARIES}
        ${Arrow_LIBRARIES}
        gar
        )
```

person.vertex.yml
```
label: person
chunk_size: 100
prefix: vertex/person/
property_groups:
  - properties:
      - name: id
        data_type: int64
        is_primary: true
    file_type: csv
  - properties:
      - name: firstName
        data_type: string
        is_primary: false
      - name: lastName
        data_type: string
        is_primary: false
      - name: gender
        data_type: string
        is_primary: false
    file_type: csv
version: gar/v1

```

person_knows_person.edge.yml
```
src_label: person
edge_label: knows
dst_label: person
chunk_size: 1024
src_chunk_size: 100
dst_chunk_size: 100
directed: false
prefix: edge/person_knows_person/
adj_lists:
  - ordered: true
    aligned_by: src
    file_type: csv
    property_groups:
      - properties:
          - name: creationDate
            data_type: string
            is_primary: false
        file_type: csv
version: gar/v1
```

main-temp.cpp
```
#include <iostream>

#include "arrow/api.h"
#include "arrow/filesystem/api.h"

#include "./config.h"
#include "gar/api.h"
#include "gar/writer/edges_builder.h"
#include "gar/writer/vertices_builder.h"

void vertices_builder() {
    // construct vertices builder
    std::string vertex_meta_file = 
"/home/chenyinbo/cppject/graphar-example/person.vertex.yml";
    auto vertex_meta = graphar::Yaml::LoadFile(vertex_meta_file).value();
    auto vertex_info = graphar::VertexInfo::Load(vertex_meta).value();
    graphar::IdType start_index = 0;
    graphar::builder::VerticesBuilder builder(vertex_info, 
"/home/chenyinbo/cppject/graphar-example/generate-temp/", start_index);

    // set validate level
    builder.SetValidateLevel(graphar::ValidateLevel::strong_validate);

    // prepare vertex data
    int vertex_count = 3;
    std::vector<std::string> property_names = {"id", "firstName", "lastName",
                                               "gender"};
    std::vector<int64_t> id = {0, 1, 2};
    std::vector<std::string> firstName = {"John", "Jane", "Alice"};
    std::vector<std::string> lastName = {"Smith", "Doe", "Wonderland"};
    std::vector<std::string> gender = {"male", "famale", "famale"};

    // add vertices
    for (int i = 0; i < vertex_count; i++) {
        graphar::builder::Vertex v;
        v.AddProperty(property_names[0], id[i]);
        v.AddProperty(property_names[1], firstName[i]);
        v.AddProperty(property_names[2], lastName[i]);
        v.AddProperty(property_names[3], gender[i]);
        ASSERT(builder.AddVertex(v).ok());
    }

    // dump
    ASSERT(builder.GetNum() == vertex_count);
    std::cout << "vertex_count=" << builder.GetNum() << std::endl;
    ASSERT(builder.Dump().ok());
    std::cout << "dump vertices collection successfully!" << std::endl;

    // clear vertices
    builder.Clear();
    ASSERT(builder.GetNum() == 0);
}

void edges_builder() {
    // construct edges builder
    std::string edge_meta_file = 
"/home/chenyinbo/cppject/graphar-example/person_knows_person.edge.yml";
    auto edge_meta = graphar::Yaml::LoadFile(edge_meta_file).value();
    auto edge_info = graphar::EdgeInfo::Load(edge_meta).value();
    auto vertex_count = 3;
    graphar::builder::EdgesBuilder builder(
            edge_info, 
"/home/chenyinbo/cppject/graphar-example/generate-temp/", 
graphar::AdjListType::ordered_by_dest, vertex_count);

    // set validate level
    builder.SetValidateLevel(graphar::ValidateLevel::strong_validate);

    // prepare edge data
    int edge_count = 4;
    std::vector<std::string> property_names = {"creationDate"};
    std::vector<int64_t> src = {1, 0, 0, 2};
    std::vector<int64_t> dst = {0, 1, 2, 1};
    std::vector<std::string> creationDate = {"2010-01-01", "2011-01-01",
                                             "2012-01-01", "2013-01-01"};

    // add edges
    for (int i = 0; i < edge_count; i++) {
        graphar::builder::Edge e(src[i], dst[i]);
        e.AddProperty("creationDate", creationDate[i]);
        ASSERT(builder.AddEdge(e).ok());
    }

    // dump
    ASSERT(builder.GetNum() == edge_count);
    std::cout << "edge_count=" << builder.GetNum() << std::endl;
    ASSERT(builder.Dump().ok());
    std::cout << "dump edges collection successfully!" << std::endl;

    // clear edges
    builder.Clear();
    ASSERT(builder.GetNum() == 0);
}

int main(int argc, char* argv[]) {
    // vertices builder
    std::cout << "Vertices builder" << std::endl;
    std::cout << "-------------------" << std::endl;
    vertices_builder();
    std::cout << std::endl;

    // edges builder
    std::cout << "Edges builder" << std::endl;
    std::cout << "----------------" << std::endl;
    edges_builder();
}
```

config.h
```
#pragma once

#include <filesystem>
#include <string>

// Define a new macro that is just like the standard C assert macro,
// except that it works even in optimized builds (where NDEBUG is
// defined) and it prints the failed assertion to stderr.
#ifndef ASSERT
#define ASSERT(x)                                    \
  if (!(x)) {                                        \
    char buf[2048];                                  \
    snprintf(buf, sizeof(buf),                       \
             "Assertion failed in \"%s\", line %d\n" \
             "\tProbable bug in software.\n",        \
             __FILE__, __LINE__);                    \
    ABORT(buf);                                      \
  } else  // NOLINT
// The 'else' exists to catch the user's following semicolon
#endif

// Define a new macro that is just like the standard C abort macro,
// except that it prints the failed assertion to stderr.
#ifndef ABORT
#define ABORT(msg)              \
  do {                          \
    fprintf(stderr, "%s", msg); \
    fflush(stderr);             \
    abort();                    \
  } while (0)
#endif

// DASSERT is like ASSERT, but it only works in debug builds.
#ifdef DEBUG
#define DASSERT(x) ASSERT(x)
#else
#define DASSERT(x)
#endif

static const std::string TEST_DATA_DIR =  // NOLINT
        std::filesystem::path(__FILE__)
                .parent_path()
                .parent_path()
                .parent_path()
                .parent_path()
                .string() +
        "/testing";
```

GitHub link: 
https://github.com/apache/incubator-graphar/discussions/457#discussioncomment-9165112

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to