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

vortex-data / vortex / 16935267080

13 Aug 2025 11:00AM UTC coverage: 24.312% (-63.3%) from 87.658%
16935267080

Pull #4226

github

web-flow
Merge 81b48c7fb into baa6ea202
Pull Request #4226: Support converting TimestampTZ to and from duckdb

0 of 2 new or added lines in 1 file covered. (0.0%)

20666 existing lines in 469 files now uncovered.

8726 of 35892 relevant lines covered (24.31%)

147.74 hits per line

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

0.0
/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

6
use arrow_buffer::BooleanBufferBuilder;
7
use vortex_dtype::{DType, Nullability};
8
use vortex_error::{VortexResult, vortex_bail};
9
use vortex_mask::Mask;
10

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

16
pub struct BoolBuilder {
17
    inner: BooleanBufferBuilder,
18
    nulls: LazyNullBufferBuilder,
19
    nullability: Nullability,
20
    dtype: DType,
21
}
22

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

UNCOV
28
    pub fn with_capacity(nullability: Nullability, capacity: usize) -> Self {
×
UNCOV
29
        Self {
×
UNCOV
30
            inner: BooleanBufferBuilder::new(capacity),
×
UNCOV
31
            nulls: LazyNullBufferBuilder::new(capacity),
×
UNCOV
32
            nullability,
×
UNCOV
33
            dtype: DType::Bool(nullability),
×
UNCOV
34
        }
×
UNCOV
35
    }
×
36

UNCOV
37
    pub fn append_value(&mut self, value: bool) {
×
UNCOV
38
        self.append_values(value, 1)
×
UNCOV
39
    }
×
40

UNCOV
41
    pub fn append_values(&mut self, value: bool, n: usize) {
×
UNCOV
42
        self.inner.append_n(n, value);
×
UNCOV
43
        self.nulls.append_n_non_nulls(n)
×
UNCOV
44
    }
×
45

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

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

UNCOV
59
    fn as_any_mut(&mut self) -> &mut dyn Any {
×
UNCOV
60
        self
×
UNCOV
61
    }
×
62

UNCOV
63
    fn dtype(&self) -> &DType {
×
UNCOV
64
        &self.dtype
×
UNCOV
65
    }
×
66

UNCOV
67
    fn len(&self) -> usize {
×
UNCOV
68
        self.inner.len()
×
UNCOV
69
    }
×
70

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

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

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

UNCOV
86
        self.inner.append_buffer(array.boolean_buffer());
×
UNCOV
87
        self.nulls.append_validity_mask(array.validity_mask()?);
×
88

UNCOV
89
        Ok(())
×
UNCOV
90
    }
×
91

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

UNCOV
99
    fn set_validity(&mut self, validity: Mask) {
×
UNCOV
100
        self.nulls = LazyNullBufferBuilder::new(validity.len());
×
UNCOV
101
        self.nulls.append_validity_mask(validity);
×
UNCOV
102
    }
×
103

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

UNCOV
111
        BoolArray::new(
×
UNCOV
112
            self.inner.finish(),
×
UNCOV
113
            self.nulls.finish_with_nullability(self.nullability),
×
UNCOV
114
        )
×
UNCOV
115
        .into_array()
×
UNCOV
116
    }
×
117
}
118

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

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

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

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

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

162
        let into_canon = chunk.to_bool().unwrap();
163

164
        assert_eq!(canon_into.validity(), into_canon.validity());
165
        assert_eq!(canon_into.boolean_buffer(), into_canon.boolean_buffer());
166
    }
167
}
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