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

vortex-data / vortex / 16598973893

29 Jul 2025 02:25PM UTC coverage: 82.692% (-0.01%) from 82.703%
16598973893

push

github

web-flow
Clean up stats propagation for slicing (#3356)

Reduces the amount we copy some stats (by removing into_iter that forces
a full stats copy)

---------

Signed-off-by: Nicholas Gates <nick@nickgates.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Will Manning <will@willmanning.io>
Co-authored-by: Robert Kruszewski <github@robertk.io>
Co-authored-by: Will Manning <will@willmanning.io>

130 of 157 new or added lines in 15 files covered. (82.8%)

30 existing lines in 13 files now uncovered.

45215 of 54679 relevant lines covered (82.69%)

184610.34 hits per line

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

77.49
/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 {
302,990✔
45
        self.len() == 0
302,990✔
46
    }
302,990✔
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 {
494,082✔
65
        self.encoding_id() == encoding
494,082✔
66
    }
494,082✔
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,471✔
71
        self.is_encoding(NullEncoding.id())
15,471✔
72
            || self.is_encoding(BoolEncoding.id())
15,471✔
73
            || self.is_encoding(PrimitiveEncoding.id())
11,772✔
74
            || self.is_encoding(VarBinEncoding.id())
9,425✔
75
            || self.is_encoding(VarBinViewEncoding.id())
9,425✔
76
    }
15,471✔
77

78
    /// Whether the array is of a canonical encoding.
79
    // TODO(ngates): this shouldn't live here.
80
    fn is_canonical(&self) -> bool {
71,538✔
81
        self.is_encoding(NullEncoding.id())
71,538✔
82
            || self.is_encoding(BoolEncoding.id())
71,538✔
83
            || self.is_encoding(PrimitiveEncoding.id())
67,440✔
84
            || self.is_encoding(DecimalEncoding.id())
45,267✔
85
            || self.is_encoding(StructEncoding.id())
43,952✔
86
            || self.is_encoding(ListEncoding.id())
42,661✔
87
            || self.is_encoding(VarBinViewEncoding.id())
42,355✔
88
            || self.is_encoding(ExtensionEncoding.id())
40,335✔
89
    }
71,538✔
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 {
992,304✔
153
        self.as_ref().as_any()
992,304✔
154
    }
992,304✔
155

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

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

164
    fn dtype(&self) -> &DType {
1,361,241✔
165
        self.as_ref().dtype()
1,361,241✔
166
    }
1,361,241✔
167

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

228
    fn invoke(
48,760✔
229
        &self,
48,760✔
230
        compute_fn: &ComputeFn,
48,760✔
231
        args: &InvocationArgs,
48,760✔
232
    ) -> VortexResult<Option<Output>> {
48,760✔
233
        self.as_ref().invoke(compute_fn, args)
48,760✔
234
    }
48,760✔
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 {
300✔
251
        self.as_opt::<V>().vortex_expect("Failed to downcast")
300✔
252
    }
300✔
253

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

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

266
    pub fn is_constant(&self) -> bool {
245,082✔
267
        let opts = IsConstantOpts {
245,082✔
268
            cost: Cost::Specialized,
245,082✔
269
        };
245,082✔
270
        is_constant_opts(self, &opts)
245,082✔
271
            .inspect_err(|e| log::warn!("Failed to compute IsConstant: {e}"))
245,082✔
272
            .ok()
245,082✔
273
            .flatten()
245,082✔
274
            .unwrap_or_default()
245,082✔
275
    }
245,082✔
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> {
125,070✔
287
        self.is_constant().then(|| self.scalar_at(0).ok()).flatten()
125,070✔
288
    }
125,070✔
289

290
    /// Total size of the array in bytes, including all children and buffers.
291
    pub fn nbytes(&self) -> u64 {
159,330✔
292
        let mut nbytes = 0;
159,330✔
293
        for array in self.depth_first_traversal() {
223,986✔
294
            for buffer in array.buffers() {
256,644✔
295
                nbytes += buffer.len() as u64;
256,644✔
296
            }
256,644✔
297
        }
298
        nbytes
159,330✔
299
    }
159,330✔
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,692✔
309
        self
4,692✔
310
    }
4,692✔
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,768,258✔
339
        self
1,768,258✔
340
    }
1,768,258✔
341

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

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

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

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

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

362
    fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
76,264✔
363
        if start == 0 && stop == self.len() {
76,264✔
364
            return Ok(self.to_array());
10,192✔
365
        }
