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

vortex-data / vortex / 16272455594

14 Jul 2025 04:31PM UTC coverage: 81.537% (+0.06%) from 81.481%
16272455594

Pull #3870

github

web-flow
Merge 10f7e63d5 into 9b0d852a1
Pull Request #3870: chore[bench]: move tpcds into new benchmark format

46270 of 56747 relevant lines covered (81.54%)

145245.28 hits per line

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

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

4
mod convert;
5
pub mod display;
6
mod statistics;
7
mod visitor;
8

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

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

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

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

40
    /// Returns the array as an [`ArrayRef`].
41
    fn to_array(&self) -> ArrayRef;
42

43
    /// Returns the length of the array.
44
    fn len(&self) -> usize;
45

46
    /// Returns whether the array is empty (has zero rows).
47
    fn is_empty(&self) -> bool {
209,911✔
48
        self.len() == 0
209,911✔
49
    }
209,911✔
50

51
    /// Returns the logical Vortex [`DType`] of the array.
52
    fn dtype(&self) -> &DType;
53

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

57
    /// Returns the encoding ID of the array.
58
    fn encoding_id(&self) -> EncodingId;
59

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

63
    /// Fetch the scalar at the given index.
64
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar>;
65

66
    /// Return an optimized version of the same array.
67
    ///
68
    /// See [`OperationsVTable::optimize`] for more details.
69
    fn optimize(&self) -> VortexResult<ArrayRef>;
70

71
    /// Returns whether the array is of the given encoding.
72
    fn is_encoding(&self, encoding: EncodingId) -> bool {
342,409✔
73
        self.encoding_id() == encoding
342,409✔
74
    }
342,409✔
75

76
    /// Returns whether this array is an arrow encoding.
77
    // TODO(ngates): this shouldn't live here.
78
    fn is_arrow(&self) -> bool {
8,283✔
79
        self.is_encoding(NullEncoding.id())
8,283✔
80
            || self.is_encoding(BoolEncoding.id())
8,283✔
81
            || self.is_encoding(PrimitiveEncoding.id())
7,172✔
82
            || self.is_encoding(VarBinEncoding.id())
5,296✔
83
            || self.is_encoding(VarBinViewEncoding.id())
5,296✔
84
    }
8,283✔
85

86
    /// Whether the array is of a canonical encoding.
87
    // TODO(ngates): this shouldn't live here.
88
    fn is_canonical(&self) -> bool {
49,575✔
89
        self.is_encoding(NullEncoding.id())
49,575✔
90
            || self.is_encoding(BoolEncoding.id())
49,575✔
91
            || self.is_encoding(PrimitiveEncoding.id())
48,095✔
92
            || self.is_encoding(DecimalEncoding.id())
32,961✔
93
            || self.is_encoding(StructEncoding.id())
31,652✔
94
            || self.is_encoding(ListEncoding.id())
30,395✔
95
            || self.is_encoding(VarBinViewEncoding.id())
30,393✔
96
            || self.is_encoding(ExtensionEncoding.id())
29,126✔
97
    }
49,575✔
98

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

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

105
    /// Returns whether all items in the array are valid.
106
    ///
107
    /// This is usually cheaper than computing a precise `valid_count`.
108
    fn all_valid(&self) -> VortexResult<bool>;
109

110
    /// Returns whether the array is all invalid.
111
    ///
112
    /// This is usually cheaper than computing a precise `invalid_count`.
113
    fn all_invalid(&self) -> VortexResult<bool>;
114

115
    /// Returns the number of valid elements in the array.
116
    fn valid_count(&self) -> VortexResult<usize>;
117

118
    /// Returns the number of invalid elements in the array.
119
    fn invalid_count(&self) -> VortexResult<usize>;
120

121
    /// Returns the canonical validity mask for the array.
122
    fn validity_mask(&self) -> VortexResult<Mask>;
123

124
    /// Returns the canonical representation of the array.
125
    fn to_canonical(&self) -> VortexResult<Canonical>;
126

127
    /// Writes the array into the canonical builder.
128
    ///
129
    /// The [`DType`] of the builder must match that of the array.
130
    fn append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()>;
