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

vortex-data / vortex / 16036348213

02 Jul 2025 09:38PM UTC coverage: 77.903% (+0.06%) from 77.845%
16036348213

push

github

web-flow
chore: update toolchain to nightly-2025-06-26 (#3742)

Signed-off-by: Daniel King <dan@spiraldb.com>

21 of 32 new or added lines in 8 files covered. (65.63%)

43280 of 55556 relevant lines covered (77.9%)

55774.65 hits per line

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

59.22
/vortex-array/src/variants.rs
1
//! This module defines extension functionality specific to each Vortex DType.
2
use std::cmp::Ordering;
3
use std::sync::Arc;
4

5
use vortex_dtype::{DType, ExtDType, FieldNames, PType};
6
use vortex_error::{VortexExpect, VortexResult, vortex_panic};
7
use vortex_scalar::PValue;
8

9
use crate::Array;
10
use crate::compute::sum;
11
use crate::search_sorted::IndexOrd;
12

13
impl dyn Array + '_ {
14
    /// Downcasts the array for null-specific behavior.
NEW
15
    pub fn as_null_typed(&self) -> NullTyped<'_> {
×
16
        matches!(self.dtype(), DType::Null)
×
17
            .then(|| NullTyped(self))
×
18
            .vortex_expect("Array does not have DType::Null")
×
19
    }
×
20

21
    /// Downcasts the array for bool-specific behavior.
22
    pub fn as_bool_typed(&self) -> BoolTyped<'_> {
1,480✔
23
        matches!(self.dtype(), DType::Bool(..))
1,480✔
24
            .then(|| BoolTyped(self))
1,480✔
25
            .vortex_expect("Array does not have DType::Bool")
1,480✔
26
    }
1,480✔
27

28
    /// Downcasts the array for primitive-specific behavior.
29
    pub fn as_primitive_typed(&self) -> PrimitiveTyped<'_> {
417,612✔
30
        matches!(self.dtype(), DType::Primitive(..))
417,612✔
31
            .then(|| PrimitiveTyped(self))
417,612✔
32
            .vortex_expect("Array does not have DType::Primitive")
417,612✔
33
    }
417,612✔
34

35
    /// Downcasts the array for decimal-specific behavior.
NEW
36
    pub fn as_decimal_typed(&self) -> DecimalTyped<'_> {
×
37
        matches!(self.dtype(), DType::Decimal(..))
×
38
            .then(|| DecimalTyped(self))
×
39
            .vortex_expect("Array does not have DType::Decimal")
×
40
    }
×
41

42
    /// Downcasts the array for utf8-specific behavior.
NEW
43
    pub fn as_utf8_typed(&self) -> Utf8Typed<'_> {
×
44
        matches!(self.dtype(), DType::Utf8(..))
×
45
            .then(|| Utf8Typed(self))
×
46
            .vortex_expect("Array does not have DType::Utf8")
×
47
    }
×
48

49
    /// Downcasts the array for binary-specific behavior.
NEW
50
    pub fn as_binary_typed(&self) -> BinaryTyped<'_> {
×
51
        matches!(self.dtype(), DType::Binary(..))
×
52
            .then(|| BinaryTyped(self))
×
53
            .vortex_expect("Array does not have DType::Binary")
×
54
    }
×
55

56
    /// Downcasts the array for struct-specific behavior.
57
    pub fn as_struct_typed(&self) -> StructTyped<'_> {
74✔
58
        matches!(self.dtype(), DType::Struct(..))
74✔
59
            .then(|| StructTyped(self))
74✔
60
            .vortex_expect("Array does not have DType::Struct")
74✔
61
    }
74✔
62

63
    /// Downcasts the array for list-specific behavior.
NEW
64
    pub fn as_list_typed(&self) -> ListTyped<'_> {
×
65
        matches!(self.dtype(), DType::List(..))
×
66
            .then(|| ListTyped(self))
×
67
            .vortex_expect("Array does not have DType::List")
×
68
    }
×
69

70
    /// Downcasts the array for extension-specific behavior.
NEW
71
    pub fn as_extension_typed(&self) -> ExtensionTyped<'_> {
×
72
        matches!(self.dtype(), DType::Extension(..))
×
73
            .then(|| ExtensionTyped(self))
×
74
            .vortex_expect("Array does not have DType::Extension")
×
75
    }
×
76
}
77

78
#[allow(dead_code)]
79
pub struct NullTyped<'a>(&'a dyn Array);
80

81
pub struct BoolTyped<'a>(&'a dyn Array);
82

