Skip to main content

vortex_array/test_harness/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::io::Write;
5
6use goldenfile::Mint;
7use goldenfile::differs::binary_diff;
8use itertools::Itertools;
9use vortex_error::VortexResult;
10
11use crate::ExecutionCtx;
12use crate::arrays::BoolArray;
13use crate::arrays::bool::BoolArrayExt;
14
15#[cfg(not(codspeed))]
16pub mod trace;
17
18/// Check that a named metadata matches its previous versioning.
19///
20/// Goldenfile takes care of checking for equality against a checked-in file.
21#[expect(clippy::unwrap_used)]
22pub fn check_metadata(name: &str, metadata: &[u8]) {
23    let mut mint = Mint::new("goldenfiles/");
24    let mut f = mint
25        .new_goldenfile_with_differ(name, Box::new(binary_diff))
26        .unwrap();
27    f.write_all(metadata).unwrap();
28}
29
30/// Outputs the indices of the true values in a BoolArray
31pub fn to_int_indices(indices_bits: BoolArray, ctx: &mut ExecutionCtx) -> VortexResult<Vec<u64>> {
32    let buffer = indices_bits.to_bit_buffer();
33    let mask = indices_bits
34        .as_ref()
35        .validity()?
36        .execute_mask(indices_bits.as_ref().len(), ctx)?;
37    Ok(buffer
38        .iter()
39        .enumerate()
40        .filter_map(|(idx, v)| (v && mask.value(idx)).then_some(idx as u64))
41        .collect_vec())
42}