• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16524157085

25 Jul 2025 02:15PM UTC coverage: 81.694% (-0.06%) from 81.758%
16524157085

Pull #3356

github

web-flow
Merge f8337491a into 45200f15d
Pull Request #3356: Clean up stats propagation for slicing

79 of 106 new or added lines in 12 files covered. (74.53%)

26 existing lines in 12 files now uncovered.

43118 of 52780 relevant lines covered (81.69%)

170587.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.43
/vortex-array/src/array/mod.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
pub mod display;
5
mod visitor;
6

7
use std::any::Any;
8
use std::fmt::{Debug, Formatter};
9
use std::sync::Arc;
10

11
pub use visitor::*;
12
use vortex_buffer::ByteBuffer;
13
use vortex_dtype::DType;
14
use vortex_error::{VortexExpect, VortexResult, vortex_bail, vortex_err};
15
use vortex_mask::Mask;
16
use vortex_scalar::Scalar;
17

18
use crate::arrays::{
19
    BoolEncoding, ConstantVTable, DecimalEncoding, ExtensionEncoding, ListEncoding, NullEncoding,
20
    PrimitiveEncoding, StructEncoding, VarBinEncoding, VarBinViewEncoding,
21
};
22
use crate::builders::ArrayBuilder;
23
use crate::compute::{ComputeFn, Cost, InvocationArgs, IsConstantOpts, Output, is_constant_opts};
24
use crate::serde::ArrayChildren;
25
use crate::stats::{Precision, Stat, StatsSetRef};
26
use crate::vtable::{
27
    ArrayVTable, CanonicalVTable, ComputeVTable, OperationsVTable, SerdeVTable, VTable,
28
    ValidityVTable, VisitorVTable,
29
};
30
use crate::{Canonical, EncodingId, EncodingRef, SerializeMetadata};
31

32
/// The public API trait for all Vortex arrays.
33
pub trait Array: 'static + private::Sealed + Send + Sync + Debug + ArrayVisitor {
34
    /// Returns the array as a reference to a generic [`Any`] trait object.
35
    fn as_any(&self) -> &dyn Any;
36

37
    /// Returns the array as an [`ArrayRef`].
38
    fn to_array(&self) -> ArrayRef;
39

40
    /// Returns the length of the array.
41
    fn len(&self) -> usize;
42

43
    /// Returns whether the array is empty (has zero rows).
44
    fn is_empty(&self) -> bool {
236,786✔
45
        self.len() == 0
236,786✔
46
    }
236,786✔
47

48
    /// Returns the logical Vortex [`DType`] of the array.
49
    fn dtype(&self) -> &DType;
50

51
    /// Returns the encoding of the array.
52
    fn encoding(&self) -> EncodingRef;
53

54
    /// Returns the encoding ID of the array.
55
    fn encoding_id(&self) -> EncodingId;
56

57
    /// Performs a constant-time slice of the array.
58
    fn slice(&self, start: usize, end: usize) -> VortexResult<ArrayRef>;
59

60
    /// Fetch the scalar at the given index.
61
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar>;
62

63
    /// Returns whether the array is of the given encoding.
64
    fn is_encoding(&self, encoding: EncodingId) -> bool {
450,267✔
65
        self.encoding_id() == encoding
450,267✔
66
    }
450,267✔
67

68
    /// Returns whether this array is an arrow encoding.
69
    // TODO(ngates): this shouldn't live here.
70
    fn is_arrow(&self) -> bool {
15,301✔
71
        self.is_encoding(NullEncoding.id())
15,301✔
72
            || self.is_encoding(BoolEncoding.id())
15,301✔
73
            || self.is_encoding(PrimitiveEncoding.id())
11,622✔
74
            || self.is_encoding(VarBinEncoding.id())
9,325✔
75
            || self.is_encoding(VarBinViewEncoding.id())
9,325✔
76
    }
15,301✔
77

78
    /// Whether the array is of a canonical encoding.
79
    // TODO(ngates): this shouldn't live here.
80
    fn is_canonical(&self) -> bool {
64,303✔
81
        self.is_encoding(NullEncoding.id())
64,303✔
82
            || self.is_encoding(BoolEncoding.id())
64,303✔
83
            || self.is_encoding(PrimitiveEncoding.id())
60,235✔
84
            || self.is_encoding(DecimalEncoding.id())
40,931✔
85
            || self.is_encoding(StructEncoding.id())
39,618✔
86
            || self.is_encoding(ListEncoding.id())
38,341✔
87
            || self.is_encoding(VarBinViewEncoding.id())
38,339✔
88
            || self.is_encoding(ExtensionEncoding.id())
36,508✔
89
    }
