From ac3544e35fbe3023ee8d4dba41304e2e9011b85d Mon Sep 17 00:00:00 2001 From: "vortex-claude[bot]" <274007616+vortex-claude[bot]@users.noreply.github.com> Date: Wed, 2 Dec 2026 05:13:20 +0000 Subject: [PATCH] Return validity errors from CaseWhen and Zip conditions instead of panicking Tracking Issue: #12531 Signed-off-by: vortex-claude[bot] <274007616+vortex-claude[bot]@users.noreply.github.com> --- fuzz/fuzz_targets/file_io.rs | 4 ++- vortex-array/src/arrays/bool/array.rs | 13 ++++---- vortex-array/src/compute/conformance/mask.rs | 4 ++- vortex-functions/src/case_when/mod.rs | 2 +- vortex-functions/src/case_when/tests.rs | 32 ++++++++++++++++++++ vortex-functions/src/zip/mod.rs | 2 +- vortex-python/src/arrays/mod.rs | 2 +- 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/fuzz/fuzz_targets/file_io.rs b/fuzz/fuzz_targets/file_io.rs index f0e28fe694c..a4dd90ed864 100644 --- a/fuzz/fuzz_targets/file_io.rs +++ b/fuzz/fuzz_targets/file_io.rs @@ -117,7 +117,9 @@ impl FileRoundTrip { let bool_mask_bool = bool_mask .execute::(&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"); diff --git a/vortex-array/src/arrays/bool/array.rs b/vortex-array/src/arrays/bool/array.rs index d8f82150d00..1eb3b3ed82c 100644 --- a/vortex-array/src/arrays/bool/array.rs +++ b/vortex-array/src/arrays/bool/array.rs @@ -126,16 +126,17 @@ pub trait BoolArrayExt: TypedArrayRef { .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 { + 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> BoolArrayExt for T {} diff --git a/vortex-array/src/compute/conformance/mask.rs b/vortex-array/src/compute/conformance/mask.rs index de9c6ce7c25..ddf8d53b014 100644 --- a/vortex-array/src/compute/conformance/mask.rs +++ b/vortex-array/src/compute/conformance/mask.rs @@ -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()) diff --git a/vortex-functions/src/case_when/mod.rs b/vortex-functions/src/case_when/mod.rs index d1d442502a1..f1bd6f73b81 100644 --- a/vortex-functions/src/case_when/mod.rs +++ b/vortex-functions/src/case_when/mod.rs @@ -268,7 +268,7 @@ impl ScalarFnVTable for CaseWhen { let condition = args.get(i * 2)?.filter(remaining.clone())?; let cond_bool = condition.execute::(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() { diff --git a/vortex-functions/src/case_when/tests.rs b/vortex-functions/src/case_when/tests.rs index 1c77df5af4e..61588696df5 100644 --- a/vortex-functions/src/case_when/tests.rs +++ b/vortex-functions/src/case_when/tests.rs @@ -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::(&mut ctx).unwrap_err(); + assert!(error.to_string().contains("overflow"), "{error}"); + Ok(()) +} + #[rstest] #[case::with_else(true)] #[case::without_else(false)] diff --git a/vortex-functions/src/zip/mod.rs b/vortex-functions/src/zip/mod.rs index 2f0ba78c348..bb6e86cfab8 100644 --- a/vortex-functions/src/zip/mod.rs +++ b/vortex-functions/src/zip/mod.rs @@ -204,7 +204,7 @@ impl ScalarFnVTable for Zip { let mask = mask_array .execute::(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())?; diff --git a/vortex-python/src/arrays/mod.rs b/vortex-python/src/arrays/mod.rs index 6eec759182c..e240562fdcf 100644 --- a/vortex-python/src/arrays/mod.rs +++ b/vortex-python/src/arrays/mod.rs @@ -840,7 +840,7 @@ impl PyArray { let mut ctx = session().create_execution_ctx(); let mask = mask .execute::(&mut ctx)? - .to_mask_fill_null_false(&mut ctx); + .to_mask_fill_null_false(&mut ctx)?; Ok(slf .filter(mask)? .execute::(&mut ctx)?