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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ license = "Apache-2.0"
[dependencies]
# anyhow = "1.0.100"
cxx = "1.0.190"
pastey = "0.2.1"

[build-dependencies]
cxx-build = "1.0.190"
Expand Down
18 changes: 12 additions & 6 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ use std::path::{Path, PathBuf};
fn link_libraries() {
println!("cargo:rerun-if-env-changed=PKG_CONFIG_PATH");

let _arrow = pkg_config::Config::new()
.statik(false)
.cargo_metadata(true)
.probe("arrow")
.expect("Arrow development files not found via pkg-config. Set PKG_CONFIG_PATH if needed.");
for package in ["arrow", "parquet", "arrow-dataset", "arrow-acero"] {
pkg_config::Config::new()
.statik(false)
.cargo_metadata(true)
.probe(package)
.unwrap_or_else(|_| {
panic!(
"{package} development files not found via pkg-config. Set PKG_CONFIG_PATH if needed."
)
});
}

println!("cargo:rustc-link-lib=graphar");
println!("cargo:rustc-link-lib=graphar_thirdparty");
Expand All @@ -39,7 +45,7 @@ fn build_ffi(bridge_file: &str, out_name: &str, source_file: &str, include_paths

build.includes(include_paths);
// TODO support MSVC
build.flag("-std=c++17");
build.flag("-std=c++20");
build.flag("-fdiagnostics-color=always");

build.compile(out_name);
Expand Down
77 changes: 73 additions & 4 deletions rust/include/graphar_rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
#include <string>
#include <vector>

#include "graphar/fwd.h"
#include "graphar/graph_info.h"
#include "graphar/types.h"
#include "graphar/version_parser.h"
#include "graphar/api/high_level_writer.h"
#include "graphar/api/info.h"
#include "rust/cxx.h"

using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;

namespace graphar {
struct MaybeIndex;

Expand Down Expand Up @@ -129,4 +132,70 @@ void graph_info_save(const graphar::GraphInfo& graph_info,
const std::string& path);
std::unique_ptr<std::string> graph_info_dump(
const graphar::GraphInfo& graph_info);

// =========================== Builder ===========================
// `Vertex`
std::unique_ptr<graphar::builder::Vertex> new_vertex_builder();

inline bool vertex_builder_is_empty(const graphar::builder::Vertex& v) {
return v.Empty();
}

inline bool vertex_builder_is_multi_property(const graphar::builder::Vertex& v,
const std::string& name) {
return v.IsMultiProperty(name);
}

inline bool vertex_builder_contains_property(const graphar::builder::Vertex& v,
const std::string& name) {
const auto& props = v.GetProperties();
return props.find(name) != props.end();
}

#define DEF_VERTEX_BUILDER_ADD_PROPERTY_FUNC(type) \
inline void vertex_builder_add_property_##type( \
graphar::builder::Vertex& v, const std::string& name, type val) { \
v.AddProperty(name, val); \
}

DEF_VERTEX_BUILDER_ADD_PROPERTY_FUNC(bool)
DEF_VERTEX_BUILDER_ADD_PROPERTY_FUNC(i32)
DEF_VERTEX_BUILDER_ADD_PROPERTY_FUNC(i64)
DEF_VERTEX_BUILDER_ADD_PROPERTY_FUNC(f32)
DEF_VERTEX_BUILDER_ADD_PROPERTY_FUNC(f64)

inline void vertex_builder_add_property_string(graphar::builder::Vertex& v,
const std::string& name,
const std::string& val) {
v.AddProperty(name, val);
}

#define DEF_VERTEX_BUILDER_ADD_PROPERTY_WITH_CARDINALITY_FUNC(type) \
inline void vertex_builder_add_property_##type##_with_cardinality( \
graphar::builder::Vertex& v, graphar::Cardinality cardinality, \
const std::string& name, type val) { \
v.AddProperty(cardinality, name, val); \
}

DEF_VERTEX_BUILDER_ADD_PROPERTY_WITH_CARDINALITY_FUNC(bool)
DEF_VERTEX_BUILDER_ADD_PROPERTY_WITH_CARDINALITY_FUNC(i32)
DEF_VERTEX_BUILDER_ADD_PROPERTY_WITH_CARDINALITY_FUNC(i64)
DEF_VERTEX_BUILDER_ADD_PROPERTY_WITH_CARDINALITY_FUNC(f32)
DEF_VERTEX_BUILDER_ADD_PROPERTY_WITH_CARDINALITY_FUNC(f64)

inline void vertex_builder_add_property_string_with_cardinality(
graphar::builder::Vertex& v, graphar::Cardinality cardinality,
const std::string& name, const std::string& val) {
v.AddProperty(cardinality, name, val);
}

void add_vertex(graphar::builder::VerticesBuilder& builder,
graphar::builder::Vertex& v);

std::unique_ptr<graphar::builder::VerticesBuilder>
new_vertices_builder(const std::shared_ptr<graphar::VertexInfo>& vertex_info,
const std::string& path_prefix, i64 start_idx);

void vertices_dump(graphar::builder::VerticesBuilder& builder);

} // namespace graphar_rs
11 changes: 11 additions & 0 deletions rust/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! High-level builders for writing GraphAr data.

/// Vertex builders for writing vertex chunks.
pub mod vertex;

mod property_value;

/// A value that can be written into a GraphAr property.
pub use property_value::PropertyValue;

pub use vertex::{Vertex, VerticesBuilder};
35 changes: 35 additions & 0 deletions rust/src/builder/property_value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.

//! Shared property value abstractions for builders.

use crate::types::Cardinality;

#[doc(hidden)]
pub(crate) mod sealed {
pub trait Sealed<Target> {}
}

/// A value that can be written into a GraphAr property.
///
/// This trait is sealed and cannot be implemented outside this crate.
pub trait PropertyValue<Target>: sealed::Sealed<Target> {
/// Add this value as a property on the given target.
fn add_to(self, target: &mut Target, name: &str);
/// Add this value as a property on the given target with the specified cardinality.
fn add_to_with_cardinality(self, target: &mut Target, name: &str, cardinality: Cardinality);
}
Loading
Loading