64,303✔
90

91
    /// Returns whether the item at `index` is valid.
92
    fn is_valid(&self, index: usize) -> VortexResult<bool>;
93

94
    /// Returns whether the item at `index` is invalid.
95
    fn is_invalid(&self, index: usize) -> VortexResult<bool>;
96

97
    /// Returns whether all items in the array are valid.
98
    ///
99
    /// This is usually cheaper than computing a precise `valid_count`.
100
    fn all_valid(&self) -> VortexResult<bool>;
101

102
    /// Returns whether the array is all invalid.
103
    ///
104
    /// This is usually cheaper than computing a precise `invalid_count`.
105
    fn all_invalid(&self) -> VortexResult<bool>;
106

107
    /// Returns the number of valid elements in the array.
108
    fn valid_count(&self) -> VortexResult<usize>;
109

110
    /// Returns the number of invalid elements in the array.
111
    fn invalid_count(&self) -> VortexResult<usize>;
112

113
    /// Returns the canonical validity mask for the array.
114
    fn validity_mask(&self) -> VortexResult<Mask>;
115

116
    /// Returns the canonical representation of the array.
117
    fn to_canonical(&self) -> VortexResult<Canonical>;
118

119
    /// Writes the array into the canonical builder.
120
    ///
121
    /// The [`DType`] of the builder must match that of the array.
122
    fn append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()>;
123

124
    /// Returns the statistics of the array.
125
    // TODO(ngates): change how this works. It's weird.
126
    fn statistics(&self) -> StatsSetRef<'_>;
127

128
    /// Replaces the children of the array with the given array references.
129
    fn with_children(&self, children: &[ArrayRef]) -> VortexResult<ArrayRef>;
130

131
    /// Optionally invoke a kernel for the given compute function.
132
    ///
133
    /// These encoding-specific kernels are independent of kernels registered directly with
134
    /// compute functions using [`ComputeFn::register_kernel`], and are attempted only if none of
135
    /// the function-specific kernels returns a result.
136
    ///
137
    /// This allows encodings the opportunity to generically implement many compute functions
138
    /// that share some property, for example [`ComputeFn::is_elementwise`], without prior
139
    /// knowledge of the function itself, while still allowing users to override the implementation
140
    /// of compute functions for built-in encodings. For an example, see the implementation for
141
    /// chunked arrays.
142
    ///
143
    /// The first input in the [`InvocationArgs`] is always the array itself.
144
    ///
145
    /// Warning: do not call `compute_fn.invoke(args)` directly, as this will result in a recursive
146
    /// call.
147
    fn invoke(&self, compute_fn: &ComputeFn, args: &InvocationArgs)
148
    -> VortexResult<Option<Output>>;
149
}
150

