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

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

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

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

UNCOV
47
        Ok(Some(ConstantArray::new(scalar, length).into_array()))
×
UNCOV
48
    }
×
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

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

UNCOV
71
fn kleene_or(left: Option<bool>, right: Option<bool>) -> Option<bool> {
×
UNCOV
72
    match (left, right) {
×
73
        (Some(true), _) => Some(true),
×
74
        (_, Some(true)) => Some(true),
×
75
        (None, _) => None,
×
76
        (_, None) => None,
×
UNCOV
77
        (Some(l), Some(r)) => Some(l | r),
×
78
    }
UNCOV
79
}
×
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 · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc