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

vortex-data / vortex / 17073077835

19 Aug 2025 02:40PM UTC coverage: 24.083%. First build
17073077835

Pull #4177

github

web-flow
Merge b42e5758f into 431a8f2b5
Pull Request #4177: feat: ArrayOperations infallible, eager validation + new_unchecked

197 of 1455 new or added lines in 154 files covered. (13.54%)

8646 of 35901 relevant lines covered (24.08%)

142.28 hits per line

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

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

4
use vortex_buffer::ByteBufferMut;
5
use vortex_dtype::DType;
6
use vortex_error::VortexResult;
7
use vortex_mask::Mask;
8
use vortex_scalar::Scalar;
9

10
use crate::stats::{ArrayStats, StatsSetRef};
11
use crate::vtable::{
12
    ArrayVTable, NotSupported, OperationsVTable, VTable, ValidityVTable, VisitorVTable,
13
};
14
use crate::{
15
    ArrayBufferVisitor, ArrayChildVisitor, ArrayRef, EncodingId, EncodingRef, IntoArray, vtable,
16
};
17

18
mod canonical;
19
mod compute;
20
mod encode;
21
mod serde;
22

23
vtable!(Constant);
24

25
#[derive(Clone, Debug)]
26
pub struct ConstantArray {
27
    scalar: Scalar,
28
    len: usize,
29
    stats_set: ArrayStats,
30
}
31

32
#[derive(Clone, Debug)]
33
pub struct ConstantEncoding;
34

35
impl VTable for ConstantVTable {
36
    type Array = ConstantArray;
37
    type Encoding = ConstantEncoding;
38

39
    type ArrayVTable = Self;
40
    type CanonicalVTable = Self;
41
    type OperationsVTable = Self;
42
    type ValidityVTable = Self;
43
    type VisitorVTable = Self;
44
    // TODO(ngates): implement a compute kernel for elementwise operations
45
    type ComputeVTable = NotSupported;
46
    type EncodeVTable = Self;
47
    type SerdeVTable = Self;
48

49
    fn id(_encoding: &Self::Encoding) -> EncodingId {
2✔
50
        EncodingId::new_ref("vortex.constant")
2✔
51
    }
2✔
52

53
    fn encoding(_array: &Self::Array) -> EncodingRef {
×
54
        EncodingRef::new_ref(ConstantEncoding.as_ref())
×
55
    }
×
56
}
57

58
impl ConstantArray {
59
    pub fn new<S>(scalar: S, len: usize) -> Self
16✔
60
    where
16✔
61
        S: Into<Scalar>,
16✔
62
    {
63
        let scalar = scalar.into();
16✔
64
        Self {
16✔
65
            scalar,
16✔
66
            len,
16✔
67
            stats_set: Default::default(),
16✔
68
        }
16✔
69
    }
16✔
70

71
    /// Returns the [`Scalar`] value of this constant array.
72
    pub fn scalar(&self) -> &Scalar {
8✔
73
        &self.scalar
8✔
74
    }
8✔
75
}
76

77
impl ArrayVTable<ConstantVTable> for ConstantVTable {
78
    fn len(array: &ConstantArray) -> usize {
32✔
79
        array.len
32✔
80
    }
32✔
81

82
    fn dtype(array: &ConstantArray) -> &DType {
40✔
83
        array.scalar.dtype()
40✔
84
    }
40✔
85

86
    fn stats(array: &ConstantArray) -> StatsSetRef<'_> {
8✔
87
        array.stats_set.to_ref(array.as_ref())
8✔
88
    }
8✔
89
}
90

91
impl OperationsVTable<ConstantVTable> for ConstantVTable {
NEW
92
    fn slice(array: &ConstantArray, start: usize, stop: usize) -> ArrayRef {
×
NEW
93
        ConstantArray::new(array.scalar.clone(), stop - start).into_array()
×
94
    }
×
95

NEW
96
    fn scalar_at(array: &ConstantArray, _index: usize) -> Scalar {
×
NEW
97
        array.scalar.clone()
×
98
    }
×
99
}
100

101
impl ValidityVTable<ConstantVTable> for ConstantVTable {
102
    fn is_valid(array: &ConstantArray, _index: usize) -> VortexResult<bool> {
×
103
        Ok(!array.scalar().is_null())
×
104
    }
×
105

106
    fn all_valid(array: &ConstantArray) -> VortexResult<bool> {
×
107
        Ok(!array.scalar().is_null())
×
108
    }
×
109

110
    fn all_invalid(array: &ConstantArray) -> VortexResult<bool> {
×
111
        Ok(array.scalar().is_null())
×
112
    }
×
113

114
    fn validity_mask(array: &ConstantArray) -> VortexResult<Mask> {
×
115
        Ok(match array.scalar().is_null() {
×
116
            true => Mask::AllFalse(array.len()),
×
117
            false => Mask::AllTrue(array.len()),
×
118
        })
119
    }
×
120
}
121

122
impl VisitorVTable<ConstantVTable> for ConstantVTable {
123
    fn visit_buffers(array: &ConstantArray, visitor: &mut dyn ArrayBufferVisitor) {
8✔
124
        let buffer = array
8✔
125
            .scalar
8✔
126
            .value()
8✔
127
            .to_protobytes::<ByteBufferMut>()
8✔
128
            .freeze();
8✔
129
        visitor.visit_buffer(&buffer);
8✔
130
    }
8✔
131

132
    fn visit_children(_array: &ConstantArray, _visitor: &mut dyn ArrayChildVisitor) {}
8✔
133
}
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