66,072✔
366

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

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

382
        assert_eq!(
65,901✔
383
            sliced.len(),
65,901✔
384
            stop - start,
65,901✔
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!(
65,901✔
391
            sliced.dtype(),
65,901✔
392
            self.dtype(),
65,901✔
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>() {
65,901✔
399
            self.statistics().with_iter(|iter| {
56,314✔
400
                sliced.statistics().inherit(iter.filter(|(stat, value)| {
119,122✔
401
                    matches!(
106,971✔
402
                        stat,
119,122✔
403
                        Stat::IsConstant | Stat::IsSorted | Stat::IsStrictSorted
404
                    ) && value.as_ref().as_exact().is_some_and(|v| {
12,151✔
405
                        v.as_bool()
12,151✔
406
                            .vortex_expect("must be a bool")
12,151✔
407
                            .unwrap_or_default()
12,151✔
408
                    })
12,151✔
409
                }));
119,122✔
410
            });
56,314✔
411
        }
9,587✔
412

413
        Ok(sliced)
65,901✔
414
    }
76,264✔
415

416
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar> {
5,967,300✔
417
        if index >= self.len() {
5,967,300✔
418
            vortex_bail!(OutOfBounds: index, 0, self.len());
8✔
419
        }
5,967,292✔
420
        if self.is_invalid(index)? {
5,967,292✔
421
            return Ok(Scalar::null(self.dtype().clone()));
13,714✔
422
        }
5,953,578✔
423
        let scalar = <V::OperationsVTable as OperationsVTable<V>>::scalar_at(&self.0, index)?;
5,953,578✔
424
        assert_eq!(self.dtype(), scalar.dtype(), "Scalar dtype mismatch");
5,953,578✔
425
        Ok(scalar)
5,953,578✔
426
    }
5,967,300✔
427

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

435
    fn is_invalid(&self, index: usize) -> VortexResult<bool> {
5,968,062✔
436
        self.is_valid(index).map(|valid| !valid)
5,968,062✔
437
    }
5,968,062✔
438

439
    fn all_valid(&self) -> VortexResult<bool> {
4,966,260✔
440
        <V::ValidityVTable as ValidityVTable<V>>::all_valid(&self.0)
4,966,260✔
441
    }
4,966,260✔
442

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

447
    fn valid_count(&self) -> VortexResult<usize> {
64,615✔
448
        if let Some(Precision::Exact(invalid_count)) =
6,581✔
449
            self.statistics().get_as::<usize>(Stat::NullCount)
64,615✔
450
        {
451
            return Ok(self.len() - invalid_count);
6,581✔
452
        }
58,034✔
453

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

457
        self.statistics()
58,034✔
458
            .set(Stat::NullCount, Precision::exact(self.len() - count));
58,034✔
459

460
        Ok(count)
58,034✔
461
    }
64,615✔
462

463
    fn invalid_count(&self) -> VortexResult<usize> {
16,403✔
464
        if let Some(Precision::Exact(invalid_count)) =
1,085✔
465
            self.statistics().get_as::<usize>(Stat::NullCount)
16,403✔
466
        {
467
            return Ok(invalid_count);
1,085✔
468
        }
15,318✔
469

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

473
        self.statistics()
15,318✔
474
            .set(Stat::NullCount, Precision::exact(count));
15,318✔
475

476
        Ok(count)
15,318✔
477
    }
16,403✔
478

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

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

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

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

530
    fn statistics(&self) -> StatsSetRef<'_> {
2,142,565✔
531
        <V::ArrayVTable as ArrayVTable<V>>::stats(&self.0)
2,142,565✔
532
    }
2,142,565✔
533

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

648
    fn buffers(&self) -> Vec<ByteBuffer> {
233,634✔
649
        struct BufferCollector {
650
            buffers: Vec<ByteBuffer>,
651
        }
652

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

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

666
    fn nbuffers(&self) -> usize {
46,897✔
667
        <V::VisitorVTable as VisitorVTable<V>>::nbuffers(&self.0)
46,897✔
668
    }
46,897✔
669

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

674
    fn metadata_fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
718✔
675
        match <V::SerdeVTable as SerdeVTable<V>>::metadata(&self.0) {
718✔
676
            Err(e) => write!(f, "<serde error: {e}>"),
×
677
            Ok(None) => write!(f, "<serde not supported>"),
×
678
            Ok(Some(metadata)) => Debug::fmt(&metadata, f),
718✔
679
        }
680
    }
718✔
681
}
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