131

132
    /// Returns the statistics of the array.
133
    // TODO(ngates): change how this works. It's weird.
134
    fn statistics(&self) -> StatsSetRef<'_>;
135

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

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

159
impl Array for Arc<dyn Array> {
160
    fn as_any(&self) -> &dyn Any {
524,759✔
161
        self.as_ref().as_any()
524,759✔
162
    }
524,759✔
163

164
    fn to_array(&self) -> ArrayRef {
124,511✔
165
        self.clone()
124,511✔
166
    }
124,511✔
167

168
    fn len(&self) -> usize {
1,038,966✔
169
        self.as_ref().len()
1,038,966✔
170
    }
1,038,966✔
171

172
    fn dtype(&self) -> &DType {
821,965✔
173
        self.as_ref().dtype()
821,965✔
174
    }
821,965✔
175

176
    fn encoding(&self) -> EncodingRef {
17,966✔
177
        self.as_ref().encoding()
17,966✔
178
    }
17,966✔
179

180
    fn encoding_id(&self) -> EncodingId {
303,604✔
181
        self.as_ref().encoding_id()
303,604✔
182
    }
303,604✔
183

184
    fn slice(&self, start: usize, end: usize) -> VortexResult<ArrayRef> {
34,440✔
185
        self.as_ref().slice(start, end)
34,440✔
186
    }
34,440✔
187

188
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar> {
489,634✔
189
        self.as_ref().scalar_at(index)
489,634✔
190
    }
489,634✔
191

192
    fn optimize(&self) -> VortexResult<ArrayRef> {
×
193
        self.as_ref().optimize()
×
194
    }
×
195

196
    fn is_valid(&self, index: usize) -> VortexResult<bool> {
30,263✔
197
        self.as_ref().is_valid(index)
30,263✔
198
    }
30,263✔
199

200
    fn is_invalid(&self, index: usize) -> VortexResult<bool> {
362✔
201
        self.as_ref().is_invalid(index)
362✔
202
    }
362✔
203

204
    fn all_valid(&self) -> VortexResult<bool> {
24,935✔
205
        self.as_ref().all_valid()
24,935✔
206
    }
24,935✔
207

208
    fn all_invalid(&self) -> VortexResult<bool> {
42,368✔
209
        self.as_ref().all_invalid()
42,368✔
210
    }
42,368✔
211

212
    fn valid_count(&self) -> VortexResult<usize> {
2,616✔
213
        self.as_ref().valid_count()
2,616✔
214
    }
2,616✔
215

216
    fn invalid_count(&self) -> VortexResult<usize> {
433✔
217
        self.as_ref().invalid_count()
433✔
218
    }
433✔
219

220
    fn validity_mask(&self) -> VortexResult<Mask> {
6,026✔
221
        self.as_ref().validity_mask()
6,026✔
222
    }
6,026✔
223

224
    fn to_canonical(&self) -> VortexResult<Canonical> {
217,715✔
225
        self.as_ref().to_canonical()
217,715✔
226
    }
217,715✔
227

228
    fn append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
40,236✔
229
        self.as_ref().append_to_builder(builder)
40,236✔
230
    }
40,236✔
231

232
    fn statistics(&self) -> StatsSetRef<'_> {
396,430✔
233
        self.as_ref().statistics()
396,430✔
234
    }
396,430✔
235

236
    fn with_children(&self, children: &[ArrayRef]) -> VortexResult<ArrayRef> {
×
237
        self.as_ref().with_children(children)
×
238
    }
×
239

240
    fn invoke(
32,867✔
241
        &self,
32,867✔
242
        compute_fn: &ComputeFn,
32,867✔
243
        args: &InvocationArgs,
32,867✔
244
    ) -> VortexResult<Option<Output>> {
32,867✔
245
        self.as_ref().invoke(compute_fn, args)
32,867✔
246
    }
32,867✔
247
}
248

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

252
impl ToOwned for dyn Array {
253
    type Owned = ArrayRef;
254

255
    fn to_owned(&self) -> Self::Owned {
×
256
        self.to_array()
×
257
    }
×
258
}
259

