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

vortex-data / vortex / 16728097825

04 Aug 2025 04:00PM UTC coverage: 48.355% (-35.1%) from 83.429%
16728097825

Pull #4108

github

web-flow
Merge 1b2d27fd8 into 649ba9576
Pull Request #4108: perf[vortex-array]: use all_valid instead of `invalid_count() == 0`

1 of 1 new or added line in 1 file covered. (100.0%)

11596 existing lines in 378 files now uncovered.

18635 of 38538 relevant lines covered (48.35%)

151786.4 hits per line

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

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

4
use vortex_dtype::DType;
5
use vortex_error::{VortexResult, vortex_bail, vortex_err};
6
use vortex_scalar::Scalar;
7

8
use crate::arrays::{ConstantArray, ConstantVTable};
9
use crate::compute::{BooleanKernel, BooleanKernelAdapter, BooleanOperator};
10
use crate::{Array, ArrayRef, IntoArray, register_kernel};
11

12
impl BooleanKernel for ConstantVTable {
13
    fn boolean(
1,638✔
14
        &self,
1,638✔
15
        lhs: &ConstantArray,
1,638✔
16
        rhs: &dyn Array,
1,638✔
17
        op: BooleanOperator,
1,638✔
18
    ) -> VortexResult<Option<ArrayRef>> {
1,638✔
19
        // We only implement this for constant <-> constant arrays, otherwise we allow fall back
20
        // to the Arrow implementation.
21
        if !rhs.is_constant() {
1,638✔
22
            return Ok(None);
×
23
        }
1,638✔
24

25
        let length = lhs.len();
1,638✔
26
        let nullable = lhs.dtype().is_nullable() || rhs.dtype().is_nullable();
1,638✔
27
        let lhs = lhs.scalar().as_bool().value();
1,638✔
28
        let Some(rhs) = rhs.as_constant() else {
1,638✔
29
            vortex_bail!("Binary boolean operation requires both sides to be constant");
×
30
        };
31
        let rhs = rhs
1,638✔
32
            .as_bool_opt()
1,638✔
33
            .ok_or_else(|| vortex_err!("expected rhs to be boolean"))?
1,638✔
34
            .value();
1,638✔
35

36
        let result = match op {
1,638✔
UNCOV
37
            BooleanOperator::And => and(lhs, rhs),
×
38
            BooleanOperator::AndKleene => kleene_and(lhs, rhs),
642✔
UNCOV
39
            BooleanOperator::Or => or(lhs, rhs),
×
40
            BooleanOperator::OrKleene => kleene_or(lhs, rhs),
996✔
41
        };
42

43
        let scalar = result
1,638✔
44
            .map(|b| Scalar::bool(b, nullable.into()))
1,638✔
45
            .unwrap_or_else(|| Scalar::null(DType::Bool(nullable.into())));
1,638✔
46

47
        Ok(Some(ConstantArray::new(scalar, length).into_array()))
1,638✔
48
    }
1,638✔
49
}
50

51
register_kernel!(BooleanKernelAdapter(ConstantVTable).lift());
52

UNCOV
53
fn and(left: Option<bool>, right: Option<bool>) -> Option<bool> {
×
UNCOV
54
    left.zip(right).map(|(l, r)| l & r)
×
UNCOV
55
}
×
56

57
fn kleene_and(left: Option<bool>, right: Option<bool>) -> Option<bool> {
642✔
58
    match (left, right) {
642✔
59
        (Some(false), _) => Some(false),
642✔
UNCOV
60
        (_, Some(false)) => Some(false),
×
61
        (None, _) => None,
×
62
        (_, None) => None,
×
UNCOV
63
        (Some(l), Some(r)) => Some(l & r),
×
64
    }
65
}
642✔
66

UNCOV
67
fn or(left: Option<bool>, right: Option<bool>) -> Option<bool> {
×
UNCOV
68
    left.zip(right).map(|(l, r)| l | r)
×
UNCOV
69
}
×
70

71
fn kleene_or(left: Option<bool>, right: Option<bool>) -> Option<bool> {
996✔
72
    match (left, right) {
996✔
73
        (Some(true), _) => Some(true),
×
74
        (_, Some(true)) => Some(true),
×
75
        (None, _) => None,
×
76
        (_, None) => None,
×
77
        (Some(l), Some(r)) => Some(l | r),
996✔
78
    }
79
}
996✔
80

81
#[cfg(test)]
82
mod test {
83
    use rstest::rstest;
84

85
    use crate::arrays::BoolArray;
86
    use crate::arrays::constant::ConstantArray;
87
    use crate::canonical::ToCanonical;
88
    use crate::compute::{and, or};
89
    use crate::{Array, ArrayRef, IntoArray};
90

91
    #[rstest]
92
    #[case(ConstantArray::new(true, 4).into_array(), BoolArray::from_iter([Some(true), Some(false), Some(true), Some(false)].into_iter()).into_array()
93
    )]
94
    #[case(BoolArray::from_iter([Some(true), Some(false), Some(true), Some(false)].into_iter()).into_array(), ConstantArray::new(true, 4).into_array()
95
    )]
96
    fn test_or(#[case] lhs: ArrayRef, #[case] rhs: ArrayRef) {
97
        let r = or(&lhs, &rhs).unwrap().to_bool().unwrap().into_array();
98

99
        let v0 = r.scalar_at(0).unwrap().as_bool().value();
100
        let v1 = r.scalar_at(1).unwrap().as_bool().value();
101
        let v2 = r.scalar_at(2).unwrap().as_bool().value();
102
        let v3 = r.scalar_at(3).unwrap().as_bool().value();
103

104
        assert!(v0.unwrap());
105
        assert!(v1.unwrap());
106
        assert!(v2.unwrap());
107
        assert!(v3.unwrap());
108
    }
109

110
    #[rstest]
111
    #[case(ConstantArray::new(true, 4).into_array(), BoolArray::from_iter([Some(true), Some(false), Some(true), Some(false)].into_iter()).into_array()
112
    )]
113
    #[case(BoolArray::from_iter([Some(true), Some(false), Some(true), Some(false)].into_iter()).into_array(),
114
        ConstantArray::new(true, 4).into_array())]
115
    fn test_and(#[case] lhs: ArrayRef, #[case] rhs: ArrayRef) {
116
        let r = and(&lhs, &rhs).unwrap().to_bool().unwrap().into_array();
117

118
        let v0 = r.scalar_at(0).unwrap().as_bool().value();
119
        let v1 = r.scalar_at(1).unwrap().as_bool().value();
120
        let v2 = r.scalar_at(2).unwrap().as_bool().value();
121
        let v3 = r.scalar_at(3).unwrap().as_bool().value();
122

123
        assert!(v0.unwrap());
124
        assert!(!v1.unwrap());
125
        assert!(v2.unwrap());
126
        assert!(!v3.unwrap());
127
    }
128
}
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