Struct arrow_array::array::RunArray
source · pub struct RunArray<R: RunEndIndexType> { /* private fields */ }
Expand description
A run-end encoding (REE) is a variation of run-length encoding (RLE).
This encoding is good for representing data containing same values repeated consecutively.
RunArray
contains run_ends
array and values
array of same length.
The run_ends
array stores the indexes at which the run ends. The values
array
stores the value of each run. Below example illustrates how a logical array is represented in
RunArray
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┐
┌─────────────────┐ ┌─────────┐ ┌─────────────────┐
│ │ A │ │ 2 │ │ │ A │
├─────────────────┤ ├─────────┤ ├─────────────────┤
│ │ D │ │ 3 │ │ │ A │ run length of 'A' = runs_ends[0] - 0 = 2
├─────────────────┤ ├─────────┤ ├─────────────────┤
│ │ B │ │ 6 │ │ │ D │ run length of 'D' = run_ends[1] - run_ends[0] = 1
└─────────────────┘ └─────────┘ ├─────────────────┤
│ values run_ends │ │ B │
├─────────────────┤
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┘ │ B │
├─────────────────┤
RunArray │ B │ run length of 'B' = run_ends[2] - run_ends[1] = 3
length = 3 └─────────────────┘
Logical array
Contents
Implementations§
source§impl<R: RunEndIndexType> RunArray<R>
impl<R: RunEndIndexType> RunArray<R>
sourcepub fn try_new(
run_ends: &PrimitiveArray<R>,
values: &dyn Array
) -> Result<Self, ArrowError>
pub fn try_new(
run_ends: &PrimitiveArray<R>,
values: &dyn Array
) -> Result<Self, ArrowError>
Attempts to create RunArray using given run_ends (index where a run ends) and the values (value of the run). Returns an error if the given data is not compatible with RunEndEncoded specification.
sourcepub fn run_ends(&self) -> &PrimitiveArray<R>
pub fn run_ends(&self) -> &PrimitiveArray<R>
Returns a reference to run_ends array
Note: any slicing of this array is not applied to the returned array and must be handled separately
Trait Implementations§
source§impl<T: RunEndIndexType> Array for RunArray<T>
impl<T: RunEndIndexType> Array for RunArray<T>
source§fn data_ref(&self) -> &ArrayData
fn data_ref(&self) -> &ArrayData
source§fn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
source§fn offset(&self) -> usize
fn offset(&self) -> usize
0
. Read moresource§fn is_null(&self, index: usize) -> bool
fn is_null(&self, index: usize) -> bool
index
is null.
When using this function on a slice, the index is relative to the slice. Read moresource§fn is_valid(&self, index: usize) -> bool
fn is_valid(&self, index: usize) -> bool
index
is not null.
When using this function on a slice, the index is relative to the slice. Read moresource§fn null_count(&self) -> usize
fn null_count(&self) -> usize
source§fn get_buffer_memory_size(&self) -> usize
fn get_buffer_memory_size(&self) -> usize
source§fn get_array_memory_size(&self) -> usize
fn get_array_memory_size(&self) -> usize
get_buffer_memory_size()
and
includes the overhead of the data structures that contain the pointers to the various buffers.source§impl<R: RunEndIndexType> Debug for RunArray<R>
impl<R: RunEndIndexType> Debug for RunArray<R>
source§impl<'a, T: RunEndIndexType> FromIterator<&'a str> for RunArray<T>
impl<'a, T: RunEndIndexType> FromIterator<&'a str> for RunArray<T>
Constructs a RunArray
from an iterator of strings.
Example:
use arrow_array::{RunArray, PrimitiveArray, StringArray, types::Int16Type};
let test = vec!["a", "a", "b", "c"];
let array: RunArray<Int16Type> = test.into_iter().collect();
assert_eq!(
"RunArray {run_ends: PrimitiveArray<Int16>\n[\n 2,\n 3,\n 4,\n], values: StringArray\n[\n \"a\",\n \"b\",\n \"c\",\n]}\n",
format!("{:?}", array)
);
source§impl<'a, T: RunEndIndexType> FromIterator<Option<&'a str>> for RunArray<T>
impl<'a, T: RunEndIndexType> FromIterator<Option<&'a str>> for RunArray<T>
Constructs a RunArray
from an iterator of optional strings.
Example:
use arrow_array::{RunArray, PrimitiveArray, StringArray, types::Int16Type};
let test = vec!["a", "a", "b", "c", "c"];
let array: RunArray<Int16Type> = test
.iter()
.map(|&x| if x == "b" { None } else { Some(x) })
.collect();
assert_eq!(
"RunArray {run_ends: PrimitiveArray<Int16>\n[\n 2,\n 3,\n 5,\n], values: StringArray\n[\n \"a\",\n null,\n \"c\",\n]}\n",
format!("{:?}", array)
);