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

vortex-data / vortex / 16331938722

16 Jul 2025 10:49PM UTC coverage: 80.702% (-0.9%) from 81.557%
16331938722

push

github

web-flow
feat: build with stable rust (#3881)

120 of 173 new or added lines in 28 files covered. (69.36%)

174 existing lines in 102 files now uncovered.

41861 of 51871 relevant lines covered (80.7%)

157487.71 hits per line

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

77.41
/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 {
215,110✔
48
        self.len() == 0
215,110✔
49
    }
215,110✔
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 {
347,829✔
73
        self.encoding_id() == encoding
347,829✔
74
    }
347,829✔
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,445✔
79
        self.is_encoding(NullEncoding.id())
8,445✔
80
            || self.is_encoding(BoolEncoding.id())
8,445✔
81
            || self.is_encoding(PrimitiveEncoding.id())
7,314✔
82
            || self.is_encoding(VarBinEncoding.id())
5,385✔
83
            || self.is_encoding(VarBinViewEncoding.id())
5,385✔
84
    }
8,445✔
85

86
    /// Whether the array is of a canonical encoding.
87
    // TODO(ngates): this shouldn't live here.
88
    fn is_canonical(&self) -> bool {
50,363✔
89
        self.is_encoding(NullEncoding.id())
50,363✔
90
            || self.is_encoding(BoolEncoding.id())
50,363✔
91
            || self.is_encoding(PrimitiveEncoding.id())
48,853✔
92
            || self.is_encoding(DecimalEncoding.id())
33,433✔
93
            || self.is_encoding(StructEncoding.id())
32,122✔
94
            || self.is_encoding(ListEncoding.id())
30,855✔
95
            || self.is_encoding(VarBinViewEncoding.id())
30,853✔
96
            || self.is_encoding(ExtensionEncoding.id())
29,563✔
97
    }
50,363✔
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 {
571,852✔
161
        self.as_ref().as_any()
571,852✔
162
    }
571,852✔
163

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

240
    fn invoke(
33,469✔
241
        &self,
33,469✔
242
        compute_fn: &ComputeFn,
33,469✔
243
        args: &InvocationArgs,
33,469✔
244
    ) -> VortexResult<Option<Output>> {
33,469✔
245
        self.as_ref().invoke(compute_fn, args)
33,469✔
246
    }
33,469✔
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 {
269✔
263
        self.as_opt::<V>().vortex_expect("Failed to downcast")
269✔
264
    }
269✔
265

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

273
    /// Is self an array with encoding from vtable `V`.
274
    pub fn is<V: VTable>(&self) -> bool {
9,595✔
275
        self.as_opt::<V>().is_some()
9,595✔
276
    }
9,595✔
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 {
152,761✔
283
        let mut nbytes = 0;
152,761✔
284
        for array in self.depth_first_traversal() {
214,713✔
285
            for buffer in array.buffers() {
271,674✔
286
                nbytes += buffer.len();
271,674✔
287
            }
271,674✔
288
        }
289
        nbytes
152,761✔
290
    }
152,761✔
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,560,134✔
319
        self
1,560,134✔
320
    }
1,560,134✔
321

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

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

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

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

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

342
    fn slice(&self, start: usize, stop: usize) -> VortexResult<ArrayRef> {
69,451✔
343
        if start == 0 && stop == self.len() {
69,451✔
344
            return Ok(self.to_array());
9,897✔
345
        }
59,554✔
346

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

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

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

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

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

380
            if is_constant == Some(Precision::Exact(true)) {
50,423✔
381
                stats.set(Stat::IsConstant, Precision::exact(true));
×
382
            }
50,423✔
383
            if is_sorted == Some(Precision::Exact(true)) {
50,423✔
384
                stats.set(Stat::IsSorted, Precision::exact(true));
1,150✔
385
            }
49,273✔
386
            if is_strict_sorted == Some(Precision::Exact(true)) {
50,423✔
387
                stats.set(Stat::IsStrictSorted, Precision::exact(true));
840✔
388
            }
49,583✔
389

390
            stats
50,423✔
391
        });
50,423✔
392

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

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

408
        if let Some(derived_stats) = derived_stats {
59,539✔
409
            let mut stats = sliced.statistics().to_owned();
50,423✔
410
            stats.combine_sets(&derived_stats, self.dtype())?;
50,423✔
411
            for (stat, val) in stats.into_iter() {
104,610✔
412
                sliced.statistics().set(stat, val)
104,272✔
413
            }
414
        }
9,116✔
415

416
        Ok(sliced)
59,539✔
417
    }
69,451✔
418

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

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

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

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

459
        Ok(result)
4✔
460
    }
4✔
461

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

