Skip to content

About

Rust bindings to the RayforceDB

Resources

Stars

12 stars

Watchers

0 watching

Forks

Latest commit

 

History

137 Commits

Folders and files

Repository files navigation

High-Performance, Zero-Copy Rust bindings for RayforceDB

CI Crates.io Docs.rs License: MIT Rust Version

Rust bindings for RayforceDB, a high-performance columnar database designed for analytics and data operations. The core is written in pure C with minimal overhead — combining columnar storage with SIMD vectorization for lightning-fast analytics on time-series and big-data workloads.

The bindings call the core's C API directly (no marshalling shim), so reads are zero-copy where it counts: a numeric column is exposed as a &[T] slice rather than copied element by element.

Full Documentation: https://rs.rayforcedb.com/

Features

  • Fluent API — chainable, intuitive query builders that read like the operation; real operator overloads for arithmetic, methods for comparisons.
  • Zero-Copy & High Performance — build a column in a single memcpy, read it back as a borrow; minimal overhead between Rust and the RayforceDB runtime via the C API.
  • Type-Safe — a full value model (atoms, vectors, lists, dicts, tables) with ToValue/FromValue conversions and optional chrono temporals.
  • Lightweight — the core is less than a 1 MB footprint.
  • Batteries included — CSV & splayed I/O, binary serialization, and a TCP/IPC client.

Quick Start

use rayforce::{col, Runtime, Table, Value};

// One live runtime per process; the scope brackets its whole life.
Runtime::scope(|_rt| {
    let quotes = Table::new(
        &["symbol", "bid", "ask"],
        &[
            Value::sym_vec(&["AAPL", "AAPL", "AAPL", "GOOG", "GOOG", "GOOG"]),
            Value::vec(&[100.0f64, 101.0, 102.0, 200.0, 201.0, 202.0]),
            Value::vec(&[110.0f64, 111.0, 112.0, 210.0, 211.0, 212.0]),
        ],
    )?;

    let result = quotes
        .select()
        .agg("max_bid", col("bid").max())
        .agg("min_bid", col("bid").min())
        .agg("avg_ask", col("ask").avg())
        .agg("count",   col("bid").count())
        .filter(col("bid").ge(110.0).and(col("ask").gt(100.0)))
        .by("symbol")
        .execute()?;

    println!("{result}");
    Ok(())
})?;
┌────────┬─────────┬─────────┬─────────┬───────┐
│ symbol │ max_bid │ min_bid │ avg_ask │ count │
│  SYM   │   F64   │   F64   │   F64   │  I64  │
├────────┼─────────┼─────────┼─────────┼───────┤
│ GOOG   │ 202.0   │ 200.0   │ 211.0   │ 3     │
├────────┴─────────┴─────────┴─────────┴───────┤
│ 1 rows (1 shown) 5 columns (5 shown)         │
└──────────────────────────────────────────────┘

Installation

The RayforceDB core and the rayforce-q IPC client are C. Both ship inside the crate, so nothing is fetched at build time — the build script compiles them and statically links librayforce.a.

# Cargo.toml
[dependencies]
rayforce = { git = "https://github.com/RayforceDB/rayforce-rs" }

Requirements: a C toolchain (make, clang) and libclang for bindgen.

Working on the bindings

The C sources live in git submodules under rayforce-sys/vendor/, so a checkout needs them initialized:

git clone --recurse-submodules https://github.com/RayforceDB/rayforce-rs
# in an existing clone:
git submodule update --init --recursive

cargo build
cargo test

Choosing the core version

Each release links one pinned core version. It lives in two places that must agree — the rayforce-sys/vendor/rayforce submodule, and the CORE_VERSION / CORE_COMMIT constants in rayforce-sys/build.rs that get stamped into librayforce.a (a crate unpacked from crates.io has no git history for the core's Makefile to read a version from).

To move the pin, move both:

git -C rayforce-sys/vendor/rayforce fetch --tags
git -C rayforce-sys/vendor/rayforce checkout v3.0.2
git add rayforce-sys/vendor/rayforce

git -C rayforce-sys/vendor/rayforce rev-parse --short=7 HEAD   # CORE_COMMIT
$EDITOR rayforce-sys/build.rs                                  # CORE_VERSION, CORE_COMMIT

./scripts/check-vendored-pin.sh    # names the mismatch if they disagree
cargo test --workspace

The pin may also be a commit of the core's dev branch, between releases. Then CORE_VERSION is the newest release that commit contains, what the core's own Makefile stamps on it (release tags sit on master, so git describe would name an older one), and the check asserts that it is.

rayforce-sys/vendor/rayforce-q works the same way, minus the constants — nothing is stamped from it. The build script needs rayforce-q 2.5.0 or later, the first with q_decode_cols, and names the version when a checkout is older.

To build against a core you are changing instead, point the build script at your own checkout. These take precedence over the vendored copies:

export RAYFORCE_SRC=/path/to/rayforce
export RAYFORCE_Q_SRC=/path/to/rayforce-q

Such a checkout is built in place, so incremental state is preserved — except across a core-flavour switch. Release and debug objects share every filename, so the first build after RAYFORCE_CORE_DEBUG changes drops every object under src/ and the librayforce.a beside them, and records the flags in an untracked .stamp. Nothing tracked by git is touched.

bindgen locates libclang via LIBCLANG_PATH. This is deliberately not set in the repo's .cargo/config.toml. If bindgen can't auto-detect libclang, set it yourself:

# macOS (CTL):
export LIBCLANG_PATH="/Library/Developer/CommandLineTools/usr/lib"
# Linux: the directory of libclang itself. A pattern like libclang*.so* also
# matches libclang-cpp and the libclang_rt runtime, whose directory has none.
export LIBCLANG_PATH="$(dirname "$(find /usr/lib -regextype posix-extended \
  -regex '.*/libclang(-[0-9][0-9.]*)?\.so(\.[0-9]+)*' | sort -V | tail -1)")"

The chrono is on by default for date/time/timestamp conversions.


Built with ❤️ for high-performance data processing | MIT Licensed | RayforceDB

About

Rust bindings to the RayforceDB

Resources

Stars

12 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages