runlength_arrow/lib.rs
1//! Run-length encoded sequences over Apache Arrow arrays.
2//!
3//! This crate builds on [`runlength`] and uses its plans and merge rules, but
4//! stores values as an Arrow array, so values can be of any Arrow type:
5//! numbers, strings, dictionaries, lists, structs, and nulls in any of them.
6//!
7//! * Combining sequences gathers values through a [`runlength::Plan`] and
8//! applies any Arrow kernel ([`kernels`] has the usual ones).
9//! * Merging uses the same rule as the core crate for every type
10//! ([`identical_neighbours`]).
11//! * [`ArrowRleBatch`] keys sequences by a table of key columns of any
12//! types, and converts to one long table for polars or pandas.
13//!
14//! ```
15//! use std::sync::Arc;
16//! use arrow_array::{ArrayRef, StringArray};
17//! use runlength_arrow::{ArrowRle, kernels};
18//!
19//! let names: ArrayRef = Arc::new(StringArray::from(vec!["a", "a", "b", "c", "c"]));
20//! let rle = ArrowRle::from_dense(names).unwrap();
21//! assert_eq!(rle.runs(), vec![2, 1, 2]);
22//!
23//! let other: ArrayRef = Arc::new(StringArray::from(vec!["a", "x", "c", "c", "c"]));
24//! let other = ArrowRle::from_dense(other).unwrap();
25//! let same = rle.zip_with(&other, None, None, kernels::eq).unwrap();
26//! assert_eq!(same.runs(), vec![1, 2, 2]);
27//! ```
28
29mod batch;
30mod coverage;
31mod error;
32mod identical;
33pub mod kernels;
34mod numeric;
35mod reduce;
36mod rle;
37mod slices;
38mod transform;
39
40pub use batch::ArrowRleBatch;
41pub use coverage::{
42 Agg, coverage, coverage_agg, coverage_agg_by_key, coverage_by_key, overlap_plan_by_key,
43};
44pub use error::{Error, Result};
45pub use identical::identical_neighbours;
46pub use numeric::common_numeric_type;
47pub use rle::{ArrowRle, default_fill};
48pub use runlength::{How, Keep, OverlapPlan, PlanMany, overlap_plan, plan_many};
49pub use slices::SliceAgg;
50pub use transform::{concat, zip_many};