125 releases (48 breaking)

new 0.49.6 Dec 9, 2024
0.49.1 Nov 25, 2024
0.38.0 Jul 22, 2024
0.28.0 Mar 25, 2024
0.1.0 Mar 5, 2022

#91 in Encoding

Download history 108907/week @ 2024-08-21 95152/week @ 2024-08-28 120216/week @ 2024-09-04 119395/week @ 2024-09-11 118052/week @ 2024-09-18 128058/week @ 2024-09-25 140256/week @ 2024-10-02 149504/week @ 2024-10-09 147011/week @ 2024-10-16 273760/week @ 2024-10-23 173727/week @ 2024-10-30 168228/week @ 2024-11-06 150369/week @ 2024-11-13 134683/week @ 2024-11-20 51844/week @ 2024-11-27 81222/week @ 2024-12-04

447,184 downloads per month
Used in 12 crates (3 directly)

Apache-2.0

72KB
1.5K SLoC

substrait-rs

substrait

crates.io docs.rs

Rust crate for Substrait: Cross-Language Serialization for Relational Algebra.

Documentation


lib.rs:

Substrait: Cross-Language Serialization for Relational Algebra

Serialization and deserialization

This crate provides generated types to serialize and deserialize Substrait data.

Protobuf

Protobuf serialization and deserialization are provided via [prost] in the [proto] module.

Example

Serialize and deserialize a plan

use prost::Message;
use substrait::proto::Plan;

let plan = Plan::default();

// Serialize the plan
let encoded = plan.encode_to_vec();

// Deserialize the buffer to a Plan
let decoded = Plan::decode(encoded.as_slice())?;

assert_eq!(plan, decoded);

Serde support

The serde feature generates serde implementations that match the Protobuf JSON Mapping via pbjson.

Example
Deserialize a plan version using the serde feature
use substrait::proto::Version;

let version_json = r#"{
  "minorNumber": 21
}"#;

let version = serde_json::from_str::<Version>(version_json)?;
assert_eq!(
  version,
  Version {
    minor_number: 21,
    ..Default::default()
  }
);

Text

Substrait defines a YAML schema for extensions. Types with serialization and deserialization support for these are provided via typify in the [text] module.

Example

Read a simple extension

use substrait::text::simple_extensions::SimpleExtensions;

let simple_extension_yaml = r#"
%YAML 1.2
---
scalar_functions:
  -
    name: "add"
    description: "Add two values."
    impls:
      - args:
         - name: x
           value: i8
         - name: y
           value: i8
        options:
          overflow:
            values: [ SILENT, SATURATE, ERROR ]
        return: i8
"#;

let simple_extension = serde_yaml::from_str::<SimpleExtensions>(simple_extension_yaml)?;

assert_eq!(simple_extension.scalar_functions.len(), 1);
assert_eq!(simple_extension.scalar_functions[0].name, "add");

Dependencies

~5–9.5MB
~182K SLoC