Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

#include "arrow/api.h"
#include "arrow/c/bridge.h"
#include <iostream>
#include <jni.h>
#include <iostream>
#include <new>
#include "arrow/api.h"
#include "arrow/c/bridge.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -32,14 +32,14 @@ extern "C" {
JNIEXPORT
jlong JNICALL
Java_org_apache_graphar_arrow_ArrowTable_1Static_1cxx_10x58c7409_nativeFromArrowArrayAndArrowSchema(
JNIEnv *, jclass, jlong rv_base, jlong arg0 /* arrayAddress0 */,
JNIEnv*, jclass, jlong rv_base, jlong arg0 /* arrayAddress0 */,
jlong arg1 /* schemaAddress1 */) {
auto maybeRecordBatch =
arrow::ImportRecordBatch(reinterpret_cast<struct ArrowArray *>(arg0),
reinterpret_cast<struct ArrowSchema *>(arg1));
arrow::ImportRecordBatch(reinterpret_cast<struct ArrowArray*>(arg0),
reinterpret_cast<struct ArrowSchema*>(arg1));
auto table = arrow::Table::FromRecordBatches({maybeRecordBatch.ValueOrDie()});
return reinterpret_cast<jlong>(new (
(void *)rv_base) arrow::Result<std::shared_ptr<arrow::Table>>(table));
(void*) rv_base) arrow::Result<std::shared_ptr<arrow::Table>>(table));
}

#ifdef __cplusplus
Expand Down
33 changes: 0 additions & 33 deletions python/.clang-format

This file was deleted.

85 changes: 42 additions & 43 deletions rust/include/graphar_rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,71 +35,70 @@ namespace graphar {
using SharedPropertyGroup = std::shared_ptr<PropertyGroup>;
using SharedAdjacentList = std::shared_ptr<AdjacentList>;
using ConstInfoVersion = const InfoVersion;
} // namespace graphar
} // namespace graphar

