Skip to main content

vortex_array/
test_harness.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/// Check that a named metadata matches its previous versioning.
16///
17/// Goldenfile takes care of checking for equality against a checked-in file.
18#[expect(clippy::unwrap_used)]
19pub fn check_metadata(name: &str, metadata: &[u8]) {
20    let mut mint = Mint::new("goldenfiles/");
21    let mut f = mint
22        .new_goldenfile_with_differ(name, Box::new(binary_diff))
23        .unwrap();
24    f.write_all(metadata).unwrap();
25}
26
27/// Outputs the indices of the true values in a BoolArray
28pub fn to_int_indices(indices_bits: BoolArray, ctx: &mut ExecutionCtx) -> VortexResult<Vec<u64>> {
29    let buffer = indices_bits.to_bit_buffer();
30    let mask = indices_bits
31        .as_ref()
32        .validity()?
33        .execute_mask(indices_bits.as_ref().len(), ctx)?;
34    Ok(buffer
35        .iter()
36        .enumerate()
37        .filter_map(|(idx, v)| (v && mask.value(idx)).then_some(idx as u64))
38        .collect_vec())
39}