ptars

Crates.ioptars
lib.rsptars
version0.0.9
created_at2025-12-23 12:39:34.069898+00
updated_at2025-12-30 11:27:36.107274+00
descriptionFast conversion from protobuf to Apache Arrow and back
homepagehttps://github.com/0x26res/ptars
repositoryhttps://github.com/0x26res/ptars
max_upload_size
id2001443
size277,522
0x26res (0x26res)

documentation

README

ptars

Crates.io Documentation License

Fast conversion between Protocol Buffers and Apache Arrow in Rust.

Features

  • Convert protobuf messages to Arrow RecordBatch
  • Convert Arrow RecordBatch back to serialized protobuf messages
  • Support for nested messages, repeated fields, and maps
  • Special handling for well-known types:
    • google.protobuf.Timestamptimestamp[ns]
    • google.type.Datedate32
    • google.type.TimeOfDaytime64[ns]
    • Wrapper types (DoubleValue, Int32Value, etc.) → nullable primitives

Usage

Add to your Cargo.toml:

[dependencies]
ptars = "0.0.9"
prost-reflect = "0.16"

Converting Protobuf to Arrow

use ptars::messages_to_record_batch;
use prost_reflect::{DescriptorPool, DynamicMessage};

// Load your protobuf descriptor
let pool = DescriptorPool::decode(include_bytes!("descriptor.bin").as_ref()).unwrap();
let message_descriptor = pool.get_message_by_name("my.package.MyMessage").unwrap();

// Create some messages
let mut msg = DynamicMessage::new(message_descriptor.clone());
msg.set_field_by_name("id", prost_reflect::Value::I32(42));
msg.set_field_by_name("name", prost_reflect::Value::String("example".into()));

let messages = vec![msg];

// Convert to Arrow RecordBatch
let record_batch = messages_to_record_batch(&messages, &message_descriptor);

Converting Binary Array to Arrow

If you have serialized protobuf messages in an Arrow BinaryArray:

use ptars::binary_array_to_record_batch;
use arrow_array::BinaryArray;

let binary_array: BinaryArray = /* your serialized messages */;
let record_batch = binary_array_to_record_batch(&binary_array, &message_descriptor).unwrap();

Converting Arrow back to Protobuf

use ptars::record_batch_to_array;

// Convert RecordBatch to a BinaryArray of serialized messages
let binary_array = record_batch_to_array(&record_batch, &message_descriptor);

// Decode individual messages
for i in 0..binary_array.len() {
    let msg = DynamicMessage::decode(message_descriptor.clone(), binary_array.value(i)).unwrap();
}

License

Apache-2.0

Commit count: 0

cargo fmt