From 7f86522c2254c7b6bae2b09600827f2ae7c2683d Mon Sep 17 00:00:00 2001 From: Robert Kruszewski Date: Fri, 9 Oct 2026 00:09:34 +0100 Subject: [PATCH] Expose slots, dtype, len and is_empty on TypedArrayRef Extension traits over TypedArrayRef had to go through self.as_ref() to reach the backing ArrayRef for slots, dtype and length. Add these accessors to TypedArrayRef so the extension traits can call self.slots(), self.dtype() and self.len() directly. The accessors have default implementations through AsRef, so Array and ArrayView need no new code. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Robert Kruszewski --- encodings/alp/src/alp/array.rs | 4 ++-- encodings/alp/src/alp_rd/array.rs | 6 +---- encodings/bytebool/src/array.rs | 4 ++-- .../fastlanes/src/bitpacking/array/mod.rs | 13 ++++------ encodings/fastlanes/src/for_/array/mod.rs | 2 +- encodings/fsst/src/array.rs | 7 +++--- encodings/onpair/src/array.rs | 4 ++-- encodings/parquet-variant/src/array.rs | 4 ++-- encodings/pco/src/array.rs | 4 ++-- encodings/sparse/src/lib.rs | 6 ++--- vortex-array-macros/src/lib.rs | 8 +++---- vortex-array/src/array/typed.rs | 24 +++++++++++++++++++ vortex-array/src/array/view.rs | 4 ++++ vortex-array/src/arrays/bool/array.rs | 8 +++---- vortex-array/src/arrays/bool/test_harness.rs | 4 ++-- vortex-array/src/arrays/chunked/array.rs | 18 ++++++-------- .../src/arrays/chunked/paired_chunks.rs | 4 ++-- vortex-array/src/arrays/decimal/array.rs | 8 +++---- vortex-array/src/arrays/extension/array.rs | 3 +-- .../src/arrays/fixed_size_list/array.rs | 8 +++---- vortex-array/src/arrays/interleave/mod.rs | 6 ++--- vortex-array/src/arrays/list/array.rs | 10 ++++---- vortex-array/src/arrays/listview/array.rs | 14 +++++------ vortex-array/src/arrays/map/array.rs | 3 +-- vortex-array/src/arrays/masked/array.rs | 4 ++-- vortex-array/src/arrays/patched/array.rs | 6 ++--- .../src/arrays/primitive/array/mod.rs | 10 ++++---- .../src/arrays/primitive/array/top_value.rs | 4 +--- vortex-array/src/arrays/scalar_fn/array.rs | 4 ++-- vortex-array/src/arrays/struct_/array.rs | 6 ++--- vortex-array/src/arrays/union/array.rs | 2 +- vortex-array/src/arrays/varbin/array.rs | 10 ++++---- vortex-array/src/arrays/varbinview/array.rs | 4 ++-- vortex-array/src/arrays/varbinview/compact.rs | 6 +---- 34 files changed, 119 insertions(+), 113 deletions(-) diff --git a/encodings/alp/src/alp/array.rs b/encodings/alp/src/alp/array.rs index d54406bf1e5..319a08c7385 100644 --- a/encodings/alp/src/alp/array.rs +++ b/encodings/alp/src/alp/array.rs @@ -421,8 +421,8 @@ pub trait ALPArrayExt: ALPArraySlotsExt { fn patches(&self) -> Option { PatchesData::patches_from_slots( self.patches_data.as_ref(), - self.as_ref().len(), - self.as_ref().slots(), + self.len(), + self.slots(), PATCH_SLOTS, ) } diff --git a/encodings/alp/src/alp_rd/array.rs b/encodings/alp/src/alp_rd/array.rs index 4d7340e78df..b11b4f8cacc 100644 --- a/encodings/alp/src/alp_rd/array.rs +++ b/encodings/alp/src/alp_rd/array.rs @@ -523,11 +523,7 @@ pub trait ALPRDArrayExt: ALPRDArraySlotsExt { } fn left_parts_patches(&self) -> Option { - patches_from_slots( - self.as_ref().slots(), - self.patches_data.as_ref(), - self.as_ref().len(), - ) + patches_from_slots(self.slots(), self.patches_data.as_ref(), self.len()) } fn left_parts_dictionary(&self) -> &Buffer { diff --git a/encodings/bytebool/src/array.rs b/encodings/bytebool/src/array.rs index 6ece5c98022..737934c9cac 100644 --- a/encodings/bytebool/src/array.rs +++ b/encodings/bytebool/src/array.rs @@ -203,8 +203,8 @@ pub trait ByteBoolArrayExt: TypedArrayRef + ByteBoolArraySlotsExt { /// Returns the [`Validity`] derived from the validity slot. fn bytebool_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[ByteBoolSlots::VALIDITY].as_ref(), - self.as_ref().dtype().nullability(), + self.slots()[ByteBoolSlots::VALIDITY].as_ref(), + self.dtype().nullability(), ) } } diff --git a/encodings/fastlanes/src/bitpacking/array/mod.rs b/encodings/fastlanes/src/bitpacking/array/mod.rs index 4e15d29030c..d959d453a1f 100644 --- a/encodings/fastlanes/src/bitpacking/array/mod.rs +++ b/encodings/fastlanes/src/bitpacking/array/mod.rs @@ -459,15 +459,15 @@ pub trait BitPackedArrayExt: BitPackedArraySlotsExt { fn patches(&self) -> Option { PatchesData::patches_from_slots( self.patches_data.as_ref(), - self.as_ref().len(), - self.as_ref().slots(), + self.len(), + self.slots(), PATCH_SLOTS, ) } #[inline] fn validity(&self) -> Validity { - child_to_validity(self.validity_child(), self.as_ref().dtype().nullability()) + child_to_validity(self.validity_child(), self.dtype().nullability()) } #[inline] @@ -480,12 +480,7 @@ pub trait BitPackedArrayExt: BitPackedArraySlotsExt { &'a self, scratch: &'a mut [MaybeUninit; FL_CHUNK_SIZE], ) -> VortexResult> { - BitPackedData::unpacked_chunks::( - self, - self.as_ref().dtype(), - self.as_ref().len(), - scratch, - ) + BitPackedData::unpacked_chunks::(self, self.dtype(), self.len(), scratch) } } diff --git a/encodings/fastlanes/src/for_/array/mod.rs b/encodings/fastlanes/src/for_/array/mod.rs index 49c184ee251..79aff270600 100644 --- a/encodings/fastlanes/src/for_/array/mod.rs +++ b/encodings/fastlanes/src/for_/array/mod.rs @@ -54,7 +54,7 @@ pub trait FoRArrayExt: FoRArraySlotsExt { #[inline] fn ptype(&self) -> PType { - self.as_ref().dtype().as_ptype() + self.dtype().as_ptype() } } diff --git a/encodings/fsst/src/array.rs b/encodings/fsst/src/array.rs index 725e4ba2b31..3f8bd2e5541 100644 --- a/encodings/fsst/src/array.rs +++ b/encodings/fsst/src/array.rs @@ -1022,15 +1022,14 @@ pub trait FSSTArrayExt: FSSTArraySlotsExt { /// from [`FSSTData`] with the offsets and validity stored in the array's slots. fn codes(&self) -> VarBinArray { let offsets = self.codes_offsets().clone(); - let validity = - child_to_validity(self.codes_validity(), self.as_ref().dtype().nullability()); + let validity = child_to_validity(self.codes_validity(), self.dtype().nullability()); let codes_bytes = self.codes_bytes_handle().clone(); // SAFETY: components were validated at construction time. unsafe { VarBinArray::new_unchecked_from_handle( offsets, codes_bytes, - DType::Binary(self.as_ref().dtype().nullability()), + DType::Binary(self.dtype().nullability()), validity, ) } @@ -1038,7 +1037,7 @@ pub trait FSSTArrayExt: FSSTArraySlotsExt { /// Get the DType of the codes array. fn codes_dtype(&self) -> DType { - DType::Binary(self.as_ref().dtype().nullability()) + DType::Binary(self.dtype().nullability()) } } diff --git a/encodings/onpair/src/array.rs b/encodings/onpair/src/array.rs index 45c764e13a7..d48287fac84 100644 --- a/encodings/onpair/src/array.rs +++ b/encodings/onpair/src/array.rs @@ -732,8 +732,8 @@ pub trait OnPairArrayExt: OnPairArraySlotsExt { /// the outer dtype's nullability. fn array_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[OnPairSlots::VALIDITY].as_ref(), - self.as_ref().dtype().nullability(), + self.slots()[OnPairSlots::VALIDITY].as_ref(), + self.dtype().nullability(), ) } } diff --git a/encodings/parquet-variant/src/array.rs b/encodings/parquet-variant/src/array.rs index f57744ca817..39e7f1bd4ee 100644 --- a/encodings/parquet-variant/src/array.rs +++ b/encodings/parquet-variant/src/array.rs @@ -431,8 +431,8 @@ pub trait ParquetVariantArrayExt: /// Returns the outer row validity for the Variant values. fn parquet_variant_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[ParquetVariantSlots::VALIDITY].as_ref(), - self.as_ref().dtype().nullability(), + self.slots()[ParquetVariantSlots::VALIDITY].as_ref(), + self.dtype().nullability(), ) } diff --git a/encodings/pco/src/array.rs b/encodings/pco/src/array.rs index fa970d3b35d..627f0bc0751 100644 --- a/encodings/pco/src/array.rs +++ b/encodings/pco/src/array.rs @@ -374,8 +374,8 @@ pub trait PcoArrayExt: PcoArraySlotsExt { /// Reconstruct the unsliced [`Validity`] from the validity slot. fn unsliced_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[PcoSlots::VALIDITY].as_ref(), - self.as_ref().dtype().nullability(), + self.slots()[PcoSlots::VALIDITY].as_ref(), + self.dtype().nullability(), ) } } diff --git a/encodings/sparse/src/lib.rs b/encodings/sparse/src/lib.rs index 5ee07e53d83..90f594a35f8 100644 --- a/encodings/sparse/src/lib.rs +++ b/encodings/sparse/src/lib.rs @@ -151,13 +151,13 @@ impl SparseOwnedExt for Array { let patches = Patches::new( self.len(), self.patches().offset(), - self.as_ref().slots()[SparseSlots::PATCH_INDICES] + self.slots()[SparseSlots::PATCH_INDICES] .clone() .vortex_expect("indices"), - self.as_ref().slots()[SparseSlots::PATCH_VALUES] + self.slots()[SparseSlots::PATCH_VALUES] .clone() .vortex_expect("values"), - self.as_ref().slots()[SparseSlots::PATCH_CHUNK_OFFSETS].clone(), + self.slots()[SparseSlots::PATCH_CHUNK_OFFSETS].clone(), )?; Ok(SparseParts { patches, diff --git a/vortex-array-macros/src/lib.rs b/vortex-array-macros/src/lib.rs index 5270e8b8e00..1363b42cdbe 100644 --- a/vortex-array-macros/src/lib.rs +++ b/vortex-array-macros/src/lib.rs @@ -283,7 +283,7 @@ fn expand_array_slots( #[doc = "Returns a borrowed view of all slots."] fn slots_view(&self) -> #view_ident<'_> { - #view_ident::from_slots(self.as_ref().slots()) + #view_ident::from_slots(self.slots()) } } @@ -661,7 +661,7 @@ impl SlotField { #[inline] fn #field_ident(&self) -> &::vortex_array::ArrayRef { ::vortex_error::VortexExpect::vortex_expect( - self.as_ref().slots()[#struct_ident::#const_ident].as_ref(), + self.slots()[#struct_ident::#const_ident].as_ref(), #expect_message, ) } @@ -669,14 +669,14 @@ impl SlotField { SlotFieldType::Optional => quote! { #[inline] fn #field_ident(&self) -> Option<&::vortex_array::ArrayRef> { - self.as_ref().slots()[#struct_ident::#const_ident].as_ref() + self.slots()[#struct_ident::#const_ident].as_ref() } }, SlotFieldType::VariadicTail => quote! { #[inline] fn #field_ident(&self) -> ::vortex_array::SlotSlice<'_> { ::vortex_array::SlotSlice::new( - &self.as_ref().slots()[#struct_ident::#const_ident..], + &self.slots()[#struct_ident::#const_ident..], #expect_message, ) } diff --git a/vortex-array/src/array/typed.rs b/vortex-array/src/array/typed.rs index d67e03349cf..feeda1d2118 100644 --- a/vortex-array/src/array/typed.rs +++ b/vortex-array/src/array/typed.rs @@ -98,6 +98,26 @@ pub trait TypedArrayRef: AsRef + Deref Array { self.as_ref().clone().downcast() } + + /// Returns the child slots of the array. + fn slots(&self) -> &[Option] { + self.as_ref().slots() + } + + /// Returns the logical [`DType`] of the array. + fn dtype(&self) -> &DType { + self.as_ref().dtype() + } + + /// Returns the number of rows in the array. + fn len(&self) -> usize { + self.as_ref().len() + } + + /// Returns `true` if the array has no rows. + fn is_empty(&self) -> bool { + self.as_ref().is_empty() + } } impl TypedArrayRef for Array {} @@ -281,16 +301,19 @@ impl Array { } /// Returns the logical dtype. + #[allow(clippy::same_name_method)] pub fn dtype(&self) -> &DType { self.inner.dtype() } /// Returns the length. + #[allow(clippy::same_name_method)] pub fn len(&self) -> usize { self.inner.len() } /// Returns whether this array is empty. + #[allow(clippy::same_name_method)] pub fn is_empty(&self) -> bool { self.inner.len() == 0 } @@ -352,6 +375,7 @@ impl Array { } /// Returns the array slots. + #[allow(clippy::same_name_method)] pub fn slots(&self) -> &[Option] { self.inner.slots() } diff --git a/vortex-array/src/array/view.rs b/vortex-array/src/array/view.rs index e5e937e0141..65ece406a65 100644 --- a/vortex-array/src/array/view.rs +++ b/vortex-array/src/array/view.rs @@ -52,21 +52,25 @@ impl<'a, V: VTable> ArrayView<'a, V> { } /// Returns this array's child slots. + #[allow(clippy::same_name_method)] pub fn slots(&self) -> &'a [Option] { self.array.slots() } /// Returns the logical dtype. + #[allow(clippy::same_name_method)] pub fn dtype(&self) -> &DType { self.array.dtype() } /// Returns the number of rows. + #[allow(clippy::same_name_method)] pub fn len(&self) -> usize { self.array.len() } /// Returns `true` when the array has no rows. + #[allow(clippy::same_name_method)] pub fn is_empty(&self) -> bool { self.array.len() == 0 } diff --git a/vortex-array/src/arrays/bool/array.rs b/vortex-array/src/arrays/bool/array.rs index 326bcfdb929..0d9d40782c4 100644 --- a/vortex-array/src/arrays/bool/array.rs +++ b/vortex-array/src/arrays/bool/array.rs @@ -90,7 +90,7 @@ pub struct BoolDataParts { pub trait BoolArrayExt: TypedArrayRef { fn nullability(&self) -> crate::dtype::Nullability { - match self.as_ref().dtype() { + match self.dtype() { DType::Bool(nullability) => *nullability, _ => unreachable!("BoolArrayExt requires a bool dtype"), } @@ -98,7 +98,7 @@ pub trait BoolArrayExt: TypedArrayRef { fn validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[BoolSlots::VALIDITY].as_ref(), + self.slots()[BoolSlots::VALIDITY].as_ref(), self.nullability(), ) } @@ -130,11 +130,11 @@ pub trait BoolArrayExt: TypedArrayRef { fn to_mask_fill_null_false(&self, ctx: &mut ExecutionCtx) -> Mask { let validity_mask = BoolArrayExt::validity(self) - .execute_mask(self.as_ref().len(), ctx) + .execute_mask(self.len(), ctx) .vortex_expect("Failed to compute validity mask"); let buffer = match validity_mask { Mask::AllTrue(_) => self.to_bit_buffer(), - Mask::AllFalse(_) => return Mask::new_false(self.as_ref().len()), + Mask::AllFalse(_) => return Mask::new_false(self.len()), Mask::Values(validity) => validity.bit_buffer() & self.to_bit_buffer(), }; Mask::from_buffer(buffer) diff --git a/vortex-array/src/arrays/bool/test_harness.rs b/vortex-array/src/arrays/bool/test_harness.rs index 1b6aca704a3..66bfd26771c 100644 --- a/vortex-array/src/arrays/bool/test_harness.rs +++ b/vortex-array/src/arrays/bool/test_harness.rs @@ -12,7 +12,7 @@ impl BoolArray { pub fn opt_bool_vec(&self, ctx: &mut ExecutionCtx) -> Vec> { self.validity() .vortex_expect("failed to get validity") - .execute_mask(self.as_ref().len(), ctx) + .execute_mask(self.len(), ctx) .vortex_expect("Failed to compute validity mask") .to_bit_buffer() .iter() @@ -24,7 +24,7 @@ impl BoolArray { pub fn bool_vec(&self, ctx: &mut ExecutionCtx) -> Vec { self.validity() .vortex_expect("failed to get validity") - .execute_mask(self.as_ref().len(), ctx) + .execute_mask(self.len(), ctx) .vortex_expect("Failed to compute validity mask") .to_bit_buffer() .iter() diff --git a/vortex-array/src/arrays/chunked/array.rs b/vortex-array/src/arrays/chunked/array.rs index 0e68631052e..58bd92ec5bd 100644 --- a/vortex-array/src/arrays/chunked/array.rs +++ b/vortex-array/src/arrays/chunked/array.rs @@ -61,26 +61,25 @@ impl Display for ChunkedData { pub trait ChunkedArrayExt: TypedArrayRef { fn chunk_offsets_array(&self) -> &ArrayRef { - self.as_ref().slots()[ChunkedSlots::CHUNK_OFFSETS] + self.slots()[ChunkedSlots::CHUNK_OFFSETS] .as_ref() .vortex_expect("validated chunk offsets slot") } fn nchunks(&self) -> usize { - self.as_ref() - .slots() + self.slots() .len() .saturating_sub(ChunkedSlots::CHUNKS_OFFSET) } fn chunk(&self, idx: usize) -> &ArrayRef { - self.as_ref().slots()[ChunkedSlots::CHUNKS_OFFSET + idx] + self.slots()[ChunkedSlots::CHUNKS_OFFSET + idx] .as_ref() .vortex_expect("validated chunk slot") } fn iter_chunks(&self) -> impl Iterator { - self.as_ref().slots()[ChunkedSlots::CHUNKS_OFFSET..] + self.slots()[ChunkedSlots::CHUNKS_OFFSET..] .iter() .map(|slot| slot.as_ref().vortex_expect("validated chunk slot")) } @@ -99,10 +98,7 @@ pub trait ChunkedArrayExt: TypedArrayRef { } fn find_chunk_idx(&self, index: usize) -> VortexResult<(usize, usize)> { - assert!( - index <= self.as_ref().len(), - "Index out of bounds of the array" - ); + assert!(index <= self.len(), "Index out of bounds of the array"); let chunk_offset_values = self.chunk_offset_values(); let index_chunk = chunk_offset_values .search_sorted(&index, SearchSortedSide::Right)? @@ -115,14 +111,14 @@ pub trait ChunkedArrayExt: TypedArrayRef { fn array_iterator(&self) -> impl ArrayIterator + '_ { ArrayIteratorAdapter::new( - self.as_ref().dtype().clone(), + self.dtype().clone(), self.iter_chunks().map(|chunk| Ok(chunk.clone())), ) } fn array_stream(&self) -> impl ArrayStream + '_ { ArrayStreamAdapter::new( - self.as_ref().dtype().clone(), + self.dtype().clone(), stream::iter(self.iter_chunks().map(|chunk| Ok(chunk.clone()))), ) } diff --git a/vortex-array/src/arrays/chunked/paired_chunks.rs b/vortex-array/src/arrays/chunked/paired_chunks.rs index c4a73a09518..610c48ecc8e 100644 --- a/vortex-array/src/arrays/chunked/paired_chunks.rs +++ b/vortex-array/src/arrays/chunked/paired_chunks.rs @@ -70,7 +70,7 @@ pub(crate) struct PairedChunks { pub(crate) trait PairedChunksExt: ChunkedArrayExt { fn paired_chunks(&self, other: &T) -> PairedChunks { assert_eq!( - self.as_ref().len(), + self.len(), other.as_ref().len(), "paired_chunks requires arrays of equal length" ); @@ -78,7 +78,7 @@ pub(crate) trait PairedChunksExt: ChunkedArrayExt { left: ChunkCursor::new(self.chunks()), right: ChunkCursor::new(other.chunks()), pos: 0, - total_len: self.as_ref().len(), + total_len: self.len(), } } } diff --git a/vortex-array/src/arrays/decimal/array.rs b/vortex-array/src/arrays/decimal/array.rs index 97c44ff00e8..eff2e5c8688 100644 --- a/vortex-array/src/arrays/decimal/array.rs +++ b/vortex-array/src/arrays/decimal/array.rs @@ -133,26 +133,26 @@ pub struct DecimalDataParts { pub trait DecimalArrayExt: TypedArrayRef { fn decimal_dtype(&self) -> DecimalDType { - match self.as_ref().dtype() { + match self.dtype() { DType::Decimal(decimal_dtype, _) => *decimal_dtype, _ => unreachable!("DecimalArrayExt requires a decimal dtype"), } } fn nullability(&self) -> Nullability { - match self.as_ref().dtype() { + match self.dtype() { DType::Decimal(_, nullability) => *nullability, _ => unreachable!("DecimalArrayExt requires a decimal dtype"), } } fn validity_child(&self) -> Option<&ArrayRef> { - self.as_ref().slots()[DecimalSlots::VALIDITY].as_ref() + self.slots()[DecimalSlots::VALIDITY].as_ref() } fn validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[DecimalSlots::VALIDITY].as_ref(), + self.slots()[DecimalSlots::VALIDITY].as_ref(), self.nullability(), ) } diff --git a/vortex-array/src/arrays/extension/array.rs b/vortex-array/src/arrays/extension/array.rs index f6ef6575a22..841d35dbbea 100644 --- a/vortex-array/src/arrays/extension/array.rs +++ b/vortex-array/src/arrays/extension/array.rs @@ -26,8 +26,7 @@ pub struct ExtensionSlots { pub trait ExtensionArrayExt: TypedArrayRef + ExtensionArraySlotsExt { fn ext_dtype(&self) -> &ExtDTypeRef { - self.as_ref() - .dtype() + self.dtype() .as_extension_opt() .vortex_expect("extension array somehow did not have an extension dtype") } diff --git a/vortex-array/src/arrays/fixed_size_list/array.rs b/vortex-array/src/arrays/fixed_size_list/array.rs index b651b8394b3..6f35e5c91a4 100644 --- a/vortex-array/src/arrays/fixed_size_list/array.rs +++ b/vortex-array/src/arrays/fixed_size_list/array.rs @@ -215,7 +215,7 @@ impl FixedSizeListData { pub trait FixedSizeListArrayExt: FixedSizeListArraySlotsExt { fn dtype_parts(&self) -> (&DType, u32, crate::dtype::Nullability) { - match self.as_ref().dtype() { + match self.dtype() { DType::FixedSizeList(element_dtype, list_size, nullability) => { (element_dtype.as_ref(), *list_size, *nullability) } @@ -231,7 +231,7 @@ pub trait FixedSizeListArrayExt: FixedSizeListArraySlotsExt { fn fixed_size_list_validity(&self) -> Validity { let (_, _, nullability) = self.dtype_parts(); child_to_validity( - self.as_ref().slots()[FixedSizeListSlots::VALIDITY].as_ref(), + self.slots()[FixedSizeListSlots::VALIDITY].as_ref(), nullability, ) } @@ -239,10 +239,10 @@ pub trait FixedSizeListArrayExt: FixedSizeListArraySlotsExt { #[allow(clippy::disallowed_methods)] fn fixed_size_list_elements_at(&self, index: usize) -> VortexResult { debug_assert!( - index < self.as_ref().len(), + index < self.len(), "index {} out of bounds: the len is {}", index, - self.as_ref().len(), + self.len(), ); let start = self.list_size() as usize * index; diff --git a/vortex-array/src/arrays/interleave/mod.rs b/vortex-array/src/arrays/interleave/mod.rs index 5b6cb641cbf..28dfec7e5ee 100644 --- a/vortex-array/src/arrays/interleave/mod.rs +++ b/vortex-array/src/arrays/interleave/mod.rs @@ -122,21 +122,21 @@ pub trait InterleaveArrayExt: TypedArrayRef { /// The `idx`-th value array (holding the rows that `array_indices` routes to it). fn value(&self, idx: usize) -> &ArrayRef { - self.as_ref().slots()[idx + 2] + self.slots()[idx + 2] .as_ref() .vortex_expect("validated interleave value slot") } /// The selector routing each output row to a value array. fn array_indices(&self) -> &ArrayRef { - self.as_ref().slots()[0] + self.slots()[0] .as_ref() .vortex_expect("validated interleave array_indices slot") } /// The selector naming each output row's position within its value array. fn row_indices(&self) -> &ArrayRef { - self.as_ref().slots()[1] + self.slots()[1] .as_ref() .vortex_expect("validated interleave row_indices slot") } diff --git a/vortex-array/src/arrays/list/array.rs b/vortex-array/src/arrays/list/array.rs index 5951d4c86da..4ca88d348e1 100644 --- a/vortex-array/src/arrays/list/array.rs +++ b/vortex-array/src/arrays/list/array.rs @@ -279,7 +279,7 @@ impl ListData { pub trait ListArrayExt: ListArraySlotsExt { fn nullability(&self) -> crate::dtype::Nullability { - match self.as_ref().dtype() { + match self.dtype() { DType::List(_, nullability) => *nullability, _ => unreachable!("ListArrayExt requires a list dtype"), } @@ -287,7 +287,7 @@ pub trait ListArrayExt: ListArraySlotsExt { fn list_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[ListSlots::VALIDITY].as_ref(), + self.slots()[ListSlots::VALIDITY].as_ref(), self.nullability(), ) } @@ -295,9 +295,9 @@ pub trait ListArrayExt: ListArraySlotsExt { #[allow(clippy::disallowed_methods)] fn offset_at(&self, index: usize) -> VortexResult { vortex_ensure!( - index <= self.as_ref().len(), + index <= self.len(), "Index {index} out of bounds 0..={}", - self.as_ref().len() + self.len() ); if let Some(p) = self.offsets().as_opt::() { @@ -321,7 +321,7 @@ pub trait ListArrayExt: ListArraySlotsExt { fn sliced_elements(&self) -> VortexResult { let start = self.offset_at(0)?; - let end = self.offset_at(self.as_ref().len())?; + let end = self.offset_at(self.len())?; self.elements().slice(start..end) } diff --git a/vortex-array/src/arrays/listview/array.rs b/vortex-array/src/arrays/listview/array.rs index 6b0022ccb38..9025541c90d 100644 --- a/vortex-array/src/arrays/listview/array.rs +++ b/vortex-array/src/arrays/listview/array.rs @@ -355,7 +355,7 @@ fn fill_referenced_mask( pub trait ListViewArrayExt: ListViewArraySlotsExt { fn nullability(&self) -> crate::dtype::Nullability { - match self.as_ref().dtype() { + match self.dtype() { DType::List(_, nullability) => *nullability, _ => unreachable!("ListViewArrayExt requires a list dtype"), } @@ -363,7 +363,7 @@ pub trait ListViewArrayExt: ListViewArraySlotsExt { fn listview_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[ListViewSlots::VALIDITY].as_ref(), + self.slots()[ListViewSlots::VALIDITY].as_ref(), self.nullability(), ) } @@ -371,9 +371,9 @@ pub trait ListViewArrayExt: ListViewArraySlotsExt { #[allow(clippy::disallowed_methods)] fn offset_at(&self, index: usize) -> usize { assert!( - index < self.as_ref().len(), + index < self.len(), "Index {index} out of bounds 0..{}", - self.as_ref().len() + self.len() ); self.offsets() .as_opt::() @@ -391,10 +391,10 @@ pub trait ListViewArrayExt: ListViewArraySlotsExt { #[allow(clippy::disallowed_methods)] fn size_at(&self, index: usize) -> usize { assert!( - index < self.as_ref().len(), + index < self.len(), "Index {} out of bounds 0..{}", index, - self.as_ref().len() + self.len() ); self.sizes() .as_opt::() @@ -521,7 +521,7 @@ pub trait ListViewArrayExt: ListViewArraySlotsExt { /// /// The array must contain at least one list (`len() > 0`). fn referenced_element_bounds(&self, ctx: &mut ExecutionCtx) -> VortexResult<(usize, usize)> { - let n_lists = self.as_ref().len(); + let n_lists = self.len(); vortex_ensure!( n_lists > 0, "referenced_element_bounds requires a non-empty array" diff --git a/vortex-array/src/arrays/map/array.rs b/vortex-array/src/arrays/map/array.rs index 29b11d5e745..52af3bc18a8 100644 --- a/vortex-array/src/arrays/map/array.rs +++ b/vortex-array/src/arrays/map/array.rs @@ -92,8 +92,7 @@ pub trait MapArrayExt: MapArraySlotsExt { /// Returns this map's key/value type information. fn map_dtype(&self) -> &MapDType { - self.as_ref() - .dtype() + self.dtype() .as_map_opt() .vortex_expect("MapArray requires a map dtype") } diff --git a/vortex-array/src/arrays/masked/array.rs b/vortex-array/src/arrays/masked/array.rs index 001bcd6c839..a83d5ab5701 100644 --- a/vortex-array/src/arrays/masked/array.rs +++ b/vortex-array/src/arrays/masked/array.rs @@ -42,8 +42,8 @@ impl Display for MaskedData { pub trait MaskedArrayExt: TypedArrayRef + MaskedArraySlotsExt { fn masked_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[MaskedSlots::VALIDITY].as_ref(), - self.as_ref().dtype().nullability(), + self.slots()[MaskedSlots::VALIDITY].as_ref(), + self.dtype().nullability(), ) } } diff --git a/vortex-array/src/arrays/patched/array.rs b/vortex-array/src/arrays/patched/array.rs index 3d34ba15833..2c3ced3cd86 100644 --- a/vortex-array/src/arrays/patched/array.rs +++ b/vortex-array/src/arrays/patched/array.rs @@ -114,7 +114,7 @@ pub trait PatchedArrayExt: PatchedArraySlotsExt { #[inline] #[allow(clippy::disallowed_methods)] fn lane_range(&self, chunk: usize, lane: usize) -> VortexResult> { - assert!(chunk * 1024 <= self.as_ref().len() + self.offset()); + assert!(chunk * 1024 <= self.len() + self.offset()); assert!(lane < self.n_lanes()); let start = self.lane_offsets().execute_scalar( @@ -152,12 +152,12 @@ pub trait PatchedArrayExt: PatchedArraySlotsExt { let begin = (chunks.start * 1024).saturating_sub(self.offset()); let end = (chunks.end * 1024) .saturating_sub(self.offset()) - .min(self.as_ref().len()); + .min(self.len()); let offset = if chunks.start == 0 { self.offset() } else { 0 }; let inner = self.inner().slice(begin..end)?; let len = inner.len(); - let dtype = self.as_ref().dtype().clone(); + let dtype = self.dtype().clone(); let slots = PatchedSlots { inner, lane_offsets: sliced_lane_offsets, diff --git a/vortex-array/src/arrays/primitive/array/mod.rs b/vortex-array/src/arrays/primitive/array/mod.rs index 6945a47396b..1a4825df313 100644 --- a/vortex-array/src/arrays/primitive/array/mod.rs +++ b/vortex-array/src/arrays/primitive/array/mod.rs @@ -107,26 +107,26 @@ pub struct PrimitiveDataParts { pub trait PrimitiveArrayExt: TypedArrayRef { fn ptype(&self) -> PType { - match self.as_ref().dtype() { + match self.dtype() { DType::Primitive(ptype, _) => *ptype, _ => unreachable!("PrimitiveArrayExt requires a primitive dtype"), } } fn nullability(&self) -> Nullability { - match self.as_ref().dtype() { + match self.dtype() { DType::Primitive(_, nullability) => *nullability, _ => unreachable!("PrimitiveArrayExt requires a primitive dtype"), } } fn validity_child(&self) -> Option<&ArrayRef> { - self.as_ref().slots()[PrimitiveSlots::VALIDITY].as_ref() + self.slots()[PrimitiveSlots::VALIDITY].as_ref() } fn validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[PrimitiveSlots::VALIDITY].as_ref(), + self.slots()[PrimitiveSlots::VALIDITY].as_ref(), self.nullability(), ) } @@ -183,7 +183,7 @@ pub trait PrimitiveArrayExt: TypedArrayRef { return Ok(self.to_owned()); }; - let nullability = self.as_ref().dtype().nullability(); + let nullability = self.dtype().nullability(); if min < 0 || max < 0 { // Signed diff --git a/vortex-array/src/arrays/primitive/array/top_value.rs b/vortex-array/src/arrays/primitive/array/top_value.rs index a6233eb89ee..111fbdf8406 100644 --- a/vortex-array/src/arrays/primitive/array/top_value.rs +++ b/vortex-array/src/arrays/primitive/array/top_value.rs @@ -31,9 +31,7 @@ impl PrimitiveArray { match_each_native_ptype!(self.ptype(), |P| { let (top, count) = typed_top_value( self.as_slice::

(), - self.as_ref() - .validity()? - .execute_mask(self.as_ref().len(), ctx)?, + self.as_ref().validity()?.execute_mask(self.len(), ctx)?, ); Ok(Some((top.into(), count))) }) diff --git a/vortex-array/src/arrays/scalar_fn/array.rs b/vortex-array/src/arrays/scalar_fn/array.rs index 18e3dcbbd63..0a89c915f47 100644 --- a/vortex-array/src/arrays/scalar_fn/array.rs +++ b/vortex-array/src/arrays/scalar_fn/array.rs @@ -47,13 +47,13 @@ pub trait ScalarFnArrayExt: TypedArrayRef { } fn child_at(&self, idx: usize) -> &ArrayRef { - self.as_ref().slots()[idx] + self.slots()[idx] .as_ref() .vortex_expect("ScalarFnArray child slot") } fn child_count(&self) -> usize { - self.as_ref().slots().len() + self.slots().len() } fn nchildren(&self) -> usize { diff --git a/vortex-array/src/arrays/struct_/array.rs b/vortex-array/src/arrays/struct_/array.rs index fa9c4cb6386..f7792372e2c 100644 --- a/vortex-array/src/arrays/struct_/array.rs +++ b/vortex-array/src/arrays/struct_/array.rs @@ -203,14 +203,14 @@ pub(super) fn make_struct_slots( /// [`StructArraySlotsExt`] supertrait; this trait layers struct-specific lookups on top. pub trait StructArrayExt: StructArraySlotsExt { fn nullability(&self) -> crate::dtype::Nullability { - match self.as_ref().dtype() { + match self.dtype() { DType::Struct(_, nullability) => *nullability, _ => unreachable!("StructArrayExt requires a struct dtype"), } } fn names(&self) -> &FieldNames { - self.as_ref().dtype().as_struct_fields().names() + self.dtype().as_struct_fields().names() } fn struct_validity(&self) -> Validity { @@ -258,7 +258,7 @@ pub trait StructArrayExt: StructArraySlotsExt { } fn struct_fields(&self) -> &StructFields { - self.as_ref().dtype().as_struct_fields() + self.dtype().as_struct_fields() } } impl> StructArrayExt for T {} diff --git a/vortex-array/src/arrays/union/array.rs b/vortex-array/src/arrays/union/array.rs index 1eff6773f52..bd897f916e9 100644 --- a/vortex-array/src/arrays/union/array.rs +++ b/vortex-array/src/arrays/union/array.rs @@ -74,7 +74,7 @@ pub struct UnionDataParts { pub trait UnionArrayExt: UnionArraySlotsExt { /// The union's variant schema. fn variants(&self) -> &UnionVariants { - match self.as_ref().dtype() { + match self.dtype() { DType::Union(variants, _) => variants, _ => unreachable!("UnionArrayExt requires a union dtype"), } diff --git a/vortex-array/src/arrays/varbin/array.rs b/vortex-array/src/arrays/varbin/array.rs index 8f5a26211e4..8a66da79ff5 100644 --- a/vortex-array/src/arrays/varbin/array.rs +++ b/vortex-array/src/arrays/varbin/array.rs @@ -416,7 +416,7 @@ impl VarBinData { pub trait VarBinArrayExt: VarBinArraySlotsExt { fn dtype_parts(&self) -> (bool, Nullability) { - match self.as_ref().dtype() { + match self.dtype() { DType::Utf8(nullability) => (true, *nullability), DType::Binary(nullability) => (false, *nullability), _ => unreachable!("VarBinArrayExt requires a utf8 or binary dtype"), @@ -433,7 +433,7 @@ pub trait VarBinArrayExt: VarBinArraySlotsExt { fn varbin_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[VarBinSlots::VALIDITY].as_ref(), + self.slots()[VarBinSlots::VALIDITY].as_ref(), self.nullability(), ) } @@ -441,9 +441,9 @@ pub trait VarBinArrayExt: VarBinArraySlotsExt { #[allow(clippy::disallowed_methods)] fn offset_at(&self, index: usize) -> usize { assert!( - index <= self.as_ref().len(), + index <= self.len(), "Index {index} out of bounds 0..={}", - self.as_ref().len() + self.len() ); (&self @@ -462,7 +462,7 @@ pub trait VarBinArrayExt: VarBinArraySlotsExt { fn sliced_bytes(&self) -> ByteBuffer { let first_offset: usize = self.offset_at(0); - let last_offset = self.offset_at(self.as_ref().len()); + let last_offset = self.offset_at(self.len()); self.bytes().slice(first_offset..last_offset) } } diff --git a/vortex-array/src/arrays/varbinview/array.rs b/vortex-array/src/arrays/varbinview/array.rs index 91a564795c9..8327f91db2b 100644 --- a/vortex-array/src/arrays/varbinview/array.rs +++ b/vortex-array/src/arrays/varbinview/array.rs @@ -736,7 +736,7 @@ impl VarBinViewData { pub trait VarBinViewArrayExt: TypedArrayRef { fn dtype_parts(&self) -> (bool, Nullability) { - match self.as_ref().dtype() { + match self.dtype() { DType::Utf8(nullability) => (true, *nullability), DType::Binary(nullability) => (false, *nullability), _ => unreachable!("VarBinViewArrayExt requires a utf8 or binary dtype"), @@ -745,7 +745,7 @@ pub trait VarBinViewArrayExt: TypedArrayRef { fn varbinview_validity(&self) -> Validity { child_to_validity( - self.as_ref().slots()[VarBinViewSlots::VALIDITY].as_ref(), + self.slots()[VarBinViewSlots::VALIDITY].as_ref(), self.dtype_parts().1, ) } diff --git a/vortex-array/src/arrays/varbinview/compact.rs b/vortex-array/src/arrays/varbinview/compact.rs index 38549b9cf85..184e9e58301 100644 --- a/vortex-array/src/arrays/varbinview/compact.rs +++ b/vortex-array/src/arrays/varbinview/compact.rs @@ -71,11 +71,7 @@ impl VarBinViewArray { where F: FnMut(&Ref), { - match self - .as_ref() - .validity()? - .execute_mask(self.as_ref().len(), ctx)? - { + match self.as_ref().validity()?.execute_mask(self.len(), ctx)? { Mask::AllTrue(_) => { for &view in self.views().iter() { if !view.is_inlined() {