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
3 changes: 3 additions & 0 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
- `vortex_err!` for creating errors
- `vortex_bail!` for returning errors
- `vortex_panic!` for handling invariant violations
- `vortex_ensure!` and `vortex_ensure_eq!` for checking conditions. Prefer
`vortex_ensure_eq!(a, b)` with no message: the error already shows both expressions and values.
Add a message only for context the expressions lack, and never repeat the values in it.
- Add context to errors using `.with_context()`
- Include backtraces for better debugging
- Use `VortexExpect` trait when unwrapping is appropriate with proper error context.
Expand Down
34 changes: 8 additions & 26 deletions encodings/alp/src/alp/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_panic;
use vortex_session::VortexSession;
use vortex_session::registry::CachedId;
Expand Down Expand Up @@ -288,12 +289,7 @@ impl ALPData {

// Validate patches
if let Some(patches) = patches {
vortex_ensure!(
patches.array_len() == encoded.len(),
"patches array_len != encoded len: {} != {}",
patches.array_len(),
encoded.len()
);
vortex_ensure_eq!(patches.array_len(), encoded.len());

// Verify that the patches DType are of the proper DType.
}
Expand All @@ -318,19 +314,10 @@ impl ALPData {
patches: &Patches,
encoded: &ArrayRef,
) -> VortexResult<()> {
vortex_ensure!(
patches.array_len() == encoded.len(),
"patches array_len != encoded len: {} != {}",
patches.array_len(),
encoded.len()
);
vortex_ensure_eq!(patches.array_len(), encoded.len());

let expected_type = DType::Primitive(T::PTYPE, encoded.dtype().nullability());
vortex_ensure!(
patches.dtype() == &expected_type,
"Expected patches type {expected_type}, actual {}",
patches.dtype(),
);
vortex_ensure_eq!(patches.dtype(), &expected_type);

Ok(())
}
Expand Down Expand Up @@ -443,16 +430,11 @@ fn validate_parts(
) -> VortexResult<()> {
let logical_dtype = ALPData::logical_dtype(encoded)?;
ALPData::validate_components(encoded, exponents, patches.as_ref())?;
vortex_ensure!(
encoded.len() == len,
"ALP encoded len {} != outer len {len}",
encoded.len(),
);
vortex_ensure!(
&logical_dtype == dtype,
"ALP dtype {} does not match encoded logical dtype {}",
vortex_ensure_eq!(encoded.len(), len, "ALP encoded len must match outer len");
vortex_ensure_eq!(
&logical_dtype,
dtype,
logical_dtype,
"ALP dtype does not match encoded logical dtype"
);
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions encodings/alp/src/alp/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use vortex_array::IntoArray;
use vortex_array::VortexSessionExecute;
use vortex_array::arrays::Patched;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_err;
use vortex_session::VortexSession;

Expand Down Expand Up @@ -52,10 +52,10 @@ impl ArrayPlugin for ALPPatchedPlugin {
parts: ArrayDeserialization<'_>,
session: &VortexSession,
) -> VortexResult<ArrayRef> {
vortex_ensure!(
parts.serialized_id == self.id(),
"ALP plugin does not recognize serialized ID {}",
vortex_ensure_eq!(
parts.serialized_id,
self.id(),
"ALP plugin does not recognize serialized ID"
);
let alp_array = Array::<ALP>::try_from_parts(ArrayVTable::deserialize(
&ALP,
Expand Down
34 changes: 8 additions & 26 deletions encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use vortex_buffer::Buffer;
use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_err;
use vortex_error::vortex_panic;
use vortex_session::VortexSession;
Expand Down Expand Up @@ -475,16 +475,8 @@ fn validate_parts(
vortex_bail!("ALPRDArray given invalid DType ({dtype})");
}

vortex_ensure!(
left_parts.len() == len,
"left_parts len {} != outer len {len}",
left_parts.len(),
);
vortex_ensure!(
right_parts.len() == len,
"right_parts len {} != outer len {len}",
right_parts.len(),
);
vortex_ensure_eq!(left_parts.len(), len);
vortex_ensure_eq!(right_parts.len(), len);

if !left_parts.dtype().is_unsigned_int() {
vortex_bail!("left_parts dtype must be uint");
Expand All @@ -502,29 +494,19 @@ fn validate_parts(
DType::Primitive(PType::F64, _) => DType::Primitive(PType::U64, Nullability::NonNullable),
_ => vortex_bail!("Expected f32 or f64 dtype, got {:?}", dtype),
};
vortex_ensure!(
right_parts.dtype() == &expected_right_parts_dtype,
"right_parts dtype {} does not match expected {}",
right_parts.dtype(),
expected_right_parts_dtype,
);
vortex_ensure_eq!(right_parts.dtype(), &expected_right_parts_dtype);

if let Some(patches) = left_parts_patches {
vortex_ensure!(
patches.array_len() == len,
"patches array_len {} != outer len {len}",
patches.array_len(),
);
vortex_ensure_eq!(patches.array_len(), len);
// Left-parts exceptions are always all-valid and are stored as the non-nullable left-parts
// dtype. Requiring that exact dtype (rather than ignoring nullability) means each
// construction path must produce correct patches, removing the need to normalize them.
// Non-nullable also implies all-valid, so no separate validity check is required.
let expected = left_parts.dtype().as_nonnullable();
vortex_ensure!(
patches.dtype() == &expected,
"patches dtype {} must be the non-nullable left_parts dtype {}",
vortex_ensure_eq!(
patches.dtype(),
expected,
&expected,
"patches dtype must be the non-nullable left_parts dtype"
);
}

Expand Down
21 changes: 5 additions & 16 deletions encodings/bytebool/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use vortex_buffer::BitBufferMut;
use vortex_buffer::ByteBuffer;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_panic;
use vortex_session::VortexSession;
use vortex_session::registry::CachedId;
Expand Down Expand Up @@ -101,11 +101,7 @@ impl VTable for ByteBool {
array: ArrayView<'_, Self>,
buffers: &[BufferHandle],
) -> VortexResult<ArrayParts<Self>> {
vortex_ensure!(
buffers.len() == 1,
"Expected 1 buffer, got {}",
buffers.len()
);
vortex_ensure_eq!(buffers.len(), 1);
let data = ByteBoolData::new(buffers[0].clone());
Ok(
ArrayParts::new(self.clone(), array.dtype().clone(), array.len(), data)
Expand Down Expand Up @@ -260,17 +256,10 @@ impl ByteBoolData {
len: usize,
) -> VortexResult<()> {
let expected_dtype = DType::Bool(validity.nullability());
vortex_ensure!(
dtype == &expected_dtype,
"expected dtype {expected_dtype}, got {dtype}"
);
vortex_ensure!(
buffer.len() == len,
"expected len {len}, got {}",
buffer.len()
);
vortex_ensure_eq!(dtype, &expected_dtype);
vortex_ensure_eq!(buffer.len(), len);
if let Some(vlen) = validity.maybe_len() {
vortex_ensure!(vlen == len, "expected validity len {len}, got {vlen}");
vortex_ensure_eq!(vlen, len);
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions encodings/datetime-parts/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use vortex_array::vtable::ValidityChild;
use vortex_array::vtable::ValidityVTableFromChild;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_err;
use vortex_error::vortex_panic;
use vortex_session::VortexSession;
Expand Down Expand Up @@ -309,7 +309,7 @@ impl DateTimePartsData {
subseconds: &ArrayRef,
len: usize,
) -> VortexResult<()> {
vortex_ensure!(days.len() == len, "expected len {len}, got {}", days.len());
vortex_ensure_eq!(days.len(), len);

if !days.dtype().is_int() || (dtype.is_nullable() != days.dtype().is_nullable()) {
vortex_bail!(
Expand Down
14 changes: 4 additions & 10 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use vortex_error::VortexExpect;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_panic;
use vortex_session::VortexSession;

Expand Down Expand Up @@ -96,11 +97,8 @@ impl DecimalBytePartsData {
}

let expected_dtype = DType::Decimal(decimal_dtype, msp.dtype().nullability());
vortex_ensure!(
dtype == &expected_dtype,
"expected dtype {expected_dtype}, got {dtype}"
);
vortex_ensure!(msp.len() == len, "expected len {len}, got {}", msp.len());
vortex_ensure_eq!(dtype, &expected_dtype);
vortex_ensure_eq!(msp.len(), len);

let lower_part_count = lower_parts.len();

Expand All @@ -114,11 +112,7 @@ impl DecimalBytePartsData {
"lower part {idx} must have a non-nullable unsigned integer dtype, got {}",
part.dtype()
);
vortex_ensure!(
part.len() == len,
"lower part {idx} has len {}, expected {len}",
part.len()
);
vortex_ensure_eq!(part.len(), len, "lower part {idx} length mismatch");
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use vortex_buffer::trusted_len::TrustedLen;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;

use super::LOWER_PART_BITS;
use super::LOWER_PART_DTYPE;
Expand Down Expand Up @@ -72,11 +73,7 @@ pub fn assemble_decimal(
"lower part {idx} must have a non-nullable unsigned integer dtype, got {}",
part.dtype()
);
vortex_ensure!(
part.len() == len,
"lower part {idx} has len {}, expected {len}",
part.len()
);
vortex_ensure_eq!(part.len(), len, "lower part {idx} length mismatch");
}

assemble_wide_decimal_from_arrays(msp, lower_parts, validity, decimal_dtype, exec_ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ fn v1_metadata_is_unchanged() -> VortexResult<()> {
decimal_byte_parts_v2_id(),
v2_metadata(vec![PType::U64 as i32]),
vec![msp()],
"expected 2 children, got 1"
"v2 expects the msp child plus one child per lower part"
)]
#[case::v2_extra_child(
decimal_byte_parts_v2_id(),
v2_metadata(vec![PType::U64 as i32]),
vec![msp(), lower_part(), lower_part()],
"expected 2 children, got 3"
"v2 expects the msp child plus one child per lower part"
)]
#[case::v2_too_many_lower_parts(
decimal_byte_parts_v2_id(),
Expand Down
13 changes: 8 additions & 5 deletions encodings/decimal-byte-parts/src/decimal_byte_parts/plugin/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use vortex_array::dtype::PType;
use vortex_array::smallvec::smallvec;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;

use super::decimal_byte_parts_v1_id;
use crate::DecimalByteParts;
Expand Down Expand Up @@ -51,20 +52,22 @@ pub(super) fn serialize(
}

pub(super) fn deserialize(parts: ArrayDeserialization<'_>) -> VortexResult<DecimalBytePartsArray> {
vortex_ensure!(
parts.serialized_id == decimal_byte_parts_v1_id(),
vortex_ensure_eq!(
parts.serialized_id,
decimal_byte_parts_v1_id(),
"expected the v1 format"
);
let metadata = DecimalBytePartsMetadata::decode(parts.metadata)?;
vortex_ensure!(
parts.dtype.as_decimal_opt().is_some(),
"expected a decimal dtype"
);
vortex_ensure!(
metadata.lower_part_count == 0,
vortex_ensure_eq!(
metadata.lower_part_count,
0,
"v1 must not carry lower parts"
);
vortex_ensure!(parts.children.len() == 1, "v1 must carry exactly one child");
vortex_ensure_eq!(parts.children.len(), 1, "v1 must carry exactly one child");
let ptype = PType::try_from(metadata.zeroth_child_ptype)?;
vortex_ensure!(
ptype.is_signed_int(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use vortex_array::dtype::Nullability;
use vortex_array::dtype::PType;
use vortex_error::VortexResult;
use vortex_error::vortex_ensure;
use vortex_error::vortex_ensure_eq;
use vortex_error::vortex_err;

use super::decimal_byte_parts_v2_id;
Expand Down Expand Up @@ -73,11 +74,10 @@ pub(super) fn deserialize(parts: ArrayDeserialization<'_>) -> VortexResult<Decim
lower_part_count <= MAX_LOWER_PARTS,
"v2 carries at most {MAX_LOWER_PARTS} lower parts, got {lower_part_count}"
);
vortex_ensure!(
parts.children.len() == 1 + lower_part_count,
"expected {} children, got {}",
vortex_ensure_eq!(
parts.children.len(),
1 + lower_part_count,
parts.children.len()
"v2 expects the msp child plus one child per lower part"
);

let msp_ptype = PType::try_from(metadata.msp_ptype)?;
Expand Down
Loading
Loading