namespace graphar_rs {
rust::String to_type_name(const graphar::DataType &type);

std::shared_ptr<graphar::ConstInfoVersion>
new_const_info_version(int32_t version);

std::unique_ptr<graphar::Property>
new_property(const std::string &name, std::shared_ptr<graphar::DataType> type,
bool is_primary, bool is_nullable,
graphar::Cardinality cardinality);
const std::string &property_get_name(const graphar::Property &prop);
const std::shared_ptr<graphar::DataType> &
property_get_type(const graphar::Property &prop);
bool property_is_primary(const graphar::Property &prop);
bool property_is_nullable(const graphar::Property &prop);
graphar::Cardinality property_get_cardinality(const graphar::Property &prop);
std::unique_ptr<graphar::Property>
property_clone(const graphar::Property &prop);

void property_vec_push_property(std::vector<graphar::Property> &properties,
rust::String to_type_name(const graphar::DataType& type);

std::shared_ptr<graphar::ConstInfoVersion> new_const_info_version(
int32_t version);

std::unique_ptr<graphar::Property> new_property(
const std::string& name, std::shared_ptr<graphar::DataType> type,
bool is_primary, bool is_nullable, graphar::Cardinality cardinality);
const std::string& property_get_name(const graphar::Property& prop);
const std::shared_ptr<graphar::DataType>& property_get_type(
const graphar::Property& prop);
bool property_is_primary(const graphar::Property& prop);
bool property_is_nullable(const graphar::Property& prop);
graphar::Cardinality property_get_cardinality(const graphar::Property& prop);
std::unique_ptr<graphar::Property> property_clone(
const graphar::Property& prop);

void property_vec_push_property(std::vector<graphar::Property>& properties,
std::unique_ptr<graphar::Property> prop);
void property_vec_emplace_property(std::vector<graphar::Property> &properties,
const std::string &name,
void property_vec_emplace_property(std::vector<graphar::Property>& properties,
const std::string& name,
std::shared_ptr<graphar::DataType> type,
bool is_primary, bool is_nullable,
graphar::Cardinality cardinality);

std::unique_ptr<std::vector<graphar::Property>>
property_vec_clone(const std::vector<graphar::Property> &properties);
std::unique_ptr<std::vector<graphar::Property>> property_vec_clone(
const std::vector<graphar::Property>& properties);

void property_group_vec_push_property_group(
std::vector<graphar::SharedPropertyGroup> &property_groups,
std::vector<graphar::SharedPropertyGroup>& property_groups,
std::shared_ptr<graphar::PropertyGroup> property_group);

std::unique_ptr<std::vector<graphar::SharedPropertyGroup>>
property_group_vec_clone(
const std::vector<graphar::SharedPropertyGroup> &property_groups);
const std::vector<graphar::SharedPropertyGroup>& property_groups);

std::shared_ptr<graphar::VertexInfo> create_vertex_info(
const std::string &type, graphar::IdType chunk_size,
const std::vector<graphar::SharedPropertyGroup> &property_groups,
const rust::Vec<rust::String> &labels, const std::string &prefix,
const std::string& type, graphar::IdType chunk_size,
const std::vector<graphar::SharedPropertyGroup>& property_groups,
const rust::Vec<rust::String>& labels, const std::string& prefix,
std::shared_ptr<graphar::ConstInfoVersion> version);

std::shared_ptr<graphar::EdgeInfo> create_edge_info(
const std::string &src_type, const std::string &edge_type,
const std::string &dst_type, graphar::IdType chunk_size,
const std::string& src_type, const std::string& edge_type,
const std::string& dst_type, graphar::IdType chunk_size,
graphar::IdType src_chunk_size, graphar::IdType dst_chunk_size,
bool directed, const graphar::AdjacentListVector &adjacent_lists,
const std::vector<graphar::SharedPropertyGroup> &property_groups,
const std::string &prefix,
bool directed, const graphar::AdjacentListVector& adjacent_lists,
const std::vector<graphar::SharedPropertyGroup>& property_groups,
const std::string& prefix,
std::shared_ptr<graphar::ConstInfoVersion> version);

void vertex_info_save(const graphar::VertexInfo &vertex_info,
const std::string &path);
std::unique_ptr<std::string>
vertex_info_dump(const graphar::VertexInfo &vertex_info);
void vertex_info_save(const graphar::VertexInfo& vertex_info,
const std::string& path);
std::unique_ptr<std::string> vertex_info_dump(
const graphar::VertexInfo& vertex_info);

std::unique_ptr<graphar::AdjacentListVector> new_adjacent_list_vec();
void push_adjacent_list(graphar::AdjacentListVector &v,
void push_adjacent_list(graphar::AdjacentListVector& v,
std::shared_ptr<graphar::AdjacentList> adjacent_list);

void edge_info_save(const graphar::EdgeInfo &edge_info,
const std::string &path);
std::unique_ptr<std::string> edge_info_dump(const graphar::EdgeInfo &edge_info);
} // namespace graphar_rs
void edge_info_save(const graphar::EdgeInfo& edge_info,
const std::string& path);
std::unique_ptr<std::string> edge_info_dump(const graphar::EdgeInfo& edge_info);
} // namespace graphar_rs
79 changes: 39 additions & 40 deletions rust/src/graphar_rs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,78 @@
#include <utility>

namespace graphar_rs {
rust::String to_type_name(const graphar::DataType &type) {
rust::String to_type_name(const graphar::DataType& type) {
return rust::String(type.ToTypeName());
}

std::shared_ptr<graphar::ConstInfoVersion>
new_const_info_version(int32_t version) {
std::shared_ptr<graphar::ConstInfoVersion> new_const_info_version(
int32_t version) {
// Let any upstream exceptions propagate to Rust via `cxx::Exception`.
return std::make_shared<graphar::InfoVersion>(static_cast<int>(version));
}

std::unique_ptr<graphar::Property>
new_property(const std::string &name, std::shared_ptr<graphar::DataType> type,
bool is_primary, bool is_nullable,
graphar::Cardinality cardinality) {
std::unique_ptr<graphar::Property> new_property(
const std::string& name, std::shared_ptr<graphar::DataType> type,
bool is_primary, bool is_nullable, graphar::Cardinality cardinality) {
return std::make_unique<graphar::Property>(name, type, is_primary,
is_nullable, cardinality);
}
const std::string &property_get_name(const graphar::Property &prop) {
const std::string& property_get_name(const graphar::Property& prop) {
return prop.name;
}
const std::shared_ptr<graphar::DataType> &
property_get_type(const graphar::Property &prop) {
const std::shared_ptr<graphar::DataType>& property_get_type(
const graphar::Property& prop) {
return prop.type;
}
bool property_is_primary(const graphar::Property &prop) {
bool property_is_primary(const graphar::Property& prop) {
return prop.is_primary;
}
bool property_is_nullable(const graphar::Property &prop) {
bool property_is_nullable(const graphar::Property& prop) {
return prop.is_nullable;
}
graphar::Cardinality property_get_cardinality(const graphar::Property &prop) {
graphar::Cardinality property_get_cardinality(const graphar::Property& prop) {
return prop.cardinality;
}
std::unique_ptr<graphar::Property>
property_clone(const graphar::Property &prop) {
std::unique_ptr<graphar::Property> property_clone(
const graphar::Property& prop) {
return std::make_unique<graphar::Property>(prop);
}

void property_vec_push_property(std::vector<graphar::Property> &properties,
void property_vec_push_property(std::vector<graphar::Property>& properties,
std::unique_ptr<graphar::Property> prop) {
properties.emplace_back(*prop);
}

void property_vec_emplace_property(std::vector<graphar::Property> &properties,
const std::string &name,
void property_vec_emplace_property(std::vector<graphar::Property>& properties,
const std::string& name,
std::shared_ptr<graphar::DataType> type,
bool is_primary, bool is_nullable,
graphar::Cardinality cardinality) {
properties.emplace_back(name, type, is_primary, is_nullable, cardinality);
}

std::unique_ptr<std::vector<graphar::Property>>
property_vec_clone(const std::vector<graphar::Property> &properties) {
std::unique_ptr<std::vector<graphar::Property>> property_vec_clone(
const std::vector<graphar::Property>& properties) {
return std::make_unique<std::vector<graphar::Property>>(properties);
}

void property_group_vec_push_property_group(
std::vector<graphar::SharedPropertyGroup> &property_groups,
std::vector<graphar::SharedPropertyGroup>& property_groups,
std::shared_ptr<graphar::PropertyGroup> property_group) {
property_groups.emplace_back(std::move(property_group));
}

std::unique_ptr<std::vector<graphar::SharedPropertyGroup>>
property_group_vec_clone(
const std::vector<graphar::SharedPropertyGroup> &property_groups) {
const std::vector<graphar::SharedPropertyGroup>& property_groups) {
return std::make_unique<std::vector<graphar::SharedPropertyGroup>>(
property_groups);
}

std::shared_ptr<graphar::VertexInfo> create_vertex_info(
const std::string &type, graphar::IdType chunk_size,
const std::vector<graphar::SharedPropertyGroup> &property_groups,
const rust::Vec<rust::String> &labels, const std::string &prefix,
const std::string& type, graphar::IdType chunk_size,
const std::vector<graphar::SharedPropertyGroup>& property_groups,
const rust::Vec<rust::String>& labels, const std::string& prefix,
std::shared_ptr<graphar::ConstInfoVersion> version) {
if (type.empty()) {
throw std::runtime_error("CreateVertexInfo: type must not be empty");
Expand All @@ -119,12 +118,12 @@ std::shared_ptr<graphar::VertexInfo> create_vertex_info(
}

std::shared_ptr<graphar::EdgeInfo> create_edge_info(
const std::string &src_type, const std::string &edge_type,
const std::string &dst_type, graphar::IdType chunk_size,
const std::string& src_type, const std::string& edge_type,
const std::string& dst_type, graphar::IdType chunk_size,
graphar::IdType src_chunk_size, graphar::IdType dst_chunk_size,
bool directed, const graphar::AdjacentListVector &adjacent_lists,
const std::vector<graphar::SharedPropertyGroup> &property_groups,
const std::string &prefix,
bool directed, const graphar::AdjacentListVector& adjacent_lists,
const std::vector<graphar::SharedPropertyGroup>& property_groups,
const std::string& prefix,
std::shared_ptr<graphar::ConstInfoVersion> version) {
if (src_type.empty()) {
throw std::runtime_error("CreateEdgeInfo: src_type must not be empty");
Expand Down Expand Up @@ -158,16 +157,16 @@ std::shared_ptr<graphar::EdgeInfo> create_edge_info(
return edge_info;
}

void vertex_info_save(const graphar::VertexInfo &vertex_info,
const std::string &path) {
void vertex_info_save(const graphar::VertexInfo& vertex_info,
const std::string& path) {
auto status = vertex_info.Save(path);
if (!status.ok()) {
throw std::runtime_error(status.message());
}
}

std::unique_ptr<std::string>
vertex_info_dump(const graphar::VertexInfo &vertex_info) {
std::unique_ptr<std::string> vertex_info_dump(
const graphar::VertexInfo& vertex_info) {
auto dumped = vertex_info.Dump();
if (!dumped) {
throw std::runtime_error(dumped.error().message());
Expand All @@ -179,25 +178,25 @@ std::unique_ptr<graphar::AdjacentListVector> new_adjacent_list_vec() {
return std::make_unique<graphar::AdjacentListVector>();
}

void push_adjacent_list(graphar::AdjacentListVector &v,
void push_adjacent_list(graphar::AdjacentListVector& v,
std::shared_ptr<graphar::AdjacentList> adjacent_list) {
v.emplace_back(std::move(adjacent_list));
}

void edge_info_save(const graphar::EdgeInfo &edge_info,
const std::string &path) {
void edge_info_save(const graphar::EdgeInfo& edge_info,
const std::string& path) {
auto status = edge_info.Save(path);
if (!status.ok()) {
throw std::runtime_error(status.message());
}
}

std::unique_ptr<std::string>
edge_info_dump(const graphar::EdgeInfo &edge_info) {
std::unique_ptr<std::string> edge_info_dump(
const graphar::EdgeInfo& edge_info) {
auto r = edge_info.Dump();
if (!r) {
throw std::runtime_error(r.error().message());
}
return std::make_unique<std::string>(std::move(r).value());
}
} // namespace graphar_rs
} // namespace graphar_rs
Loading