260
impl dyn Array + '_ {
261
    /// Returns the array downcast to the given `A`.
262
    pub fn as_<V: VTable>(&self) -> &V::Array {
259✔
263
        self.as_opt::<V>().vortex_expect("Failed to downcast")
259✔
264
    }
259✔
265

266
    /// Returns the array downcast to the given `A`.
267
    pub fn as_opt<V: VTable>(&self) -> Option<&V::Array> {
1,320,009✔
268
        self.as_any()
1,320,009✔
269
            .downcast_ref::<ArrayAdapter<V>>()
1,320,009✔
270
            .map(|array_adapter| &array_adapter.0)
1,320,009✔
271
    }
1,320,009✔
272

273
    /// Is self an array with encoding from vtable `V`.
274
    pub fn is<V: VTable>(&self) -> bool {
9,224✔
275
        self.as_opt::<V>().is_some()
9,224✔
276
    }
9,224✔
277
}
278

279
impl dyn Array + '_ {
280
    /// Total size of the array in bytes, including all children and buffers.
281
    // TODO(ngates): this should return u64
282
    pub fn nbytes(&self) -> usize {
149,174✔
283
        let mut nbytes = 0;
149,174✔
284
        for array in self.depth_first_traversal() {
209,516✔
285
            for buffer in array.buffers() {
265,836✔
286
                nbytes += buffer.len();
265,836✔
287
            }
265,836✔
288
        }
289
        nbytes
149,174✔
290
    }
149,174✔
291
}
292

293
mod private {
294
    use super::*;
295

296
    pub trait Sealed {}
297

298
    impl<V: VTable> Sealed for ArrayAdapter<V> {}
299
    impl Sealed for Arc<dyn Array> {}
300
}
301

302
/// Adapter struct used to lift the [`VTable`] trait into an object-safe [`Array`]
303
/// implementation.
304
///
305
/// Since this is a unit struct with `repr(transparent)`, we are able to turn un-adapted array
306
/// structs into [`dyn Array`] using some cheeky casting inside [`std::ops::Deref`] and
307
/// [`AsRef`]. See the `vtable!` macro for more details.
308
#[repr(transparent)]
309
pub struct ArrayAdapter<V: VTable>(V::Array);
310

311
impl<V: VTable> Debug for ArrayAdapter<V> {
312
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
×
313
        self.0.fmt(f)
×
314
    }
×
315
}
316

