Current section

Files

Jump to
ex_arrow native ex_arrow_native src resources.rs
Raw

native/ex_arrow_native/src/resources.rs

//! Resource types for ExArrow: Schema, RecordBatch, IPC stream, IPC file.
use arrow::record_batch::RecordBatch;
use arrow_schema::Schema;
use std::fs::File;
use std::io::{BufReader, Cursor};
use std::sync::Arc;
use std::sync::Mutex;
use arrow_ipc::reader::{FileReader, StreamReader};
/// Opaque handle for an Arrow schema (held in native memory).
pub struct ExArrowSchema {
pub schema: Arc<Schema>,
}
#[rustler::resource_impl]
impl rustler::Resource for ExArrowSchema {}
/// Opaque handle for an Arrow record batch.
pub struct ExArrowRecordBatch {
pub batch: RecordBatch,
}
#[rustler::resource_impl]
impl rustler::Resource for ExArrowRecordBatch {}
/// Backing for IPC stream: either in-memory bytes or a buffered file (streaming, no full slurp).
pub enum IpcStreamBacking {
Binary(Mutex<StreamReader<Cursor<Vec<u8>>>>),
File(Mutex<StreamReader<BufReader<File>>>),
}
/// IPC stream reader: holds the StreamReader so we can call next() from Elixir.
pub struct ExArrowIpcStream {
pub reader: IpcStreamBacking,
}
#[rustler::resource_impl]
impl rustler::Resource for ExArrowIpcStream {}
/// Backing for IPC file reader: file path or in-memory bytes (for tests / from_binary).
pub enum IpcFileBacking {
File(Mutex<FileReader<BufReader<File>>>),
Binary(Mutex<FileReader<Cursor<Vec<u8>>>>),
}
/// IPC file format reader: random access (schema, batch count, get batch by index).
pub struct ExArrowIpcFile {
pub backing: IpcFileBacking,
}
#[rustler::resource_impl]
impl rustler::Resource for ExArrowIpcFile {}