Skip to content
Merged
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
2 changes: 1 addition & 1 deletion STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- `vortex_panic!` for handling invariant violations
- Add context to errors using `.with_context()`
- Include backtraces for better debugging
- Use `VortexExpect` and `VortexUnwrap` traits when unwrapping is appropriate
- Use `VortexExpect` trait when unwrapping is appropriate with proper error context.

## Code Structure

Expand Down
9 changes: 5 additions & 4 deletions encodings/alp/src/alp_rd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use vortex_dtype::DType;
use vortex_dtype::NativePType;
use vortex_dtype::match_each_integer_ptype;
use vortex_error::VortexExpect;
use vortex_error::VortexUnwrap;
use vortex_error::vortex_panic;
use vortex_utils::aliases::hash_map::HashMap;

Expand Down Expand Up @@ -229,15 +228,15 @@ impl RDEncoder {
// SAFETY: by construction, all values in left_parts can be packed to left_bit_width.
let packed_left = unsafe {
bitpack_encode_unchecked(primitive_left, left_bit_width as _)
.vortex_unwrap()
.vortex_expect("bitpack_encode_unchecked should succeed for left parts")
.into_array()
};

let primitive_right = PrimitiveArray::new(right_parts, Validity::NonNullable);
// SAFETY: by construction, all values in right_parts are right_bit_width + leading zeros.
let packed_right = unsafe {
bitpack_encode_unchecked(primitive_right, self.right_bit_width as _)
.vortex_unwrap()
.vortex_expect("bitpack_encode_unchecked should succeed for right parts")
.into_array()
};

Expand All @@ -252,7 +251,9 @@ impl RDEncoder {
// SAFETY: We calculate bw such that it is wide enough to hold the largest position index.
let packed_pos = unsafe {
bitpack_encode_unchecked(exc_pos_array, bw)
.vortex_unwrap()
.vortex_expect(
"bitpack_encode_unchecked should succeed for exception positions",
)
.into_array()
};

Expand Down
7 changes: 5 additions & 2 deletions encodings/fsst/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use vortex_buffer::Buffer;
use vortex_buffer::BufferMut;
use vortex_dtype::DType;
use vortex_error::VortexExpect;
use vortex_error::VortexUnwrap;

use crate::FSSTArray;

Expand Down Expand Up @@ -74,7 +73,11 @@ where
uncompressed_lengths.push(0);
}
Some(s) => {
uncompressed_lengths.push(s.len().try_into().vortex_unwrap());
uncompressed_lengths.push(
s.len()
.try_into()
.vortex_expect("string length must fit in i32"),
);

// SAFETY: buffer is large enough
unsafe { compressor.compress_into(s, &mut buffer) };
Expand Down
5 changes: 3 additions & 2 deletions encodings/fsst/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use vortex_array::arrays::VarBinArray;
use vortex_dtype::DType;
use vortex_dtype::NativePType;
use vortex_dtype::Nullability;
use vortex_error::VortexUnwrap;
use vortex_error::VortexExpect;

use crate::fsst_compress;
use crate::fsst_train_compressor;
Expand Down Expand Up @@ -56,5 +56,6 @@ pub fn gen_dict_fsst_test_data<T: NativePType>(
let codes = (0..len)
.map(|_| T::from(rng.random_range(0..unique_values)).unwrap())
.collect::<PrimitiveArray>();
DictArray::try_new(codes.into_array(), values).vortex_unwrap()
DictArray::try_new(codes.into_array(), values)
.vortex_expect("DictArray::try_new should succeed for test data")
}
11 changes: 6 additions & 5 deletions encodings/pco/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ use vortex_dtype::half;
use vortex_error::VortexError;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::VortexUnwrap;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_err;
Expand Down Expand Up @@ -377,7 +376,7 @@ impl PcoArray {
// may exceed the bounds of the slice, so we need to slice later.
let (fd, _) = FileDecompressor::new(self.metadata.header.as_slice())
.map_err(vortex_err_from_pco)
.vortex_unwrap();
.vortex_expect("FileDecompressor::new should succeed with valid header");
let mut decompressed_values = BufferMut::<T>::with_capacity(slice_n_values);
let mut page_idx = 0;
let mut page_value_start = 0;
Expand Down Expand Up @@ -406,18 +405,20 @@ impl PcoArray {
let (new_cd, _) = fd
.chunk_decompressor(chunk_meta_bytes)
.map_err(vortex_err_from_pco)
.vortex_unwrap();
.vortex_expect(
"chunk_decompressor should succeed with valid chunk metadata",
);
cd = Some(new_cd);
}
let mut pd = cd
.as_mut()
.unwrap()
.page_decompressor(page, page_n_values)
.map_err(vortex_err_from_pco)
.vortex_unwrap();
.vortex_expect("page_decompressor should succeed with valid page data");
pd.decompress(&mut decompressed_values[old_len..new_len])
.map_err(vortex_err_from_pco)
.vortex_unwrap();
.vortex_expect("decompress should succeed with valid compressed data");
} else {
n_skipped_values += page_n_values;
}
Expand Down
7 changes: 3 additions & 4 deletions encodings/runend/src/compute/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use vortex_dtype::NativePType;
use vortex_dtype::match_each_unsigned_integer_ptype;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::VortexUnwrap;
use vortex_mask::Mask;

use crate::RunEndArray;
Expand Down Expand Up @@ -118,9 +117,9 @@ fn filter_run_end_primitive<R: NativePType + AddAssign + From<bool> + AsPrimitiv
let end = min(run_ends[i].as_() - offset, length);

// Safety: predicate must be the same length as the array the ends have been taken from
for pred in
(start..end).map(|i| unsafe { mask.value_unchecked(i.try_into().vortex_unwrap()) })
{
for pred in (start..end).map(|i| unsafe {
mask.value_unchecked(i.try_into().vortex_expect("index must fit in usize"))
}) {
count += <R as From<bool>>::from(pred);
keep |= pred
}
Expand Down
4 changes: 2 additions & 2 deletions encodings/sparse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ mod test {
use vortex_dtype::DType;
use vortex_dtype::Nullability;
use vortex_dtype::PType;
use vortex_error::VortexUnwrap;
use vortex_error::VortexExpect;
use vortex_scalar::PrimitiveScalar;
use vortex_scalar::Scalar;

Expand Down Expand Up @@ -684,7 +684,7 @@ mod test {
.into_array(),
None,
)
.vortex_unwrap();
.vortex_expect("SparseArray::encode should succeed for test data");
let canonical = sparse.to_primitive();
assert_eq!(
sparse.validity_mask(),
Expand Down
20 changes: 10 additions & 10 deletions fuzz/fuzz_targets/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use vortex_buffer::ByteBufferMut;
use vortex_dtype::DType;
use vortex_dtype::StructFields;
use vortex_error::VortexExpect;
use vortex_error::VortexUnwrap;
use vortex_error::vortex_panic;
use vortex_file::OpenOptionsSessionExt;
use vortex_file::WriteOptionsSessionExt;
Expand Down Expand Up @@ -52,14 +51,15 @@ fuzz_target!(|fuzz: FuzzFileAction| -> Corpus {
.clone()
.unwrap_or_else(|| lit(true))
.evaluate(&array_data)
.vortex_unwrap();
.vortex_expect("filter expression evaluation should succeed in fuzz test");
let mask = bool_mask.to_bool().to_mask_fill_null_false();
let filtered = filter(&array_data, &mask).vortex_unwrap();
let filtered = filter(&array_data, &mask)
.vortex_expect("filter operation should succeed in fuzz test");
projection_expr
.clone()
.unwrap_or_else(root)
.evaluate(&filtered)
.vortex_unwrap()
.vortex_expect("projection expression evaluation should succeed in fuzz test")
};

let write_options = match compressor_strategy {
Expand All @@ -76,20 +76,20 @@ fuzz_target!(|fuzz: FuzzFileAction| -> Corpus {
let _footer = write_options
.blocking(&*RUNTIME)
.write(&mut full_buff, array_data.to_array_iterator())
.vortex_unwrap();
.vortex_expect("file write should succeed in fuzz test");

let mut output = SESSION
.open_options()
.open_buffer(full_buff)
.vortex_unwrap()
.vortex_expect("open_buffer should succeed in fuzz test")
.scan()
.vortex_unwrap()
.vortex_expect("scan should succeed in fuzz test")
.with_projection(projection_expr.unwrap_or_else(root))
.with_some_filter(filter_expr)
.into_array_iter(&*RUNTIME)
.vortex_unwrap()
.vortex_expect("into_array_iter should succeed in fuzz test")
.try_collect::<_, Vec<_>, _>()
.vortex_unwrap();
.vortex_expect("collect should succeed in fuzz test");

let output_array = match output.len() {
0 => Canonical::empty(expected_array.dtype()).into_array(),
Expand All @@ -113,7 +113,7 @@ fuzz_target!(|fuzz: FuzzFileAction| -> Corpus {
);

let bool_result = compare(&expected_array, &output_array, Operator::Eq)
.vortex_unwrap()
.vortex_expect("compare operation should succeed in fuzz test")
.to_bool();
let true_count = bool_result.bit_buffer().true_count();
if true_count != expected_array.len() && (bool_result.all_valid() || expected_array.all_valid())
Expand Down
9 changes: 5 additions & 4 deletions fuzz/src/array/fill_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use vortex_dtype::match_each_decimal_value_type;
use vortex_dtype::match_each_native_ptype;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::VortexUnwrap;
use vortex_scalar::Scalar;

/// Apply fill_null on the canonical form of the array to get a consistent baseline.
Expand Down Expand Up @@ -87,7 +86,8 @@ fn fill_primitive_array(
result_nullability: Nullability,
) -> ArrayRef {
match_each_native_ptype!(array.ptype(), |T| {
let fill_val = T::try_from(fill_value).vortex_unwrap();
let fill_val = T::try_from(fill_value)
.vortex_expect("fill value conversion should succeed in fuzz test");

match array.validity() {
Validity::NonNullable | Validity::AllValid => PrimitiveArray::from_byte_buffer(
Expand Down Expand Up @@ -129,7 +129,8 @@ fn fill_decimal_array(
let decimal_scalar = fill_value.as_decimal();

match_each_decimal_value_type!(array.values_type(), |D| {
let fill_val = D::try_from(decimal_scalar).vortex_unwrap();
let fill_val = D::try_from(decimal_scalar)
.vortex_expect("decimal fill value conversion should succeed in fuzz test");

match array.validity() {
Validity::NonNullable | Validity::AllValid => DecimalArray::new(
Expand All @@ -156,7 +157,7 @@ fn fill_decimal_array(
}

DecimalArray::try_new(new_data.freeze(), decimal_dtype, result_nullability.into())
.vortex_unwrap()
.vortex_expect("DecimalArray creation should succeed in fuzz test")
.into_array()
}
}
Expand Down
8 changes: 4 additions & 4 deletions fuzz/src/array/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use vortex_array::arrays::VarBinViewArray;
use vortex_array::vtable::ValidityHelper;
use vortex_dtype::ExtDType;
use vortex_dtype::match_each_decimal_value_type;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::VortexUnwrap;
use vortex_mask::Mask;

/// Apply mask on the canonical form of the array to get a consistent baseline.
Expand Down Expand Up @@ -94,13 +94,13 @@ pub fn mask_canonical_array(canonical: Canonical, mask: &Mask) -> VortexResult<A
array.len(),
new_validity,
)
.vortex_unwrap()
.vortex_expect("StructArray creation should succeed in fuzz test")
.into_array()
}
Canonical::Extension(array) => {
// Recursively mask the storage array
let masked_storage =
mask_canonical_array(array.storage().to_canonical(), mask).vortex_unwrap();
let masked_storage = mask_canonical_array(array.storage().to_canonical(), mask)
.vortex_expect("mask_canonical_array should succeed in fuzz test");

if masked_storage.dtype().nullability()
== array.ext_dtype().storage_dtype().nullability()
Expand Down
Loading
Loading