Skip to main content

vortex_runend/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4#[cfg(feature = "arbitrary")]
5mod arbitrary;
6#[cfg(feature = "arbitrary")]
7pub use arbitrary::ArbitraryRunEndArray;
8pub use array::*;
9pub use iter::trimmed_ends_iter;
10
11mod array;
12#[cfg(feature = "arrow")]
13mod arrow;
14pub mod compress;
15mod compute;
16pub mod decompress_bool;
17mod iter;
18mod kernel;
19mod ops;
20mod rules;
21
22#[doc(hidden)]
23pub mod _benchmarking {
24    pub use compute::filter::filter_run_end_primitive;
25    pub use compute::take::take_indices_unchecked;
26
27    use super::*;
28}
29
30use vortex_array::ArrayVTable;
31use vortex_array::aggregate_fn::AggregateFnVTable;
32use vortex_array::aggregate_fn::fns::is_constant::IsConstant;
33use vortex_array::aggregate_fn::fns::is_sorted::IsSorted;
34use vortex_array::aggregate_fn::fns::min_max::MinMax;
35use vortex_array::aggregate_fn::session::AggregateFnSessionExt;
36use vortex_array::session::ArraySessionExt;
37use vortex_session::VortexSession;
38
39/// Initialize run-end encoding in the given session.
40pub fn initialize(session: &VortexSession) {
41    session.arrays().register(RunEnd);
42    kernel::initialize(session);
43
44    // Register the RunEnd-specific aggregate kernels.
45    session.aggregate_fns().register_aggregate_kernel(
46        RunEnd.id(),
47        Some(MinMax.id()),
48        &compute::min_max::RunEndMinMaxKernel,
49    );
50    session.aggregate_fns().register_aggregate_kernel(
51        RunEnd.id(),
52        Some(IsConstant.id()),
53        &compute::is_constant::RunEndIsConstantKernel,
54    );
55    session.aggregate_fns().register_aggregate_kernel(
56        RunEnd.id(),
57        Some(IsSorted.id()),
58        &compute::is_sorted::RunEndIsSortedKernel,
59    );
60}
61
62#[cfg(test)]
63mod tests {
64    use std::sync::LazyLock;
65
66    use prost::Message;
67    use vortex_array::dtype::PType;
68    use vortex_array::test_harness::check_metadata;
69    use vortex_session::VortexSession;
70
71    use crate::RunEndMetadata;
72
73    pub static SESSION: LazyLock<VortexSession> = LazyLock::new(|| {
74        let session = vortex_array::array_session();
75        crate::initialize(&session);
76        session
77    });
78
79    #[cfg_attr(miri, ignore)]
80    #[test]
81    fn test_runend_metadata() {
82        check_metadata(
83            "runend.metadata",
84            &RunEndMetadata {
85                ends_ptype: PType::U64 as i32,
86                num_runs: u64::MAX,
87                offset: u64::MAX,
88            }
89            .encode_to_vec(),
90        );
91    }
92}