151
impl Array for Arc<dyn Array> {
152
    fn as_any(&self) -> &dyn Any {
551,218✔
153
        self.as_ref().as_any()
551,218✔
154
    }
551,218✔
155

156
    fn to_array(&self) -> ArrayRef {
137,378✔
157
        self.clone()
137,378✔
158
    }
137,378✔
159

160
    fn len(&self) -> usize {
1,180,145✔
161
        self.as_ref().len()
1,180,145✔
162
    }
1,180,145✔
163

164
    fn dtype(&self) -> &DType {
950,569✔
165
        self.as_ref().dtype()
950,569✔
166
    }
950,569✔
167

168
    fn encoding(&self) -> EncodingRef {
18,636✔
169
        self.as_ref().encoding()
18,636✔
170
    }
18,636✔
171

172
    fn encoding_id(&self) -> EncodingId {
399,842✔
173
        self.as_ref().encoding_id()
399,842✔
174
    }
399,842✔
175

176
    fn slice(&self, start: usize, end: usize) -> VortexResult<ArrayRef> {
36,700✔
177
        self.as_ref().slice(start, end)
36,700✔
178
    }
36,700✔
179

180
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar> {
531,743✔
181
        self.as_ref().scalar_at(index)
531,743✔
182
    }
531,743✔
183

184
    fn is_valid(&self, index: usize) -> VortexResult<bool> {
31,957✔
185
        self.as_ref().is_valid(index)
31,957✔
186
    }
31,957✔
187

188
    fn is_invalid(&self, index: usize) -> VortexResult<bool> {
366✔
189
        self.as_ref().is_invalid(index)
366✔
190
    }
366✔
191

192
    fn all_valid(&self) -> VortexResult<bool> {
21,895✔
193
        self.as_ref().all_valid()
21,895✔
194
    }
21,895✔
195

196
    fn all_invalid(&self) -> VortexResult<bool> {
40,283✔
197
        self.as_ref().all_invalid()
40,283✔
198
    }
40,283✔
199

200
    fn valid_count(&self) -> VortexResult<usize> {
2,757✔
201
        self.as_ref().valid_count()
2,757✔
202
    }
2,757✔
203

204
    fn invalid_count(&self) -> VortexResult<usize> {
1,491✔
205
        self.as_ref().invalid_count()
1,491✔
206
    }
1,491✔
207

208
    fn validity_mask(&self) -> VortexResult<Mask> {
6,388✔
209
        self.as_ref().validity_mask()
6,388✔
210
    }
6,388✔
211

212
    fn to_canonical(&self) -> VortexResult<Canonical> {
241,239✔
213
        self.as_ref().to_canonical()
241,239✔
214
    }
241,239✔
215

216
    fn append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
41,472✔
217
        self.as_ref().append_to_builder(builder)
41,472✔
218
    }
41,472✔
219

220
    fn statistics(&self) -> StatsSetRef<'_> {
348,706✔
221
        self.as_ref().statistics()
348,706✔
222
    }
348,706✔
223

224
    fn with_children(&self, children: &[ArrayRef]) -> VortexResult<ArrayRef> {
×
225
        self.as_ref().with_children(children)
×
226
    }
×
227

228
    fn invoke(
40,263✔
229
        &self,
40,263✔
230
        compute_fn: &ComputeFn,
40,263✔
231
        args: &InvocationArgs,
40,263✔
232
    ) -> VortexResult<Option<Output>> {
40,263✔
233
        self.as_ref().invoke(compute_fn, args)
40,263✔
234
    }
40,263✔
235
}
236

237
/// A reference counted pointer to a dynamic [`Array`] trait object.
238
pub type ArrayRef = Arc<dyn Array>;
239

240
impl ToOwned for dyn Array {
241
    type Owned = ArrayRef;
242

243
    fn to_owned(&self) -> Self::Owned {
×
244
        self.to_array()
×
245
    }
×
246
}
247

248
impl dyn Array + '_ {
249
    /// Returns the array downcast to the given `A`.
250
    pub fn as_<V: VTable>(&self) -> &V::Array {
215✔
251
        self.as_opt::<V>().vortex_expect("Failed to downcast")
215✔
252
    }
215✔
253

254
    /// Returns the array downcast to the given `A`.
255
    pub fn as_opt<V: VTable>(&self) -> Option<&V::Array> {
1,274,293✔
256
        self.as_any()
1,274,293✔
257
            .downcast_ref::<ArrayAdapter<V>>()
1,274,293✔
258
            .map(|array_adapter| &array_adapter.0)
1,274,293✔
259
    }
1,274,293✔
260

261
    /// Is self an array with encoding from vtable `V`.
262
    pub fn is<V: VTable>(&self) -> bool {
177,010✔
263
        self.as_opt::<V>().is_some()
177,010✔
264
    }
177,010✔
265

266
    pub fn is_constant(&self) -> bool {
179,502✔
267
        let opts = IsConstantOpts {
179,502✔
268
            cost: Cost::Specialized,
179,502✔
269
        };
179,502✔
270
        is_constant_opts(self, &opts)
179,502✔
271
            .inspect_err(|e| log::warn!("Failed to compute IsConstant: {e}"))
179,502✔
272
            .ok()
179,502✔
273
            .flatten()
179,502✔
274
            .unwrap_or_default()
179,502✔
275
    }
179,502✔
276

NEW
277
    pub fn is_constant_opts(&self, cost: Cost) -> bool {
×
NEW
278
        let opts = IsConstantOpts { cost };
×
NEW
279
        is_constant_opts(self, &opts)
×
NEW
280
            .inspect_err(|e| log::warn!("Failed to compute IsConstant: {e}"))
×
NEW
281
            .ok()
×
NEW
282
            .flatten()
×
NEW
283
            .unwrap_or_default()
×
NEW
284
    }
