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

vortex-data / vortex / 16992684502

15 Aug 2025 02:56PM UTC coverage: 87.875% (+0.2%) from 87.72%
16992684502

Pull #2456

github

web-flow
Merge 2d540e578 into 4a23f65b3
Pull Request #2456: feat: basic BoolBuffer / BoolBufferMut

1275 of 1428 new or added lines in 110 files covered. (89.29%)

334 existing lines in 31 files now uncovered.

57169 of 65057 relevant lines covered (87.88%)

658056.52 hits per line

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

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

4
use std::any::Any;
5
use std::mem;
6

7
use vortex_buffer::BitBufferMut;
8
use vortex_dtype::{DType, Nullability};
9
use vortex_error::{VortexResult, vortex_bail};
10
use vortex_mask::Mask;
11

12
use crate::arrays::BoolArray;
13
use crate::builders::ArrayBuilder;
14
use crate::builders::lazy_validity_builder::LazyBitBufferBuilder;
15
use crate::{Array, ArrayRef, Canonical, IntoArray};
16

17
pub struct BoolBuilder {
18
    inner: BitBufferMut,
19
    nulls: LazyBitBufferBuilder,
20
    nullability: Nullability,
21
    dtype: DType,
22
}
23

24
impl BoolBuilder {
25
    pub fn new(nullability: Nullability) -> Self {
×
26
        Self::with_capacity(nullability, 1024) // Same as Arrow builders
×
27
    }
×
28

29
    pub fn with_capacity(nullability: Nullability, capacity: usize) -> Self {
5,888✔
30
        Self {
5,888✔
31
            inner: BitBufferMut::new(capacity),
5,888✔
32
            nulls: LazyBitBufferBuilder::new(capacity),
5,888✔
33
            nullability,
5,888✔
34
            dtype: DType::Bool(nullability),
5,888✔
35
        }
5,888✔
36
    }
5,888✔
37

38
    pub fn append_value(&mut self, value: bool) {
7,368✔
39
        self.append_values(value, 1)
7,368✔
40
    }
7,368✔
41

42
    pub fn append_values(&mut self, value: bool, n: usize) {
7,368✔
43
        self.inner.append_n(value, n);
7,368✔
44
        self.nulls.append_n_non_nulls(n)
7,368✔
45
    }
7,368✔
46

47
    pub fn append_option(&mut self, value: Option<bool>) {
312✔
48
        match value {
312✔
49
            Some(value) => self.append_value(value),
312✔
50
            None => self.append_null(),
×
51
        }
52
    }
312✔
53
}
54

55
impl ArrayBuilder for BoolBuilder {
56
    fn as_any(&self) -> &dyn Any {
×
57
        self
×
58
    }
×
59

60
    fn as_any_mut(&mut self) -> &mut dyn Any {
312✔
61
        self
312✔
62
    }
312✔
63

64
    fn dtype(&self) -> &DType {
338✔
65
        &self.dtype
338✔
66
    }
338✔
67

68
    fn len(&self) -> usize {
52✔
69
        self.inner.len()
52✔
70
    }
52✔
71

72
    fn append_zeros(&mut self, n: usize) {
×
73
        self.append_values(false, n)
×
74
    }
×
75

76
    fn append_nulls(&mut self, n: usize) {
×
NEW
77
        self.inner.append_n(false, n);
×
78
        self.nulls.append_n_nulls(n)
×
79
    }
×
80

81
    fn extend_from_array(&mut self, array: &dyn Array) -> VortexResult<()> {
303✔
82
        let array = array.to_canonical()?;
303✔
83
        let Canonical::Bool(array) = array else {
303✔
84
            vortex_bail!("Expected Canonical::Bool, found {:?}", array);
×
85
        };
86

87
        self.inner.append_buffer(array.bit_buffer());
303✔
88
        self.nulls.append_validity_mask(array.validity_mask()?);
303✔
89

90
        Ok(())
303✔
91
    }
303✔
92

93
    fn ensure_capacity(&mut self, capacity: usize) {
×
94
        if capacity > self.inner.capacity() {
×
95
            self.nulls.ensure_capacity(capacity);
×
96
            self.inner.reserve(capacity - self.inner.capacity());
×
97
        }
×
98
    }
×
99

100
    fn set_validity(&mut self, validity: Mask) {
91✔
101
        self.nulls = LazyBitBufferBuilder::new(validity.len());
91✔
102
        self.nulls.append_validity_mask(validity);
91✔
103
    }
91✔
104

105
    fn finish(&mut self) -> ArrayRef {
5,888✔
106
        assert_eq!(
5,888✔
107
            self.nulls.len(),
5,888✔
108
            self.inner.len(),
5,888✔
109
            "Null count and value count should match when calling BoolBuilder::finish."
×
110
        );
111

112
        BoolArray::new(
5,888✔
113
            mem::take(&mut self.inner).freeze(),
5,888✔
114
            self.nulls.finish_with_nullability(self.nullability),
5,888✔
115
        )
5,888✔
116
        .into_array()
5,888✔
117
    }
5,888✔
118
}
119

120
#[cfg(test)]
121
mod tests {
122
    use rand::prelude::StdRng;
123
    use rand::{Rng, SeedableRng};
124

125
    use crate::array::Array;
126
    use crate::arrays::{BoolArray, ChunkedArray};
127
    use crate::builders::builder_with_capacity;
128
    use crate::canonical::ToCanonical;
129
    use crate::vtable::ValidityHelper;
130
    use crate::{ArrayRef, IntoArray};
131
    fn make_opt_bool_chunks(len: usize, chunk_count: usize) -> ArrayRef {
1✔
132
        let mut rng = StdRng::seed_from_u64(0);
1✔
133

134
        (0..chunk_count)
1✔
135
            .map(|_| {
10✔
136
                BoolArray::from_iter((0..len).map(|_| match rng.random_range::<u8, _>(0..=2) {
10,000✔
137
                    0 => Some(false),
3,350✔
138
                    1 => Some(true),
3,355✔
139
                    2 => None,
3,295✔
140
                    _ => unreachable!(),
141
                }))
10,000✔
142
                .into_array()
10✔
143
            })
10✔
144
            .collect::<ChunkedArray>()
1✔
145
            .into_array()
1✔
146
    }
1✔
147

148
    #[test]
149
    fn tests() {
1✔
150
        let len = 1000;
1✔
151
        let chunk_count = 10;
1✔
152
        let chunk = make_opt_bool_chunks(len, chunk_count);
1✔
153

154
        let mut builder = builder_with_capacity(chunk.dtype(), len * chunk_count);
1✔
155
        chunk.clone().append_to_builder(builder.as_mut()).unwrap();
1✔
156
        let canon_into = builder
1✔
157
            .finish()
1✔
158
            .to_canonical()
1✔
159
            .unwrap()
1✔
160
            .into_bool()
1✔
161
            .unwrap();
1✔
162

163
        let into_canon = chunk.to_bool().unwrap();
1✔
164

165
        assert_eq!(canon_into.validity(), into_canon.validity());
1✔
166
        assert_eq!(canon_into.bit_buffer(), into_canon.bit_buffer());
1✔
167
    }
1✔
168
}
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