Narrow

crates.io docs.rs

A Rust implementation of Apache Arrow.

Docs

Progress

Minimum supported Rust version

The minimum supported Rust version is 1.54.

Example

Struct array

```rust use narrow::{Array, BooleanArray, Float32Array, StructArray, Uint8Array};

[derive(Array, Copy, Clone, Debug, PartialEq)]

pub struct Person { name: String, age: u8, happy: bool, distance: Option, }

let persons = vec![ Person { name: "A".tostring(), age: 20, happy: true, distance: Some(1.5), }, Person { name: "B".tostring(), age: 22, happy: true, distance: None, }, ];

// Convert array of structs to struct of arrays. let personsarray: StructArray = persons.clone().intoiter().collect(); asserteq!(personsarray.len(), 2);

// To sum the ages we only need to read the age array. let agearray: &Uint8Array = &personsarray.age; asserteq!(agearray.into_iter().sum::(), 42);

// Make sure everyone is happy. let happyarray: &BooleanArray = &personsarray.happy; assert!(happyarray.intoiter().all(|bool| bool));

// The const generic bool in array types indicates nullability of the // values in that array. let distancearray: &Float32Array = &personsarray.distance; asserteq!(distancearray.null_count(), 1);

// Convert struct of arrays back to array of structs asserteq!(personsarray.into_iter().collect::>(), persons); ```

Union array

```rust use narrow::{Array, UnionArray};

[derive(Array, Copy, Clone, Debug, PartialEq)]

pub enum Either { This(bool), That(Option) }

let input = vec![ Either::This(false), Either::This(true), Either::That(Some(1234)), Either::That(None), Either::This(true) ];

let array: UnionArray = input.iter().copied().collect();

asserteq!(array.len(), 5); asserteq!(array.child().This.len(), 3); asserteq!(array.child().That.len(), 2); asserteq!(array.child().That.null_count(), 1);

asserteq!(array.intoiter().collect::>(), input); ```

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.