Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fuzz/fuzz_targets/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ impl FileRoundTrip {
let bool_mask_bool = bool_mask
.execute::<BoolArray>(&mut ctx)
.vortex_expect("execute bool");
let mask = bool_mask_bool.to_mask_fill_null_false(&mut ctx);
let mask = bool_mask_bool
.to_mask_fill_null_false(&mut ctx)
.vortex_expect("mask from bool");
let filtered = array_data
.filter(mask)
.vortex_expect("filter operation should succeed in fuzz test");
Expand Down
13 changes: 7 additions & 6 deletions vortex-array/src/arrays/bool/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,17 @@ pub trait BoolArrayExt: TypedArrayRef<Bool> {
.vortex_expect("cannot convert nullable boolean array to mask")
}

fn to_mask_fill_null_false(&self, ctx: &mut ExecutionCtx) -> Mask {
let validity_mask = BoolArrayExt::validity(self)
.execute_mask(self.len(), ctx)
.vortex_expect("Failed to compute validity mask");
/// Convert to a [`Mask`] in which null elements are `false`.
///
/// Fails if executing a lazy validity array fails.
fn to_mask_fill_null_false(&self, ctx: &mut ExecutionCtx) -> VortexResult<Mask> {
let validity_mask = BoolArrayExt::validity(self).execute_mask(self.len(), ctx)?;
let buffer = match validity_mask {
Mask::AllTrue(_) => self.to_bit_buffer(),
Mask::AllFalse(_) => return Mask::new_false(self.len()),
Mask::AllFalse(_) => return Ok(Mask::new_false(self.len())),
Mask::Values(validity) => validity.bit_buffer() & self.to_bit_buffer(),
};
Mask::from_buffer(buffer)
Ok(Mask::from_buffer(buffer))
}
}
impl<T: TypedArrayRef<Bool>> BoolArrayExt for T {}
Expand Down
4 changes: 3 additions & 1 deletion vortex-array/src/compute/conformance/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ fn test_nullable_mask_input(array: &ArrayRef, ctx: &mut ExecutionCtx) {
let validity = Validity::from_iter(validity_values.clone());
let nullable_mask = BoolArray::new(bool_array.to_bit_buffer(), validity);

let mask_array = nullable_mask.to_mask_fill_null_false(ctx);
let mask_array = nullable_mask
.to_mask_fill_null_false(ctx)
.vortex_expect("to_mask_fill_null_false should succeed in conformance test");
let masked = array
.clone()
.mask((!&mask_array).into_array())
Expand Down
2 changes: 1 addition & 1 deletion vortex-functions/src/case_when/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl ScalarFnVTable for CaseWhen {

let condition = args.get(i * 2)?.filter(remaining.clone())?;
let cond_bool = condition.execute::<BoolArray>(ctx)?;
let cond_mask = cond_bool.to_mask_fill_null_false(ctx);
let cond_mask = cond_bool.to_mask_fill_null_false(ctx)?;
let effective_mask = remaining.intersect_by_rank(&cond_mask);

if effective_mask.all_false() {
Expand Down
32 changes: 32 additions & 0 deletions vortex-functions/src/case_when/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,38 @@ fn selected_rows_do_not_execute_erroring_branches_or_later_conditions() -> Vorte
Ok(())
}

/// `mask` keeps its mask argument as the lazy validity of its result, so executing a masked
/// condition to a `BoolArray` defers the mask's computation. An overflow there must surface as an
/// error from `CaseWhen`, not a panic.
#[test]
fn condition_validity_error_is_returned() -> VortexResult<()> {
let mut ctx = SESSION.create_execution_ctx();
let overflowing_mask = buffer![i64::MIN, 0, 1]
.into_array()
.numeric(buffer![1i64, 1, 1].into_array(), NumericOperator::Sub)?
.compare(
ConstantArray::new(0i64, 3).into_array(),
CompareOperator::Gt,
CompareMode::TOTAL_ORDER,
)?;
let condition = BoolArray::from_iter([true, false, true])
.into_array()
.mask(overflowing_mask)?;

let case = ScalarFnArray::try_new(
CaseWhen.bind(CaseWhenOptions {
num_when_then_pairs: 1,
has_else: false,
}),
vec![condition, ConstantArray::new(1i32, 3).into_array()],
)?
.into_array();

let error = case.execute::<Canonical>(&mut ctx).unwrap_err();
assert!(error.to_string().contains("overflow"), "{error}");
Ok(())
}

#[rstest]
#[case::with_else(true)]
#[case::without_else(false)]
Expand Down
2 changes: 1 addition & 1 deletion vortex-functions/src/zip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl ScalarFnVTable for Zip {

let mask = mask_array
.execute::<BoolArray>(ctx)?
.to_mask_fill_null_false(ctx);
.to_mask_fill_null_false(ctx)?;

let return_dtype = zip_return_dtype(if_true.dtype(), if_false.dtype())?;

Expand Down
2 changes: 1 addition & 1 deletion vortex-python/src/arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ impl PyArray {
let mut ctx = session().create_execution_ctx();
let mask = mask
.execute::<BoolArray>(&mut ctx)?
.to_mask_fill_null_false(&mut ctx);
.to_mask_fill_null_false(&mut ctx)?;
Ok(slf
.filter(mask)?
.execute::<Canonical>(&mut ctx)?
Expand Down