469
    fn is_invalid(&self, index: usize) -> VortexResult<bool> {
3,541,324✔
470
        self.is_valid(index).map(|valid| !valid)
3,541,324✔
471
    }
3,541,324✔
472

473
    fn all_valid(&self) -> VortexResult<bool> {
3,158,493✔
474
        <V::ValidityVTable as ValidityVTable<V>>::all_valid(&self.0)
3,158,493✔
475
    }
3,158,493✔
476

477
    fn all_invalid(&self) -> VortexResult<bool> {
163,637✔
478
        <V::ValidityVTable as ValidityVTable<V>>::all_invalid(&self.0)
163,637✔
479
    }
163,637✔
480

481
    fn valid_count(&self) -> VortexResult<usize> {
55,630✔
482
        if let Some(Precision::Exact(invalid_count)) =
4,396✔
483
            self.statistics().get_as::<usize>(Stat::NullCount)
55,630✔
484
        {
485
            return Ok(self.len() - invalid_count);
4,396✔
486
        }
51,234✔
487

488
        let count = <V::ValidityVTable as ValidityVTable<V>>::valid_count(&self.0)?;
51,234✔
489
        assert!(count <= self.len(), "Valid count exceeds array length");
51,234✔
490

491
        self.statistics()
51,234✔
492
            .set(Stat::NullCount, Precision::exact(self.len() - count));
51,234✔
493

494
        Ok(count)
51,234✔
495
    }
55,630✔
496

497
    fn invalid_count(&self) -> VortexResult<usize> {
11,597✔
498
        if let Some(Precision::Exact(invalid_count)) =
3,569✔
499
            self.statistics().get_as::<usize>(Stat::NullCount)
11,597✔
500
        {
501
            return Ok(invalid_count);
3,569✔
502
        }
8,028✔
503

504
        let count = <V::ValidityVTable as ValidityVTable<V>>::invalid_count(&self.0)?;
8,028✔
505
        assert!(count <= self.len(), "Invalid count exceeds array length");
8,028✔
506

507
        self.statistics()
8,028✔
508
            .set(Stat::NullCount, Precision::exact(count));
8,028✔
509

510
        Ok(count)
8,028✔
511
    }
11,597✔
512

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

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

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

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

561
    fn statistics(&self) -> StatsSetRef<'_> {
1,781,278✔
562
        <V::ArrayVTable as ArrayVTable<V>>::stats(&self.0)
1,781,278✔
563
    }
1,781,278✔
564

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

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

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

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

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

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

621
impl<V: VTable> ArrayVisitor for ArrayAdapter<V> {
622
    fn children(&self) -> Vec<ArrayRef> {
295,351✔
623
        struct ChildrenCollector {
624
            children: Vec<ArrayRef>,
625
        }
626

627
        impl ArrayChildVisitor for ChildrenCollector {
628
            fn visit_child(&mut self, _name: &str, array: &dyn Array) {
121,439✔
629
                self.children.push(array.to_array());
121,439✔
630
            }
121,439✔
631
        }
632

633
        let mut collector = ChildrenCollector {
295,351✔
634
            children: Vec::new(),
295,351✔
635
        };
295,351✔
636
        <V::VisitorVTable as VisitorVTable<V>>::visit_children(&self.0, &mut collector);
295,351✔
637
        collector.children
295,351✔
638
    }
295,351✔
639

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

644
    fn children_names(&self) -> Vec<String> {
683✔
645
        struct ChildNameCollector {
646
            names: Vec<String>,
647
        }
648

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

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

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

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

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

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

679
    fn buffers(&self) -> Vec<ByteBuffer> {
224,558✔
680
        struct BufferCollector {
681
            buffers: Vec<ByteBuffer>,
682
        }
683

684
        impl ArrayBufferVisitor for BufferCollector {
685
            fn visit_buffer(&mut self, buffer: &ByteBuffer) {
295,205✔
686
                self.buffers.push(buffer.clone());
295,205✔
687
            }
295,205✔
688
        }
689

690
        let mut collector = BufferCollector {
224,558✔
691
            buffers: Vec::new(),
224,558✔
692
        };
224,558✔
693
        <V::VisitorVTable as VisitorVTable<V>>::visit_buffers(&self.0, &mut collector);
224,558✔
694
        collector.buffers
224,558✔
695
    }
224,558✔
696

697
    fn nbuffers(&self) -> usize {
45,864✔
698
        <V::VisitorVTable as VisitorVTable<V>>::nbuffers(&self.0)
45,864✔
699
    }
45,864✔
700

701
    fn metadata(&self) -> VortexResult<Option<Vec<u8>>> {
49,658✔
702
        Ok(<V::SerdeVTable as SerdeVTable<V>>::metadata(&self.0)?.map(|m| m.serialize()))
49,658✔
703
    }
49,658✔
704

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

© 2025 Coveralls, Inc