×
285

286
    pub fn as_constant(&self) -> Option<Scalar> {
108,245✔
287
        self.is_constant().then(|| self.scalar_at(0).ok()).flatten()
108,245✔
288
    }
108,245✔
289

290
    /// Total size of the array in bytes, including all children and buffers.
291
    pub fn nbytes(&self) -> u64 {
156,653✔
292
        let mut nbytes = 0;
156,653✔
293
        for array in self.depth_first_traversal() {
220,192✔
294
            for buffer in array.buffers() {
251,947✔
295
                nbytes += buffer.len() as u64;
251,947✔
296
            }
251,947✔
297
        }
298
        nbytes
156,653✔
299
    }
156,653✔
300
}
301

302
/// Trait for converting a type into a Vortex [`ArrayRef`].
303
pub trait IntoArray {
304
    fn into_array(self) -> ArrayRef;
305
}
306

307
impl IntoArray for ArrayRef {
308
    fn into_array(self) -> ArrayRef {
4,578✔
309
        self
4,578✔
310
    }
4,578✔
311
}
312

313
mod private {
314
    use super::*;
315

316
    pub trait Sealed {}
317

318
    impl<V: VTable> Sealed for ArrayAdapter<V> {}
319
    impl Sealed for Arc<dyn Array> {}
320
}
321

322
/// Adapter struct used to lift the [`VTable`] trait into an object-safe [`Array`]
323
/// implementation.
324
///
325
/// Since this is a unit struct with `repr(transparent)`, we are able to turn un-adapted array
326
/// structs into [`dyn Array`] using some cheeky casting inside [`std::ops::Deref`] and
327
/// [`AsRef`]. See the `vtable!` macro for more details.
328
#[repr(transparent)]
329
pub struct ArrayAdapter<V: VTable>(V::Array);
330

331
impl<V: VTable> Debug for ArrayAdapter<V> {
332
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
333
        self.0.fmt(f)
×
334
    }
×
335
}
336

337
impl<V: VTable> Array for ArrayAdapter<V> {
338
    fn as_any(&self) -> &dyn Any {
1,215,316✔
339
        self
1,215,316✔
340
    }
1,215,316✔
341

342
    fn to_array(&self) -> ArrayRef {
324,166✔
343
        Arc::new(ArrayAdapter::<V>(self.0.clone()))
324,166✔
344
    }
324,166✔
345

346
    fn len(&self) -> usize {
13,932,787✔
347
        <V::ArrayVTable as ArrayVTable<V>>::len(&self.0)
13,932,787✔
348
    }
13,932,787✔
349

350
    fn dtype(&self) -> &DType {
28,502,707✔
351
        <V::ArrayVTable as ArrayVTable<V>>::dtype(&self.0)
28,502,707✔
352
    }
28,502,707✔
353

354
    fn encoding(&self) -> EncodingRef {
25,185✔
355
        V::encoding(&self.0)
25,185✔
356
    }
25,185✔
357

358
    fn encoding_id(&self) -> EncodingId {
443,996✔
359
        V::encoding(&self.0).id()
443,996✔
360
    }
443,996✔
361

362
    fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
72,450✔
363
        if start == 0 && stop == self.len() {
72,450✔
364
            return Ok(self.to_array());
9,721✔
365
        }
62,729✔
366

367
        if start > self.len() {
62,729✔
368
            vortex_bail!(OutOfBounds: start, 0, self.len());
×
369
        }
62,729✔
370
        if stop > self.len() {
62,729✔
371
            vortex_bail!(OutOfBounds: stop, 0, self.len());
×
372
        }
62,729✔
373
        if start > stop {
62,729✔
374
            vortex_bail!("start ({start}) must be <= stop ({stop})");
×
375
        }
62,729✔
376
        if start == stop {
62,729✔
377
            return Ok(Canonical::empty(self.dtype()).into_array());
23✔
378
        }
62,706✔
379

380
        let sliced = <V::OperationsVTable as OperationsVTable<V>>::slice(&self.0, start, stop)?;
62,706✔
381

382
        assert_eq!(
62,706✔
383
            sliced.len(),
62,706✔
384
            stop - start,
62,706✔
385
            "Slice length mismatch {}",
×
386
            self.encoding_id()
×
387
        );
388

389
        // Slightly more expensive, so only do this in debug builds.
390
        debug_assert_eq!(
62,706✔
391
            sliced.dtype(),
62,706✔
392
            self.dtype(),
62,706✔
393
            "Slice dtype mismatch {}",
×
394
            self.encoding_id()
×
395
        );
396

397
        // Propagate some stats from the original array to the sliced array.
398
        if !sliced.is::<ConstantVTable>() {
62,706✔
399
            self.statistics().with_iter(|iter| {
53,920✔
400
                sliced.statistics().inherit(iter.filter(|stat| {
122,466✔
401
                    matches!(stat, (
7,320✔
402
                               Stat::IsConstant | Stat::IsSorted | Stat::IsStrictSorted,
403
                               Precision::Exact(value),
7,320✔
404
                           ) if value
7,320✔
405
                            .as_bool()
7,320✔
406
                            .vortex_expect("must be a bool")
7,320✔
407
                            .unwrap_or_default())
7,320✔
408
                }));
122,094✔
409
            });
53,920✔
410
        }
8,786✔
411

412
        Ok(sliced)
62,706✔
413
    }