83
impl BoolTyped<'_> {
84
    pub fn true_count(&self) -> VortexResult<usize> {
1,480✔
85
        let true_count = sum(self.0)?;
1,480✔
86
        Ok(true_count
1,480✔
87
            .as_primitive()
1,480✔
88
            .as_::<usize>()
1,480✔
89
            .vortex_expect("true count should never overflow usize")
1,480✔
90
            .vortex_expect("true count should never be null"))
1,480✔
91
    }
1,480✔
92
}
93

94
pub struct PrimitiveTyped<'a>(&'a dyn Array);
95

96
impl PrimitiveTyped<'_> {
97
    pub fn ptype(&self) -> PType {
259✔
98
        let DType::Primitive(ptype, _) = self.0.dtype() else {
259✔
99
            vortex_panic!("Expected Primitive DType")
×
100
        };
101
        *ptype
259✔
102
    }
259✔
103

104
    /// Return the primitive value at the given index.
105
    pub fn value(&self, idx: usize) -> Option<PValue> {
381✔
106
        self.0
381✔
107
            .is_valid(idx)
381✔
108
            .vortex_expect("is valid")
381✔
109
            .then(|| self.value_unchecked(idx))
381✔
110
    }
381✔
111

112
    /// Return the primitive value at the given index, ignoring nullability.
113
    pub fn value_unchecked(&self, idx: usize) -> PValue {
3,108,630✔
114
        self.0
3,108,630✔
115
            .scalar_at(idx)
3,108,630✔
116
            .vortex_expect("scalar at index")
3,108,630✔
117
            .as_primitive()
3,108,630✔
118
            .pvalue()
3,108,630✔
119
            .unwrap_or_else(|| PValue::zero(self.ptype()))
3,108,630✔
120
    }
3,108,630✔
121
}
122

123
impl IndexOrd<Option<PValue>> for PrimitiveTyped<'_> {
124
    fn index_cmp(&self, idx: usize, elem: &Option<PValue>) -> Option<Ordering> {
381✔
125
        self.value(idx).partial_cmp(elem)
381✔
126
    }
381✔
127

128
    fn index_len(&self) -> usize {
68✔
129
        self.0.len()
68✔
130
    }
68✔
131
}
132

133
// TODO(ngates): add generics to the `value` function and implement this over T.
134
impl IndexOrd<PValue> for PrimitiveTyped<'_> {
135
    fn index_cmp(&self, idx: usize, elem: &PValue) -> Option<Ordering> {
3,108,285✔
136
        assert!(self.0.all_valid().vortex_expect("all valid"));
3,108,285✔
137
        self.value_unchecked(idx).partial_cmp(elem)
3,108,285✔
138
    }
3,108,285✔
139

140
    fn index_len(&self) -> usize {
422,807✔
141
        self.0.len()
422,807✔
142
    }
422,807✔
143
}
144

145
#[allow(dead_code)]
146
pub struct Utf8Typed<'a>(&'a dyn Array);
147

148
#[allow(dead_code)]
149
pub struct BinaryTyped<'a>(&'a dyn Array);
150

151
#[allow(dead_code)]
152
pub struct DecimalTyped<'a>(&'a dyn Array);
153

154
pub struct StructTyped<'a>(&'a dyn Array);
155

156
impl StructTyped<'_> {
157
    pub fn names(&self) -> &FieldNames {
74✔
158
        let DType::Struct(st, _) = self.0.dtype() else {
74✔
159
            unreachable!()
×
160
        };
161
        st.names()
74✔
162
    }
74✔
163

164
    pub fn dtypes(&self) -> Vec<DType> {
×
165
        let DType::Struct(st, _) = self.0.dtype() else {
×
166
            unreachable!()
×
167
        };
168
        st.fields().collect()
×
169
    }
×
170

171
    pub fn nfields(&self) -> usize {
37✔
172
        self.names().len()
37✔
173
    }
37✔
174
}
175

176
#[allow(dead_code)]
177
pub struct ListTyped<'a>(&'a dyn Array);
178

179
pub struct ExtensionTyped<'a>(&'a dyn Array);
180

181
impl ExtensionTyped<'_> {
182
    /// Returns the extension logical [`DType`].
183
    pub fn ext_dtype(&self) -> &Arc<ExtDType> {
×
184
        let DType::Extension(ext_dtype) = self.0.dtype() else {
×
185
            vortex_panic!("Expected ExtDType")
×
186
        };
187
        ext_dtype
×
188
    }
×
189
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc