Skip to main content

ArrowRle

Struct ArrowRle 

Source
pub struct ArrowRle { /* private fields */ }
Expand description

A run-length encoded sequence whose values are an Arrow array of any type.

Like runlength::Rle, it stores cumulative run ends and one value per run, starts at position 0, and has no zero-length runs. Values may contain nulls; a null is a value like any other and merges with neighbouring nulls.

Implementations§

Source§

impl ArrowRle

Source

pub fn sum(&self) -> Result<ArrayRef>

The sum over all positions, as one value of the values’ type. Integer sums wrap on overflow.

Source

pub fn mean(&self) -> Result<Option<f64>>

The mean over all positions, or None if the sequence is empty.

Source

pub fn variance(&self, ddof: i64) -> Result<Option<f64>>

The variance over all positions with ddof delta degrees of freedom, or None if len() <= ddof.

Source

pub fn std(&self, ddof: i64) -> Result<Option<f64>>

The standard deviation; see variance.

Source

pub fn min(&self) -> Result<ArrayRef>

The smallest value ignoring NaN, as one value (null if there is none).

Source

pub fn max(&self) -> Result<ArrayRef>

The largest value ignoring NaN, as one value (null if there is none).

Source§

impl ArrowRle

Source

pub fn try_new(ends: Vec<i64>, values: ArrayRef) -> Result<Self>

Builds a sequence from cumulative run ends and one value per run.

Source

pub fn from_runs(runs: &[i64], values: ArrayRef) -> Result<Self>

Builds a sequence from run lengths and one value per run. Zero-length runs are dropped; neighbouring identical values are kept as they are.

Source

pub fn from_dense(values: ArrayRef) -> Result<Self>

Encodes a dense array, merging identical neighbours.

Source

pub fn empty(data_type: &DataType) -> Self

An empty sequence of the given value type.

Source

pub fn from_rle<T: ArrowPrimitiveType>(rle: &Rle<T::Native>) -> Self

Converts a core sequence of primitive values.

Source

pub fn to_rle<T: ArrowPrimitiveType>(&self) -> Result<Rle<T::Native>>

Converts to a core sequence of primitive values. The values must be of type T and contain no nulls.

Source

pub fn ends(&self) -> &[i64]

The cumulative end of each run.

Source

pub fn values(&self) -> &ArrayRef

One value per run.

Source

pub fn data_type(&self) -> &DataType

Source

pub fn len(&self) -> i64

The number of positions the sequence covers.

Source

pub fn is_empty(&self) -> bool

Source

pub fn num_runs(&self) -> usize

Source

pub fn runs(&self) -> Vec<i64>

The length of each run.

Source

pub fn into_parts(self) -> (Vec<i64>, ArrayRef)

Source

pub fn run_index(&self, pos: i64) -> Option<usize>

The index of the run containing pos, if pos is in range.

Source

pub fn slice(&self, start: i64, end: i64) -> ArrowRle

The positions start..end as a new sequence starting at 0, clamped to the sequence. The values are a zero-copy slice.

Source

pub fn getitems(&self, starts: &[i64], ends: &[i64]) -> Result<ArrowRleBatch>

Many slices at once, as a batch with one key column, slice, holding the slice number. Each interval needs 0 <= start <= end.

Source

pub fn to_dense(&self) -> Result<ArrayRef>

Expands the sequence into one value per position.

Source

pub fn plan_with(&self, other: &ArrowRle) -> Plan

The plan for combining this sequence with other. See Plan.

Source

pub fn identical_neighbours(&self) -> Result<Vec<bool>>

For each pair of neighbouring runs, whether their values are identical.

Source

pub fn is_merged(&self) -> Result<bool>

Whether no two neighbouring runs hold identical values.

Source

pub fn merge(self) -> Result<Self>

Merges neighbouring runs with identical values.

Source

pub fn merge_mask(self, mask: &[bool], keep: Keep) -> Result<Self>

Merges run i + 1 into run i wherever mask[i] is true, keeping the first or last value of each merged group.

Source

pub fn zip_with<F>( &self, other: &ArrowRle, fill_a: Option<&dyn Array>, fill_b: Option<&dyn Array>, f: F, ) -> Result<ArrowRle>
where F: FnOnce(&dyn Array, &dyn Array) -> Result<ArrayRef, ArrowError>,

Combines two sequences position by position and merges the result.

f receives the values of both sides gathered onto the plan’s segments (two arrays of equal length) and must return one value per segment; any Arrow kernel fits. The shorter side is padded with its fill value, a single value of the same type; with no fill value, unequal lengths are an error.

Source

pub fn zip_with_raw<F>( &self, other: &ArrowRle, fill_a: Option<&dyn Array>, fill_b: Option<&dyn Array>, f: F, ) -> Result<ArrowRle>
where F: FnOnce(&dyn Array, &dyn Array) -> Result<ArrayRef, ArrowError>,

Like zip_with but without merging the result.

Source

pub fn map<F>(&self, f: F) -> Result<ArrowRle>
where F: FnOnce(&dyn Array) -> Result<ArrayRef, ArrowError>,

Applies an Arrow kernel to the run values and merges the result.

Source

pub fn cast(&self, data_type: &DataType) -> Result<ArrowRle>

Casts the values to data_type and merges any neighbours that become identical (for example when floats are truncated to integers).

Source

pub fn zip_with_default(&self, other: &ArrowRle, f: Kernel) -> Result<ArrowRle>

Combines with other using default_fill on each side, and merges.

Source§

impl ArrowRle

Source

pub fn add(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise addition (integer overflow is an error). The shorter side is padded with default_fill.

Source

pub fn sub(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise subtraction (integer overflow is an error). The shorter side is padded with default_fill.

Source

pub fn mul(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise multiplication (integer overflow is an error). The shorter side is padded with default_fill.

Source

pub fn div(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise division (integer division by zero is an error). The shorter side is padded with default_fill.

Source

pub fn elem_eq(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise ==. The shorter side is padded with default_fill.

Source

pub fn elem_ne(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise !=. The shorter side is padded with default_fill.

Source

pub fn elem_lt(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise <. The shorter side is padded with default_fill.

Source

pub fn elem_le(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise <=. The shorter side is padded with default_fill.

Source

pub fn elem_gt(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise >. The shorter side is padded with default_fill.

Source

pub fn elem_ge(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise >=. The shorter side is padded with default_fill.

Source

pub fn and(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise logical and, with SQL semantics for nulls. The shorter side is padded with default_fill.

Source

pub fn or(&self, other: &ArrowRle) -> Result<ArrowRle>

Element-wise logical or, with SQL semantics for nulls. The shorter side is padded with default_fill.

Source§

impl ArrowRle

Source

pub fn slice_agg( &self, starts: &[i64], ends: &[i64], agg: SliceAgg, ) -> Result<ArrayRef>

Reduces many slices without copying them, in parallel: entry k of the result reduces positions starts[k]..ends[k] (clamped to the sequence) with agg. Values must be numeric or boolean.

use std::sync::Arc;
use arrow_array::{Array, Float64Array, Int64Array};
use runlength_arrow::{ArrowRle, SliceAgg};

let rle = ArrowRle::from_runs(&[3, 2], Arc::new(Int64Array::from(vec![1, 4]))).unwrap();
let means = rle.slice_agg(&[0, 2], &[2, 5], SliceAgg::Mean).unwrap();
let means = means.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(means.values().to_vec(), vec![1.0, 3.0]);
Source§

impl ArrowRle

Source

pub fn shift(&self, distance: i64, fill: &dyn Array) -> Result<ArrowRle>

Shifts values distance positions right (left if negative), keeping the length; positions shifted in hold fill, a single value of the same type. The result is merged.

Source

pub fn reversed(&self) -> Result<ArrowRle>

The sequence back to front.

Source

pub fn true_ranges(&self) -> Result<(Vec<i64>, Vec<i64>)>

For a boolean sequence, the half-open ranges (starts, ends) where it is true (nulls count as false), with touching ranges joined.

Source

pub fn fill_null(&self, fill: &dyn Array) -> Result<ArrowRle>

Replaces nulls with fill, a single value of the same type.

Trait Implementations§

Source§

impl Clone for ArrowRle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ArrowRle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ArrowRle

Source§

fn eq(&self, other: &Self) -> bool

Whether both sequences represent the same values at every position (by identical_neighbours’s rule), however the runs are split.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.