72,450✔
414

415
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar> {
3,660,117✔
416
        if index >= self.len() {
3,660,117✔
417
            vortex_bail!(OutOfBounds: index, 0, self.len());
8✔
418
        }
3,660,109✔
419
        if self.is_invalid(index)? {
3,660,109✔
420
            return Ok(Scalar::null(self.dtype().clone()));
2,807✔
421
        }
3,657,302✔
422
        let scalar = <V::OperationsVTable as OperationsVTable<V>>::scalar_at(&self.0, index)?;
3,657,302✔
423
        assert_eq!(self.dtype(), scalar.dtype(), "Scalar dtype mismatch");
3,657,302✔
424
        Ok(scalar)
3,657,302✔
425
    }
3,660,117✔
426

427
    fn is_valid(&self, index: usize) -> VortexResult<bool> {
6,120,734✔
428
        if index >= self.len() {
6,120,734✔
429
            vortex_bail!(OutOfBounds: index, 0, self.len());
×
430
        }
6,120,734✔
431
        <V::ValidityVTable as ValidityVTable<V>>::is_valid(&self.0, index)
6,120,734✔
432
    }
6,120,734✔
433

434
    fn is_invalid(&self, index: usize) -> VortexResult<bool> {
3,660,867✔
435
        self.is_valid(index).map(|valid| !valid)
3,660,867✔
436
    }
3,660,867✔
437

438
    fn all_valid(&self) -> VortexResult<bool> {
3,199,733✔
439
        <V::ValidityVTable as ValidityVTable<V>>::all_valid(&self.0)
3,199,733✔
440
    }
3,199,733✔
441

442
    fn all_invalid(&self) -> VortexResult<bool> {
118,798✔
443
        <V::ValidityVTable as ValidityVTable<V>>::all_invalid(&self.0)
118,798✔
444
    }
118,798✔
445

446
    fn valid_count(&self) -> VortexResult<usize> {
62,945✔
447
        if let Some(Precision::Exact(invalid_count)) =
6,432✔
448
            self.statistics().get_as::<usize>(Stat::NullCount)
62,945✔
449
        {
450
            return Ok(self.len() - invalid_count);
6,432✔
451
        }
56,513✔
452

453
        let count = <V::ValidityVTable as ValidityVTable<V>>::valid_count(&self.0)?;
56,513✔
454
        assert!(count <= self.len(), "Valid count exceeds array length");
56,513✔
455

456
        self.statistics()
56,513✔
457
            .set(Stat::NullCount, Precision::exact(self.len() - count));
56,513✔
458

459
        Ok(count)
56,513✔
460
    }
62,945✔
461

462
    fn invalid_count(&self) -> VortexResult<usize> {
14,681✔
463
        if let Some(Precision::Exact(invalid_count)) =
1,066✔
464
            self.statistics().get_as::<usize>(Stat::NullCount)
14,681✔
465
        {
466
            return Ok(invalid_count);
1,066✔
467
        }
13,615✔
468

469
        let count = <V::ValidityVTable as ValidityVTable<V>>::invalid_count(&self.0)?;
13,615✔
470
        assert!(count <= self.len(), "Invalid count exceeds array length");
13,615✔
471

472
        self.statistics()
13,615✔
473
            .set(Stat::NullCount, Precision::exact(count));
13,615✔
474

475
        Ok(count)
13,615✔
476
    }
