Skip to content

Commit 70eee88

Browse files
feat: iterative execution for DateTimePartsArray (#7698)
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 260badd commit 70eee88

50 files changed

Lines changed: 279 additions & 153 deletions

File tree

Some content is hidden

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

encodings/bytebool/src/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl VTable for ByteBool {
7373
len: usize,
7474
slots: &[Option<ArrayRef>],
7575
) -> VortexResult<()> {
76-
let validity = child_to_validity(&slots[VALIDITY_SLOT], dtype.nullability());
76+
let validity = child_to_validity(slots[VALIDITY_SLOT].as_ref(), dtype.nullability());
7777
ByteBoolData::validate(data.buffer(), &validity, dtype, len)
7878
}
7979

@@ -186,7 +186,7 @@ impl Display for ByteBoolData {
186186
pub trait ByteBoolArrayExt: TypedArrayRef<ByteBool> {
187187
fn validity(&self) -> Validity {
188188
child_to_validity(
189-
&self.as_ref().slots()[VALIDITY_SLOT],
189+
self.as_ref().slots()[VALIDITY_SLOT].as_ref(),
190190
self.as_ref().dtype().nullability(),
191191
)
192192
}

encodings/datetime-parts/public-api.lock

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,62 @@ pub fn vortex_datetime_parts::DateTimePartsMetadata::clear(&mut self)
152152

153153
pub fn vortex_datetime_parts::DateTimePartsMetadata::encoded_len(&self) -> usize
154154

155+
pub struct vortex_datetime_parts::DateTimePartsParts
156+
157+
pub vortex_datetime_parts::DateTimePartsParts::days: vortex_array::array::erased::ArrayRef
158+
159+
pub vortex_datetime_parts::DateTimePartsParts::seconds: vortex_array::array::erased::ArrayRef
160+
161+
pub vortex_datetime_parts::DateTimePartsParts::subseconds: vortex_array::array::erased::ArrayRef
162+
163+
pub struct vortex_datetime_parts::DateTimePartsSlots
164+
165+
pub vortex_datetime_parts::DateTimePartsSlots::days: vortex_array::array::erased::ArrayRef
166+
167+
pub vortex_datetime_parts::DateTimePartsSlots::seconds: vortex_array::array::erased::ArrayRef
168+
169+
pub vortex_datetime_parts::DateTimePartsSlots::subseconds: vortex_array::array::erased::ArrayRef
170+
171+
impl vortex_datetime_parts::DateTimePartsSlots
172+
173+
pub const vortex_datetime_parts::DateTimePartsSlots::COUNT: usize
174+
175+
pub const vortex_datetime_parts::DateTimePartsSlots::DAYS: usize
176+
177+
pub const vortex_datetime_parts::DateTimePartsSlots::NAMES: [&'static str; 3]
178+
179+
pub const vortex_datetime_parts::DateTimePartsSlots::SECONDS: usize
180+
181+
pub const vortex_datetime_parts::DateTimePartsSlots::SUBSECONDS: usize
182+
183+
pub fn vortex_datetime_parts::DateTimePartsSlots::from_slots(slots: alloc::vec::Vec<core::option::Option<vortex_array::array::erased::ArrayRef>>) -> Self
184+
185+
pub fn vortex_datetime_parts::DateTimePartsSlots::into_slots(self) -> alloc::vec::Vec<core::option::Option<vortex_array::array::erased::ArrayRef>>
186+
187+
pub struct vortex_datetime_parts::DateTimePartsSlotsView<'a>
188+
189+
pub vortex_datetime_parts::DateTimePartsSlotsView::days: &'a vortex_array::array::erased::ArrayRef
190+
191+
pub vortex_datetime_parts::DateTimePartsSlotsView::seconds: &'a vortex_array::array::erased::ArrayRef
192+
193+
pub vortex_datetime_parts::DateTimePartsSlotsView::subseconds: &'a vortex_array::array::erased::ArrayRef
194+
195+
impl<'a> vortex_datetime_parts::DateTimePartsSlotsView<'a>
196+
197+
pub fn vortex_datetime_parts::DateTimePartsSlotsView<'a>::from_slots(slots: &'a [core::option::Option<vortex_array::array::erased::ArrayRef>]) -> Self
198+
199+
pub fn vortex_datetime_parts::DateTimePartsSlotsView<'a>::to_owned(&self) -> vortex_datetime_parts::DateTimePartsSlots
200+
201+
impl<'a> core::clone::Clone for vortex_datetime_parts::DateTimePartsSlotsView<'a>
202+
203+
pub fn vortex_datetime_parts::DateTimePartsSlotsView<'a>::clone(&self) -> vortex_datetime_parts::DateTimePartsSlotsView<'a>
204+
205+
impl<'a> core::fmt::Debug for vortex_datetime_parts::DateTimePartsSlotsView<'a>
206+
207+
pub fn vortex_datetime_parts::DateTimePartsSlotsView<'a>::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
208+
209+
impl<'a> core::marker::Copy for vortex_datetime_parts::DateTimePartsSlotsView<'a>
210+
155211
pub struct vortex_datetime_parts::TemporalParts
156212

157213
pub vortex_datetime_parts::TemporalParts::days: vortex_array::array::erased::ArrayRef
@@ -160,22 +216,34 @@ pub vortex_datetime_parts::TemporalParts::seconds: vortex_array::array::erased::
160216

161217
pub vortex_datetime_parts::TemporalParts::subseconds: vortex_array::array::erased::ArrayRef
162218

163-
pub trait vortex_datetime_parts::DateTimePartsArrayExt: vortex_array::array::typed::TypedArrayRef<vortex_datetime_parts::DateTimeParts>
219+
pub trait vortex_datetime_parts::DateTimePartsArraySlotsExt: vortex_array::array::typed::TypedArrayRef<vortex_datetime_parts::DateTimeParts>
164220

165-
pub fn vortex_datetime_parts::DateTimePartsArrayExt::days(&self) -> &vortex_array::array::erased::ArrayRef
221+
pub fn vortex_datetime_parts::DateTimePartsArraySlotsExt::days(&self) -> &vortex_array::array::erased::ArrayRef
166222

167-
pub fn vortex_datetime_parts::DateTimePartsArrayExt::seconds(&self) -> &vortex_array::array::erased::ArrayRef
223+
pub fn vortex_datetime_parts::DateTimePartsArraySlotsExt::seconds(&self) -> &vortex_array::array::erased::ArrayRef
168224

169-
pub fn vortex_datetime_parts::DateTimePartsArrayExt::subseconds(&self) -> &vortex_array::array::erased::ArrayRef
225+
pub fn vortex_datetime_parts::DateTimePartsArraySlotsExt::slots_view(&self) -> vortex_datetime_parts::DateTimePartsSlotsView<'_>
170226

171-
impl<T: vortex_array::array::typed::TypedArrayRef<vortex_datetime_parts::DateTimeParts>> vortex_datetime_parts::DateTimePartsArrayExt for T
227+
pub fn vortex_datetime_parts::DateTimePartsArraySlotsExt::subseconds(&self) -> &vortex_array::array::erased::ArrayRef
228+
229+
impl<T: vortex_array::array::typed::TypedArrayRef<vortex_datetime_parts::DateTimeParts>> vortex_datetime_parts::DateTimePartsArraySlotsExt for T
172230

173231
pub fn T::days(&self) -> &vortex_array::array::erased::ArrayRef
174232

175233
pub fn T::seconds(&self) -> &vortex_array::array::erased::ArrayRef
176234

235+
pub fn T::slots_view(&self) -> vortex_datetime_parts::DateTimePartsSlotsView<'_>
236+
177237
pub fn T::subseconds(&self) -> &vortex_array::array::erased::ArrayRef
178238

239+
pub trait vortex_datetime_parts::DateTimePartsOwnedExt
240+
241+
pub fn vortex_datetime_parts::DateTimePartsOwnedExt::into_parts(self) -> vortex_datetime_parts::DateTimePartsParts
242+
243+
impl vortex_datetime_parts::DateTimePartsOwnedExt for vortex_array::array::typed::Array<vortex_datetime_parts::DateTimeParts>
244+
245+
pub fn vortex_array::array::typed::Array<vortex_datetime_parts::DateTimeParts>::into_parts(self) -> vortex_datetime_parts::DateTimePartsParts
246+
179247
pub fn vortex_datetime_parts::initialize(session: &vortex_session::VortexSession)
180248

181249
pub fn vortex_datetime_parts::split_temporal(array: vortex_array::arrays::datetime::TemporalArray, ctx: &mut vortex_array::executor::ExecutionCtx) -> vortex_error::VortexResult<vortex_datetime_parts::TemporalParts>

encodings/datetime-parts/src/array.rs

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::fmt::Formatter;
77
use std::hash::Hasher;
88

99
use prost::Message;
10+
use vortex_array::AnyCanonical;
1011
use vortex_array::Array;
1112
use vortex_array::ArrayEq;
1213
use vortex_array::ArrayHash;
@@ -18,17 +19,18 @@ use vortex_array::ExecutionCtx;
1819
use vortex_array::ExecutionResult;
1920
use vortex_array::IntoArray;
2021
use vortex_array::Precision;
21-
use vortex_array::TypedArrayRef;
22+
use vortex_array::array_slots;
23+
use vortex_array::arrays::Primitive;
2224
use vortex_array::arrays::TemporalArray;
2325
use vortex_array::buffer::BufferHandle;
2426
use vortex_array::dtype::DType;
2527
use vortex_array::dtype::Nullability;
2628
use vortex_array::dtype::PType;
29+
use vortex_array::require_child;
2730
use vortex_array::serde::ArrayChildren;
2831
use vortex_array::vtable::VTable;
2932
use vortex_array::vtable::ValidityChild;
3033
use vortex_array::vtable::ValidityVTableFromChild;
31-
use vortex_error::VortexExpect;
3234
use vortex_error::VortexResult;
3335
use vortex_error::vortex_bail;
3436
use vortex_error::vortex_ensure;
@@ -104,16 +106,8 @@ impl VTable for DateTimeParts {
104106
len: usize,
105107
slots: &[Option<ArrayRef>],
106108
) -> VortexResult<()> {
107-
let days = slots[DAYS_SLOT]
108-
.as_ref()
109-
.vortex_expect("DateTimePartsArray days slot");
110-
let seconds = slots[SECONDS_SLOT]
111-
.as_ref()
112-
.vortex_expect("DateTimePartsArray seconds slot");
113-
let subseconds = slots[SUBSECONDS_SLOT]
114-
.as_ref()
115-
.vortex_expect("DateTimePartsArray subseconds slot");
116-
DateTimePartsData::validate(dtype, days, seconds, subseconds, len)
109+
let slots = DateTimePartsSlotsView::from_slots(slots);
110+
DateTimePartsData::validate(dtype, slots.days, slots.seconds, slots.subseconds, len)
117111
}
118112

119113
fn nbuffers(_array: ArrayView<'_, Self>) -> usize {
@@ -181,12 +175,20 @@ impl VTable for DateTimeParts {
181175
}
182176

183177
fn slot_name(_array: ArrayView<'_, Self>, idx: usize) -> String {
184-
SLOT_NAMES[idx].to_string()
178+
DateTimePartsSlots::NAMES[idx].to_string()
185179
}
186180

187181
fn execute(array: Array<Self>, ctx: &mut ExecutionCtx) -> VortexResult<ExecutionResult> {
182+
let array = require_child!(array, array.days(), DateTimePartsSlots::DAYS => Primitive);
183+
let array =
184+
require_child!(array, array.seconds(), DateTimePartsSlots::SECONDS => AnyCanonical);
185+
let array = require_child!(array, array.subseconds(), DateTimePartsSlots::SUBSECONDS => AnyCanonical);
186+
187+
let dtype = array.dtype().clone();
188+
let parts = array.into_parts();
189+
188190
Ok(ExecutionResult::done(
189-
decode_to_temporal(&array, ctx)?.into_array(),
191+
decode_to_temporal(parts, &dtype, ctx)?.into_array(),
190192
))
191193
}
192194

@@ -208,46 +210,58 @@ impl VTable for DateTimeParts {
208210
}
209211
}
210212

211-
/// The days component of the datetime, stored as an integer array.
212-
pub(super) const DAYS_SLOT: usize = 0;
213-
/// The seconds component of the datetime (within the day).
214-
pub(super) const SECONDS_SLOT: usize = 1;
215-
/// The sub-second component of the datetime.
216-
pub(super) const SUBSECONDS_SLOT: usize = 2;
217-
pub(super) const NUM_SLOTS: usize = 3;
218-
pub(super) const SLOT_NAMES: [&str; NUM_SLOTS] = ["days", "seconds", "subseconds"];
213+
#[array_slots(DateTimeParts)]
214+
pub struct DateTimePartsSlots {
215+
/// The days component of the datetime, stored as an integer array.
216+
pub days: ArrayRef,
217+
/// The seconds component of the datetime (within the day).
218+
pub seconds: ArrayRef,
219+
/// The sub-second component of the datetime.
220+
pub subseconds: ArrayRef,
221+
}
219222

220223
#[derive(Clone, Debug)]
221224
pub struct DateTimePartsData {}
222225

223-
impl Display for DateTimePartsData {
224-
fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
225-
Ok(())
226-
}
226+
pub struct DateTimePartsParts {
227+
pub days: ArrayRef,
228+
pub seconds: ArrayRef,
229+
pub subseconds: ArrayRef,
227230
}
228231

229-
pub trait DateTimePartsArrayExt: TypedArrayRef<DateTimeParts> {
230-
fn days(&self) -> &ArrayRef {
231-
self.as_ref().slots()[DAYS_SLOT]
232-
.as_ref()
233-
.vortex_expect("DateTimePartsArray days slot")
234-
}
232+
pub trait DateTimePartsOwnedExt {
233+
fn into_parts(self) -> DateTimePartsParts;
234+
}
235235

236-
fn seconds(&self) -> &ArrayRef {
237-
self.as_ref().slots()[SECONDS_SLOT]
238-
.as_ref()
239-
.vortex_expect("DateTimePartsArray seconds slot")
236+
impl DateTimePartsOwnedExt for Array<DateTimeParts> {
237+
fn into_parts(self) -> DateTimePartsParts {
238+
match self.try_into_parts() {
239+
Ok(parts) => {
240+
let slots = DateTimePartsSlots::from_slots(parts.slots);
241+
DateTimePartsParts {
242+
days: slots.days,
243+
seconds: slots.seconds,
244+
subseconds: slots.subseconds,
245+
}
246+
}
247+
Err(array) => {
248+
let view = DateTimePartsSlotsView::from_slots(array.as_ref().slots());
249+
DateTimePartsParts {
250+
days: view.days.clone(),
251+
seconds: view.seconds.clone(),
252+
subseconds: view.subseconds.clone(),
253+
}
254+
}
255+
}
240256
}
257+
}
241258

242-
fn subseconds(&self) -> &ArrayRef {
243-
self.as_ref().slots()[SUBSECONDS_SLOT]
244-
.as_ref()
245-
.vortex_expect("DateTimePartsArray subseconds slot")
259+
impl Display for DateTimePartsData {
260+
fn fmt(&self, _f: &mut Formatter<'_>) -> std::fmt::Result {
261+
Ok(())
246262
}
247263
}
248264

249-
impl<T: TypedArrayRef<DateTimeParts>> DateTimePartsArrayExt for T {}
250-
251265
#[derive(Clone, Debug)]
252266
pub struct DateTimeParts;
253267

0 commit comments

Comments
 (0)