317
impl<V: VTable> Array for ArrayAdapter<V> {
318
    fn as_any(&self) -> &dyn Any {
1,237,483✔
319
        self
1,237,483✔
320
    }
1,237,483✔
321

322
    fn to_array(&self) -> ArrayRef {
303,773✔
323
        Arc::new(ArrayAdapter::<V>(self.0.clone()))
303,773✔
324
    }
303,773✔
325

326
    fn len(&self) -> usize {
10,690,218✔
327
        <V::ArrayVTable as ArrayVTable<V>>::len(&self.0)
10,690,218✔
328
    }
10,690,218✔
329

330
    fn dtype(&self) -> &DType {
26,860,611✔
331
        <V::ArrayVTable as ArrayVTable<V>>::dtype(&self.0)
26,860,611✔
332
    }
26,860,611✔
333

334
    fn encoding(&self) -> EncodingRef {
24,010✔
335
        V::encoding(&self.0)
24,010✔
336
    }
24,010✔
337

338
    fn encoding_id(&self) -> EncodingId {
336,421✔
339
        V::encoding(&self.0).id()
336,421✔
340
    }
336,421✔
341

342
    fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
68,169✔
343
        if start == 0 && stop == self.len() {
68,169✔
344
            return Ok(self.to_array());
9,571✔
345
        }
58,598✔
346

58,598✔
347
        if start > self.len() {
58,598✔
348
            vortex_bail!(OutOfBounds: start, 0, self.len());
×
349
        }
58,598✔
350
        if stop > self.len() {
58,598✔
351
            vortex_bail!(OutOfBounds: stop, 0, self.len());
×
352
        }
58,598✔
353
        if start > stop {
58,598✔
354
            vortex_bail!("start ({start}) must be <= stop ({stop})");
×
355
        }
58,598✔
356

58,598✔
357
        if start == stop {
58,598✔
358
            return Ok(Canonical::empty(self.dtype()).into_array());
15✔
359
        }
58,583✔
360

58,583✔
361
        // We know that constant array don't need stats propagation, so we can avoid the overhead of
58,583✔
362
        // computing derived stats and merging them in.
58,583✔
363
        // TODO(ngates): skip the is_constant check here, it can force an expensive compute.
58,583✔
364
        // TODO(ngates): provide a means to slice an array _without_ propagating stats.
58,583✔
365
        let derived_stats = (!self.0.is_constant_opts(Cost::Negligible)).then(|| {
58,583✔
366
            let stats = self.statistics().to_owned();
49,631✔
367

49,631✔
368
            // an array that is not constant can become constant after slicing
49,631✔
369
            let is_constant = stats.get_as::<bool>(Stat::IsConstant);
49,631✔
370
            let is_sorted = stats.get_as::<bool>(Stat::IsSorted);
49,631✔
371
            let is_strict_sorted = stats.get_as::<bool>(Stat::IsStrictSorted);
49,631✔
372

49,631✔
373
            let mut stats = stats.keep_inexact_stats(&[
49,631✔
374
                Stat::Max,
49,631✔
375
                Stat::Min,
49,631✔
376
                Stat::NullCount,
49,631✔
377
                Stat::UncompressedSizeInBytes,
49,631✔
378
            ]);
49,631✔
379

49,631✔
380
            if is_constant == Some(Precision::Exact(true)) {
49,631✔
381
                stats.set(Stat::IsConstant, Precision::exact(true));
×
382
            }
49,631✔
383
            if is_sorted == Some(Precision::Exact(true)) {
49,631✔
384
                stats.set(Stat::IsSorted, Precision::exact(true));
1,135✔
385
            }
48,496✔
386
            if is_strict_sorted == Some(Precision::Exact(true)) {
49,631✔
387
                stats.set(Stat::IsStrictSorted, Precision::exact(true));
825✔
388
            }
48,806✔
389

390
            stats
49,631✔
391
        });
58,583✔
392

393
        let sliced = <V::OperationsVTable as OperationsVTable<V>>::slice(&self.0, start, stop)?;
58,583✔
394

395
        assert_eq!(
58,583✔
396
            sliced.len(),
58,583✔
397
            stop - start,
58,583✔
398
            "Slice length mismatch {}",
×
399
            self.encoding_id()
×
400
        );
401
        assert_eq!(
58,583✔
402
            sliced.dtype(),
58,583✔
403
            self.dtype(),
58,583✔
404
            "Slice dtype mismatch {}",
×
405
            self.encoding_id()
×
406
        );
407

408
        if let Some(derived_stats) = derived_stats {
58,583✔
409
            let mut stats = sliced.statistics().to_owned();
49,631✔
410
            stats.combine_sets(&derived_stats, self.dtype())?;
49,631✔
411
            for (stat, val) in stats.into_iter() {
103,362✔
412
                sliced.statistics().set(stat, val)
103,024✔
413
            }
414
        }
8,952✔
415

416
        Ok(sliced)
58,583✔
417
    }
68,169✔
418

419
    fn scalar_at(&self, index: usize) -> VortexResult<Scalar> {
3,441,798✔
420
        if index >= self.len() {
3,441,798✔
421
            vortex_bail!(OutOfBounds: index, 0, self.len());
8✔
422
        }
3,441,790✔
423
        if self.is_invalid(index)? {
3,441,790✔
424
            return Ok(Scalar::null(self.dtype().clone()));
2,672✔
425
        }
3,439,118✔
426
        let scalar = <V::OperationsVTable as OperationsVTable<V>>::scalar_at(&self.0, index)?;
3,439,118✔
427
        assert_eq!(self.dtype(), scalar.dtype(), "Scalar dtype mismatch");
3,439,118✔
428
        Ok(scalar)
3,439,118✔
429
    }
3,441,798✔
430

431
    fn optimize(&self) -> VortexResult<ArrayRef> {
4✔
432
        let result = <V::OperationsVTable as OperationsVTable<V>>::optimize(&self.0)?.into_array();
4✔
433

4✔
434
        #[cfg(debug_assertions)]
4✔
435
        {
4✔
436
            let nbytes = self.0.nbytes();
4✔
437
            let result_nbytes = result.nbytes();
4✔
438
            assert!(
4✔
439
                result_nbytes <= nbytes,
4✔
440
                "optimize() made the array larger: {} bytes -> {} bytes",
×
441
                nbytes,
442
                result_nbytes
443
            );
444
        }
445

446
        assert_eq!(
4✔
447
            self.dtype(),
4✔
448
            result.dtype(),
4✔
449
            "optimize() changed DType from {} to {}",
×
450
            self.dtype(),
×
451
            result.dtype()
×
452
        );
453
        assert_eq!(
4✔
454
            result.len(),
4✔
455
            self.len(),
4✔
456
            "optimize() changed len from {} to {}",
×
457
            self.len(),
×
458
            result.len()
×
459
        );
460

461
        Ok(result)
4✔
462
    }
4✔
463

464
    fn is_valid(&self, index: usize) -> VortexResult<bool> {
3,481,832✔
465
        if index >= self.len() {
3,481,832✔
466
            vortex_bail!(OutOfBounds: index, 0, self.len());
×
467
        }
3,481,832✔
468
        <V::ValidityVTable as ValidityVTable<V>>::is_valid(&self.0, index)
3,481,832✔
469
    }
3,481,832✔
470

471
    fn is_invalid(&self, index: usize) -> VortexResult<bool> {
3,442,524✔
472
        self.is_valid(index).map(|valid| !valid)
3,442,524✔
473
    }
3,442,524✔
474

475
    fn all_valid(&self) -> VortexResult<bool> {
3,072,986✔
476
        <V::ValidityVTable as ValidityVTable<V>>::all_valid(&self.0)
3,072,986✔
477
    }
3,072,986✔
478

479
    fn all_invalid(&self) -> VortexResult<bool> {
160,363✔
480
        <V::ValidityVTable as ValidityVTable<V>>::all_invalid(&self.0)
160,363✔
481
    }
160,363✔
482

483
    fn valid_count(&self) -> VortexResult<usize> {
54,248✔
484
        if let Some(Precision::Exact(invalid_count)) =
4,257✔
485
            self.statistics().get_as::<usize>(Stat::NullCount)
54,248✔
486
        {
487
            return Ok(self.len() - invalid_count);
4,257✔
488
        }
49,991✔
489

490
        let count = <V::ValidityVTable as ValidityVTable<V>>::valid_count(&self.0)?;
49,991✔
491
        assert!(count <= self.len(), "Valid count exceeds array length");
49,991✔
492

493
        self.statistics()
49,991✔
494
            .set(Stat::NullCount, Precision::exact(self.len() - count));
49,991✔
495

49,991✔
496
        Ok(count)
49,991✔
497
    }
54,248✔
498

499
    fn invalid_count(&self) -> VortexResult<usize> {
11,295✔
500
        if let Some(Precision::Exact(invalid_count)) =
3,414✔
501
            self.statistics().get_as::<usize>(Stat::NullCount)
11,295✔
502
        {
503
            return Ok(invalid_count);
3,414✔
504
        }
7,881✔
505

506
        let count = <V::ValidityVTable as ValidityVTable<V>>::invalid_count(&self.0)?;
7,881✔
507
        assert!(count <= self.len(), "Invalid count exceeds array length");
7,881✔
508

509
        self.statistics()
7,881✔
510
            .set(Stat::NullCount, Precision::exact(count));
7,881✔
511

7,881✔
512
        Ok(count)
7,881✔
513
    }
11,295✔
514

515
    fn validity_mask(&self) -> VortexResult<Mask> {
240,040✔
516
        let mask = <V::ValidityVTable as ValidityVTable<V>>::validity_mask(&self.0)?;
240,040✔
517
        assert_eq!(mask.len(), self.len(), "Validity mask length mismatch");
240,040✔
518
        Ok(mask)
240,040✔
519
    }