14,681✔
477

478
    fn validity_mask(&self) -> VortexResult<Mask> {
266,227✔
479
        let mask = <V::ValidityVTable as ValidityVTable<V>>::validity_mask(&self.0)?;
266,227✔
480
        assert_eq!(mask.len(), self.len(), "Validity mask length mismatch");
266,227✔
481
        Ok(mask)
266,227✔
482
    }
266,227✔
483

484
    fn to_canonical(&self) -> VortexResult<Canonical> {
315,506✔
485
        let canonical = <V::CanonicalVTable as CanonicalVTable<V>>::canonicalize(&self.0)?;
315,506✔
486
        assert_eq!(
315,506✔
487
            self.len(),
315,506✔
488
            canonical.as_ref().len(),
315,506✔
489
            "Canonical length mismatch {}. Expected {} but encoded into {}.",
×
490
            self.encoding_id(),
×
491
            self.len(),
×
492
            canonical.as_ref().len()
×
493
        );
494
        assert_eq!(
315,506✔
495
            self.dtype(),
315,506✔
496
            canonical.as_ref().dtype(),
315,506✔
497
            "Canonical dtype mismatch {}. Expected {} but encoded into {}.",
×
498
            self.encoding_id(),
×
499
            self.dtype(),
×
500
            canonical.as_ref().dtype()
×
501
        );
502
        canonical
315,506✔
503
            .as_ref()
315,506✔
504
            .statistics()
315,506✔
505
            .replace(self.statistics().to_owned());
315,506✔
506
        Ok(canonical)
315,506✔
507
    }
315,506✔
508

509
    fn append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
43,271✔
510
        if builder.dtype() != self.dtype() {
43,271✔
511
            vortex_bail!(
×
512
                "Builder dtype mismatch: expected {}, got {}",
×
513
                self.dtype(),
×
514
                builder.dtype(),
×
515
            );
516
        }
43,271✔
517
        let len = builder.len();
43,271✔
518

519
        <V::CanonicalVTable as CanonicalVTable<V>>::append_to_builder(&self.0, builder)?;
43,271✔
520
        assert_eq!(
43,271✔
521
            len + self.len(),
43,271✔
522
            builder.len(),
43,271✔
523
            "Builder length mismatch after writing array for encoding {}",
×
524
            self.encoding_id(),
×
525
        );
526
        Ok(())
43,271✔
527
    }
43,271✔
528

529
    fn statistics(&self) -> StatsSetRef<'_> {
1,737,300✔
530
        <V::ArrayVTable as ArrayVTable<V>>::stats(&self.0)
1,737,300✔
531
    }
1,737,300✔
532

533
    fn with_children(&self, children: &[ArrayRef]) -> VortexResult<ArrayRef> {
×
534
        struct ReplacementChildren<'a> {
535
            children: &'a [ArrayRef],
536
        }
537

538
        impl ArrayChildren for ReplacementChildren<'_> {
539
            fn get(&self, index: usize, dtype: &DType, len: usize) -> VortexResult<ArrayRef> {
×
540
                if index >= self.children.len() {
×
541
                    vortex_bail!(OutOfBounds: index, 0, self.children.len());
×
542
                }
×
543
                let child = &self.children[index];
×
544
                if child.len() != len {
×
545
                    vortex_bail!(
×
546
                        "Child length mismatch: expected {}, got {}",
×
547
                        len,
548
                        child.len()
×
549
                    );
550
                }
×
551
                if child.dtype() != dtype {
×
552
                    vortex_bail!(
×
553
                        "Child dtype mismatch: expected {}, got {}",
×
554
                        dtype,
555
                        child.dtype()
×
556
                    );
557
                }
×
558
                Ok(child.clone())
×
559
            }
×
560

561
            fn len(&self) -> usize {
×
562
                self.children.len()
×
563
            }
×
564
        }
565

566
        let metadata = self.metadata()?.ok_or_else(|| {
×
567
            vortex_err!("Cannot replace children for arrays that do not support serialization")
×
568
        })?;
×
569

570
        // Replace the children of the array by re-building the array from parts.
571
        self.encoding().build(
×
572
            self.dtype(),
×
573
            self.len(),
×
574
            &metadata,
×
575
            &self.buffers(),
×
576
            &ReplacementChildren { children },
×
577
        )
