Skip to content

Commit 8974afe

Browse files
feat: add an arrays slots macro (#7360)
Adds a array_slot(VTable) attr macro which can be applied to a slots struct. This gives types access to the slots for an array. e.g. ```rust #[array_slots(ALP)] pub struct ALPSlots { /// The ALP-encoded values array. pub encoded: ArrayRef, /// The indices of exception values that could not be ALP-encoded. pub patch_indices: Option<ArrayRef>, /// The exception values that could not be ALP-encoded. pub patch_values: Option<ArrayRef>, /// Chunk offsets for the patch indices/values. pub patch_chunk_offsets: Option<ArrayRef>, } ``` --------- Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent c660607 commit 8974afe

File tree

63 files changed

+1034
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1034
-356
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
|| 'ubuntu-latest' }}
8282
timeout-minutes: 40
8383
env:
84-
RUST_LOG: "info,uv=debug"
84+
RUST_LOG: "info,maturin=warn,uv=debug"
8585
MATURIN_PEP517_ARGS: "--profile ci"
8686
steps:
8787
- uses: runs-on/action@v2

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = [
33
# Core crates in dependency order
4+
"vortex-array-macros",
45
"vortex-error",
56
"vortex-buffer",
67
"vortex-mask",
@@ -241,6 +242,7 @@ thiserror = "2.0.3"
241242
tokio = { version = "1.48" }
242243
tokio-stream = "0.1.17"
243244
tokio-util = "0.7.17"
245+
vortex-array-macros = { version = "0.1.0", path = "./vortex-array-macros" }
244246
# Pull these into non-public crates to support DF 58
245247
tpchgen = { version = "2.0.2", git = "https://github.com/clflushopt/tpchgen-rs.git", rev = "438e9c2dbc25b2fff82c0efc08b3f13b5707874f" }
246248
tpchgen-arrow = { version = "2.0.2", git = "https://github.com/clflushopt/tpchgen-rs.git", rev = "438e9c2dbc25b2fff82c0efc08b3f13b5707874f" }

encodings/alp/public-api.lock

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,60 @@ pub fn vortex_alp::ALPRDMetadata::clear(&mut self)
296296

297297
pub fn vortex_alp::ALPRDMetadata::encoded_len(&self) -> usize
298298

299+
pub struct vortex_alp::ALPSlots
300+
301+
pub vortex_alp::ALPSlots::encoded: vortex_array::array::erased::ArrayRef
302+
303+
pub vortex_alp::ALPSlots::patch_chunk_offsets: core::option::Option<vortex_array::array::erased::ArrayRef>
304+
305+
pub vortex_alp::ALPSlots::patch_indices: core::option::Option<vortex_array::array::erased::ArrayRef>
306+
307+
pub vortex_alp::ALPSlots::patch_values: core::option::Option<vortex_array::array::erased::ArrayRef>
308+
309+
impl vortex_alp::ALPSlots
310+
311+
pub const vortex_alp::ALPSlots::COUNT: usize
312+
313+
pub const vortex_alp::ALPSlots::ENCODED: usize
314+
315+
pub const vortex_alp::ALPSlots::NAMES: [&'static str; 4]
316+
317+
pub const vortex_alp::ALPSlots::PATCH_CHUNK_OFFSETS: usize
318+
319+
pub const vortex_alp::ALPSlots::PATCH_INDICES: usize
320+
321+
pub const vortex_alp::ALPSlots::PATCH_VALUES: usize
322+
323+
pub fn vortex_alp::ALPSlots::from_slots(slots: alloc::vec::Vec<core::option::Option<vortex_array::array::erased::ArrayRef>>) -> Self
324+
325+
pub fn vortex_alp::ALPSlots::into_slots(self) -> alloc::vec::Vec<core::option::Option<vortex_array::array::erased::ArrayRef>>
326+
327+
pub struct vortex_alp::ALPSlotsView<'a>
328+
329+
pub vortex_alp::ALPSlotsView::encoded: &'a vortex_array::array::erased::ArrayRef
330+
331+
pub vortex_alp::ALPSlotsView::patch_chunk_offsets: core::option::Option<&'a vortex_array::array::erased::ArrayRef>
332+
333+
pub vortex_alp::ALPSlotsView::patch_indices: core::option::Option<&'a vortex_array::array::erased::ArrayRef>
334+
335+
pub vortex_alp::ALPSlotsView::patch_values: core::option::Option<&'a vortex_array::array::erased::ArrayRef>
336+
337+
impl<'a> vortex_alp::ALPSlotsView<'a>
338+
339+
pub fn vortex_alp::ALPSlotsView<'a>::from_slots(slots: &'a [core::option::Option<vortex_array::array::erased::ArrayRef>]) -> Self
340+
341+
pub fn vortex_alp::ALPSlotsView<'a>::to_owned(&self) -> vortex_alp::ALPSlots
342+
343+
impl<'a> core::clone::Clone for vortex_alp::ALPSlotsView<'a>
344+
345+
pub fn vortex_alp::ALPSlotsView<'a>::clone(&self) -> vortex_alp::ALPSlotsView<'a>
346+
347+
impl<'a> core::fmt::Debug for vortex_alp::ALPSlotsView<'a>
348+
349+
pub fn vortex_alp::ALPSlotsView<'a>::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
350+
351+
impl<'a> core::marker::Copy for vortex_alp::ALPSlotsView<'a>
352+
299353
pub struct vortex_alp::Exponents
300354

301355
pub vortex_alp::Exponents::e: u8
@@ -338,18 +392,14 @@ pub fn vortex_alp::RDEncoder::from_parts(right_bit_width: u8, codes: alloc::vec:
338392

339393
pub fn vortex_alp::RDEncoder::new<T>(sample: &[T]) -> Self where T: vortex_alp::ALPRDFloat + vortex_array::dtype::ptype::NativePType, <T as vortex_alp::ALPRDFloat>::UINT: vortex_array::dtype::ptype::NativePType
340394

341-
pub trait vortex_alp::ALPArrayExt: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>
342-
343-
pub fn vortex_alp::ALPArrayExt::encoded(&self) -> &vortex_array::array::erased::ArrayRef
395+
pub trait vortex_alp::ALPArrayExt: vortex_alp::ALPArraySlotsExt
344396

345397
pub fn vortex_alp::ALPArrayExt::exponents(&self) -> vortex_alp::Exponents
346398

347399
pub fn vortex_alp::ALPArrayExt::patches(&self) -> core::option::Option<vortex_array::patches::Patches>
348400

349401
impl<T: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>> vortex_alp::ALPArrayExt for T
350402

351-
pub fn T::encoded(&self) -> &vortex_array::array::erased::ArrayRef
352-
353403
pub fn T::exponents(&self) -> vortex_alp::Exponents
354404

355405
pub fn T::patches(&self) -> core::option::Option<vortex_array::patches::Patches>
@@ -362,6 +412,30 @@ impl vortex_alp::ALPArrayOwnedExt for vortex_array::array::typed::Array<vortex_a
362412

363413
pub fn vortex_array::array::typed::Array<vortex_alp::ALP>::into_parts(self) -> (vortex_array::array::erased::ArrayRef, vortex_alp::Exponents, core::option::Option<vortex_array::patches::Patches>)
364414

415+
pub trait vortex_alp::ALPArraySlotsExt: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>
416+
417+
pub fn vortex_alp::ALPArraySlotsExt::encoded(&self) -> &vortex_array::array::erased::ArrayRef
418+
419+
pub fn vortex_alp::ALPArraySlotsExt::patch_chunk_offsets(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
420+
421+
pub fn vortex_alp::ALPArraySlotsExt::patch_indices(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
422+
423+
pub fn vortex_alp::ALPArraySlotsExt::patch_values(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
424+
425+
pub fn vortex_alp::ALPArraySlotsExt::slots_view(&self) -> vortex_alp::ALPSlotsView<'_>
426+
427+
impl<T: vortex_array::array::typed::TypedArrayRef<vortex_alp::ALP>> vortex_alp::ALPArraySlotsExt for T
428+
429+
pub fn T::encoded(&self) -> &vortex_array::array::erased::ArrayRef
430+
431+
pub fn T::patch_chunk_offsets(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
432+
433+
pub fn T::patch_indices(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
434+
435+
pub fn T::patch_values(&self) -> core::option::Option<&vortex_array::array::erased::ArrayRef>
436+
437+
pub fn T::slots_view(&self) -> vortex_alp::ALPSlotsView<'_>
438+
365439
pub trait vortex_alp::ALPFloat: vortex_alp::alp::private::Sealed + num_traits::float::Float + core::fmt::Display + vortex_array::dtype::ptype::NativePType
366440

367441
pub type vortex_alp::ALPFloat::ALPInt: num_traits::int::PrimInt + core::fmt::Display + num_traits::cast::ToPrimitive + core::marker::Copy + vortex_array::dtype::ptype::NativePType + core::convert::Into<vortex_array::scalar::typed_view::primitive::pvalue::PValue>

encodings/alp/src/alp/array.rs

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_array::ExecutionResult;
2020
use vortex_array::IntoArray;
2121
use vortex_array::Precision;
2222
use vortex_array::TypedArrayRef;
23+
use vortex_array::array_slots;
2324
use vortex_array::arrays::Primitive;
2425
use vortex_array::buffer::BufferHandle;
2526
use vortex_array::dtype::DType;
@@ -81,15 +82,14 @@ impl VTable for ALP {
8182
len: usize,
8283
slots: &[Option<ArrayRef>],
8384
) -> VortexResult<()> {
85+
let slots = ALPSlotsView::from_slots(slots);
8486
validate_parts(
8587
dtype,
8688
len,
8789
data.exponents,
88-
slots[ENCODED_SLOT]
89-
.as_ref()
90-
.vortex_expect("ALPArray encoded slot"),
90+
slots.encoded,
9191
patches_from_slots(
92-
slots,
92+
&slots,
9393
data.patch_offset,
9494
data.patch_offset_within_chunk,
9595
len,
@@ -170,16 +170,16 @@ impl VTable for ALP {
170170
}
171171

172172
fn slot_name(_array: ArrayView<'_, Self>, idx: usize) -> String {
173-
SLOT_NAMES[idx].to_string()
173+
ALPSlots::NAMES[idx].to_string()
174174
}
175175

176176
fn execute(array: Array<Self>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
177-
let array = require_child!(array, array.encoded(), ENCODED_SLOT => Primitive);
177+
let array = require_child!(array, array.encoded(), ALPSlots::ENCODED => Primitive);
178178
require_patches!(
179179
array,
180-
PATCH_INDICES_SLOT,
181-
PATCH_VALUES_SLOT,
182-
PATCH_CHUNK_OFFSETS_SLOT
180+
ALPSlots::PATCH_INDICES,
181+
ALPSlots::PATCH_VALUES,
182+
ALPSlots::PATCH_CHUNK_OFFSETS
183183
);
184184

185185
Ok(ExecutionResult::done(
@@ -205,21 +205,17 @@ impl VTable for ALP {
205205
}
206206
}
207207

208-
/// The ALP-encoded values array.
209-
pub(super) const ENCODED_SLOT: usize = 0;
210-
/// The indices of exception values that could not be ALP-encoded.
211-
pub(super) const PATCH_INDICES_SLOT: usize = 1;
212-
/// The exception values that could not be ALP-encoded.
213-
pub(super) const PATCH_VALUES_SLOT: usize = 2;
214-
/// Chunk offsets for the patch indices/values.
215-
pub(super) const PATCH_CHUNK_OFFSETS_SLOT: usize = 3;
216-
pub(super) const NUM_SLOTS: usize = 4;
217-
pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = [
218-
"encoded",
219-
"patch_indices",
220-
"patch_values",
221-
"patch_chunk_offsets",
222-
];
208+
#[array_slots(ALP)]
209+
pub struct ALPSlots {
210+
/// The ALP-encoded values array.
211+
pub encoded: ArrayRef,
212+
/// The indices of exception values that could not be ALP-encoded.
213+
pub patch_indices: Option<ArrayRef>,
214+
/// The exception values that could not be ALP-encoded.
215+
pub patch_values: Option<ArrayRef>,
216+
/// Chunk offsets for the patch indices/values.
217+
pub patch_chunk_offsets: Option<ArrayRef>,
218+
}
223219

224220
#[derive(Clone, Debug)]
225221
pub struct ALPData {
@@ -439,20 +435,14 @@ impl ALPData {
439435
}
440436
}
441437

442-
pub trait ALPArrayExt: TypedArrayRef<ALP> {
443-
fn encoded(&self) -> &ArrayRef {
444-
self.as_ref().slots()[ENCODED_SLOT]
445-
.as_ref()
446-
.vortex_expect("ALPArray encoded slot")
447-
}
448-
438+
pub trait ALPArrayExt: ALPArraySlotsExt {
449439
fn exponents(&self) -> Exponents {
450440
self.exponents
451441
}
452442

453443
fn patches(&self) -> Option<Patches> {
454444
patches_from_slots(
455-
self.as_ref().slots(),
445+
&self.slots_view(),
456446
self.patch_offset,
457447
self.patch_offset_within_chunk,
458448
self.as_ref().len(),
@@ -461,12 +451,12 @@ pub trait ALPArrayExt: TypedArrayRef<ALP> {
461451
}
462452

463453
fn patches_from_slots(
464-
slots: &[Option<ArrayRef>],
454+
slots: &ALPSlotsView,
465455
patch_offset: Option<usize>,
466456
patch_offset_within_chunk: Option<usize>,
467457
len: usize,
468458
) -> Option<Patches> {
469-
match (&slots[PATCH_INDICES_SLOT], &slots[PATCH_VALUES_SLOT]) {
459+
match (slots.patch_indices, slots.patch_values) {
470460
(Some(indices), Some(values)) => {
471461
let patch_offset = patch_offset.vortex_expect("has patch slots but no patch_offset");
472462
Some(unsafe {
@@ -475,7 +465,7 @@ fn patches_from_slots(
475465
patch_offset,
476466
indices.clone(),
477467
values.clone(),
478-
slots[PATCH_CHUNK_OFFSETS_SLOT].clone(),
468+
slots.patch_chunk_offsets.cloned(),
479469
patch_offset_within_chunk,
480470
)
481471
})

encodings/alp/src/alp/compress.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ mod tests {
135135

136136
use super::*;
137137
use crate::alp::array::ALPArrayExt;
138+
use crate::alp::array::ALPArraySlotsExt;
138139
use crate::decompress_into_array;
139140

140141
#[test]

encodings/alp/src/alp/compute/between.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_error::VortexResult;
2020
use crate::ALP;
2121
use crate::ALPFloat;
2222
use crate::alp::array::ALPArrayExt;
23+
use crate::alp::array::ALPArraySlotsExt;
2324
use crate::match_each_alp_float_ptype;
2425

2526
impl BetweenReduce for ALP {

encodings/alp/src/alp/compute/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vortex_array::scalar_fn::fns::cast::CastReduce;
1111
use vortex_error::VortexResult;
1212

1313
use crate::ALPArrayExt;
14+
use crate::ALPArraySlotsExt;
1415
use crate::alp::ALP;
1516

1617
impl CastReduce for ALP {

encodings/alp/src/alp/compute/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use vortex_error::vortex_err;
2020

2121
use crate::ALP;
2222
use crate::ALPArrayExt;
23+
use crate::ALPArraySlotsExt;
2324
use crate::ALPFloat;
2425
use crate::match_each_alp_float_ptype;
2526

encodings/alp/src/alp/compute/filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use vortex_mask::Mask;
1111

1212
use crate::ALP;
1313
use crate::ALPArrayExt;
14+
use crate::ALPArraySlotsExt;
1415

1516
impl FilterKernel for ALP {
1617
fn filter(

0 commit comments

Comments
 (0)