240,040✔
520

521
    fn to_canonical(&self) -> VortexResult<Canonical> {
286,183✔
522
        let canonical = <V::CanonicalVTable as CanonicalVTable<V>>::canonicalize(&self.0)?;
286,183✔
523
        assert_eq!(
286,183✔
524
            self.len(),
286,183✔
525
            canonical.as_ref().len(),
286,183✔
526
            "Canonical length mismatch {}. Expected {} but encoded into {}.",
×
527
            self.encoding_id(),
×
528
            self.len(),
×
529
            canonical.as_ref().len()
×
530
        );
531
        assert_eq!(
286,183✔
532
            self.dtype(),
286,183✔
533
            canonical.as_ref().dtype(),
286,183✔
534
            "Canonical dtype mismatch {}. Expected {} but encoded into {}.",
×
535
            self.encoding_id(),
×
536
            self.dtype(),
×
537
            canonical.as_ref().dtype()
×
538
        );
539
        canonical.as_ref().statistics().inherit(self.statistics());
286,183✔
540
        Ok(canonical)
286,183✔
541
    }
286,183✔
542

543
    fn append_to_builder(&self, builder: &mut dyn ArrayBuilder) -> VortexResult<()> {
42,027✔
544
        if builder.dtype() != self.dtype() {
42,027✔
545
            vortex_bail!(
×
546
                "Builder dtype mismatch: expected {}, got {}",
×
547
                self.dtype(),
×
548
                builder.dtype(),
×
549
            );
×
550
        }
42,027✔
551
        let len = builder.len();
42,027✔
552

42,027✔
553
        <V::CanonicalVTable as CanonicalVTable<V>>::append_to_builder(&self.0, builder)?;
42,027✔
554
        assert_eq!(
42,027✔
555
            len + self.len(),
42,027✔
556
            builder.len(),
42,027✔
557
            "Builder length mismatch after writing array for encoding {}",
×
558
            self.encoding_id(),
×
559
        );
560
        Ok(())
42,027✔
561
    }
42,027✔
562

563
    fn statistics(&self) -> StatsSetRef<'_> {
1,740,989✔
564
        <V::ArrayVTable as ArrayVTable<V>>::stats(&self.0)
1,740,989✔
565
    }
1,740,989✔
566

567
    fn with_children(&self, children: &[ArrayRef]) -> VortexResult<ArrayRef> {
×
568
        struct ReplacementChildren<'a> {
569
            children: &'a [ArrayRef],
570
        }
571

572
        impl ArrayChildren for ReplacementChildren<'_> {
573
            fn get(&self, index: usize, dtype: &DType, len: usize) -> VortexResult<ArrayRef> {
×
574
                if index >= self.children.len() {
×
575
                    vortex_bail!(OutOfBounds: index, 0, self.children.len());
×
576
                }
×
577
                let child = &self.children[index];
×
578
                if child.len() != len {
×
579
                    vortex_bail!(
×
580
                        "Child length mismatch: expected {}, got {}",
×
581
                        len,
×
582
                        child.len()
×
583
                    );
×
584
                }
×
585
                if child.dtype() != dtype {
×
586
                    vortex_bail!(
×
587
                        "Child dtype mismatch: expected {}, got {}",
×
588
                        dtype,
×
589
                        child.dtype()
×
590
                    );
×
591
                }
×
592
                Ok(child.clone())
×
593
            }
×
594

595
            fn len(&self) -> usize {
×
596
                self.children.len()
×
597
            }
×
598
        }
599

600
        let metadata = self.metadata()?.ok_or_else(|| {
×
601
            vortex_err!("Cannot replace children for arrays that do not support serialization")
×
602
        })?;
×
603

604
        // Replace the children of the array by re-building the array from parts.
605
        self.encoding().build(
×
606
            self.dtype(),
×
607
            self.len(),
×
608
            &metadata,
×
609
            &self.buffers(),
×
610
            &ReplacementChildren { children },
×
611
        )
×
612
    }
×
613

614
    fn invoke(
36,019✔
615
        &self,
36,019✔
616
        compute_fn: &ComputeFn,
36,019✔
617
        args: &InvocationArgs,
36,019✔
618
    ) -> VortexResult<Option<Output>> {
36,019✔
619
        <V::ComputeVTable as ComputeVTable<V>>::invoke(&self.0, compute_fn, args)
36,019✔
620
    }
36,019✔
621
}
622

623
impl<V: VTable> ArrayVisitor for ArrayAdapter<V> {
624
    fn children(&self) -> Vec<ArrayRef> {
287,075✔
625
        struct ChildrenCollector {
626
            children: Vec<ArrayRef>,
627
        }
628

629
        impl ArrayChildVisitor for ChildrenCollector {
630
            fn visit_child(&mut self, _name: &str, array: &dyn Array) {
117,791✔
631
                self.children.push(array.to_array());
117,791✔
632
            }
117,791✔
633
        }
634

635
        let mut collector = ChildrenCollector {
287,075✔
636
            children: Vec::new(),
287,075✔
637
        };
287,075✔
638
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
287,075✔
639
        collector.children
287,075✔
640
    }
287,075✔
641

642
    fn nchildren(&self) -> usize {
×
643
        <V::VisitorVTable as VisitorVTable<V>>::nchildren(&self.0)
×
644
    }
×
645

646
    fn children_names(&self) -> Vec<String> {
660✔
647
        struct ChildNameCollector {
648
            names: Vec<String>,
649
        }
650

651
        impl ArrayChildVisitor for ChildNameCollector {
652
            fn visit_child(&mut self, name: &str, _array: &dyn Array) {
456✔
653
                self.names.push(name.to_string());
456✔
654
            }
456✔
655
        }
656

657
        let mut collector = ChildNameCollector { names: Vec::new() };
660✔
658
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
660✔
659
        collector.names
660✔
660
    }
660✔
661

662
    fn named_children(&self) -> Vec<(String, ArrayRef)> {
×
663
        struct NamedChildrenCollector {
664
            children: Vec<(String, ArrayRef)>,
665
        }
666

667
        impl ArrayChildVisitor for NamedChildrenCollector {
668
            fn visit_child(&mut self, name: &str, array: &dyn Array) {
×
669
                self.children.push((name.to_string(), array.to_array()));
×
670
            }
×
671
        }
672

673
        let mut collector = NamedChildrenCollector {
×
674
            children: Vec::new(),
×
675
        };
×
676

×
677
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
×
678
        collector.children
×
679
    }
×
680

681
    fn buffers(&self) -> Vec<ByteBuffer> {
218,553✔
682
        struct BufferCollector {
683
            buffers: Vec<ByteBuffer>,
684
        }
685

686
        impl ArrayBufferVisitor for BufferCollector {
687
            fn visit_buffer(&mut self, buffer: &ByteBuffer) {
288,367✔
688
                self.buffers.push(buffer.clone());
288,367✔
689
            }
288,367✔
690
        }
691

692
        let mut collector = BufferCollector {
218,553✔
693
            buffers: Vec::new(),
218,553✔
694
        };
218,553✔
695
        <V::VisitorVTable as VisitorVTable<V>>::visit_buffers(&self.0, &mut collector);
218,553✔
696
        collector.buffers
218,553✔
697
    }
218,553✔
698

699
    fn nbuffers(&self) -> usize {
44,412✔
700
        <V::VisitorVTable as VisitorVTable<V>>::nbuffers(&self.0)
44,412✔
701
    }
44,412✔
702

703
    fn metadata(&self) -> VortexResult<Option<Vec<u8>>> {
48,020✔
704
        Ok(<V::SerdeVTable as SerdeVTable<V>>::metadata(&self.0)?.map(|m| m.serialize()))
48,020✔
705
    }
48,020✔
706

707
    fn metadata_fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
660✔
708
        match <V::SerdeVTable as SerdeVTable<V>>::metadata(&self.0) {
660✔
709
            Err(e) => write!(f, "<serde error: {e}>"),
×
710
            Ok(None) => write!(f, "<serde not supported>"),
×
711
            Ok(Some(metadata)) => Debug::fmt(&metadata, f),
660✔
712
        }
713
    }
660✔
714
}
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