×
578
    }
×
579

580
    fn invoke(
43,588✔
581
        &self,
43,588✔
582
        compute_fn: &ComputeFn,
43,588✔
583
        args: &InvocationArgs,
43,588✔
584
    ) -> VortexResult<Option<Output>> {
43,588✔
585
        <V::ComputeVTable as ComputeVTable<V>>::invoke(&self.0, compute_fn, args)
43,588✔
586
    }
43,588✔
587
}
588

589
impl<V: VTable> ArrayVisitor for ArrayAdapter<V> {
590
    fn children(&self) -> Vec<ArrayRef> {
301,731✔
591
        struct ChildrenCollector {
592
            children: Vec<ArrayRef>,
593
        }
594

595
        impl ArrayChildVisitor for ChildrenCollector {
596
            fn visit_child(&mut self, _name: &str, array: &dyn Array) {
122,806✔
597
                self.children.push(array.to_array());
122,806✔
598
            }
122,806✔
599
        }
600

601
        let mut collector = ChildrenCollector {
301,731✔
602
            children: Vec::new(),
301,731✔
603
        };
301,731✔
604
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
301,731✔
605
        collector.children
301,731✔
606
    }
301,731✔
607

608
    fn nchildren(&self) -> usize {
×
609
        <V::VisitorVTable as VisitorVTable<V>>::nchildren(&self.0)
×
610
    }
×
611

612
    fn children_names(&self) -> Vec<String> {
706✔
613
        struct ChildNameCollector {
614
            names: Vec<String>,
615
        }
616

617
        impl ArrayChildVisitor for ChildNameCollector {
618
            fn visit_child(&mut self, name: &str, _array: &dyn Array) {
482✔
619
                self.names.push(name.to_string());
482✔
620
            }
482✔
621
        }
622

623
        let mut collector = ChildNameCollector { names: Vec::new() };
706✔
624
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
706✔
625
        collector.names
706✔
626
    }
706✔
627

628
    fn named_children(&self) -> Vec<(String, ArrayRef)> {
×
629
        struct NamedChildrenCollector {
630
            children: Vec<(String, ArrayRef)>,
631
        }
632

633
        impl ArrayChildVisitor for NamedChildrenCollector {
634
            fn visit_child(&mut self, name: &str, array: &dyn Array) {
×
635
                self.children.push((name.to_string(), array.to_array()));
×
636
            }
×
637
        }
638

639
        let mut collector = NamedChildrenCollector {
×
640
            children: Vec::new(),
×
641
        };
×
642

643
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
×
644
        collector.children
×
645
    }
×
646

647
    fn buffers(&self) -> Vec<ByteBuffer> {
230,476✔
648
        struct BufferCollector {
649
            buffers: Vec<ByteBuffer>,
650
        }
651

652
        impl ArrayBufferVisitor for BufferCollector {
653
            fn visit_buffer(&mut self, buffer: &ByteBuffer) {
275,540✔
654
                self.buffers.push(buffer.clone());
275,540✔
655
            }
275,540✔
656
        }
657

658
        let mut collector = BufferCollector {
230,476✔
659
            buffers: Vec::new(),
230,476✔
660
        };
230,476✔
661
        <V::VisitorVTable as VisitorVTable<V>>::visit_buffers(&self.0, &mut collector);
230,476✔
662
        collector.buffers
230,476✔
663
    }
230,476✔
664

665
    fn nbuffers(&self) -> usize {
45,971✔
666
        <V::VisitorVTable as VisitorVTable<V>>::nbuffers(&self.0)
45,971✔
667
    }
45,971✔
668

669
    fn metadata(&self) -> VortexResult<Option<Vec<u8>>> {
50,370✔
670
        Ok(<V::SerdeVTable as SerdeVTable<V>>::metadata(&self.0)?.map(|m| m.serialize()))
50,370✔
671
    }
50,370✔
672

673
    fn metadata_fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
706✔
674
        match <V::SerdeVTable as SerdeVTable<V>>::metadata(&self.0) {
706✔
675
            Err(e) => write!(f, "<serde error: {e}>"),
×
676
            Ok(None) => write!(f, "<serde not supported>"),
×
677
            Ok(Some(metadata)) => Debug::fmt(&metadata, f),
706✔
678
        }
679
    }
706✔
680
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc