• 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

48.42
/vortex-expr/src/exprs/operators.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use core::fmt;
5
use std::fmt::{Display, Formatter};
6

7
use vortex_array::compute;
8
use vortex_error::VortexError;
9
use vortex_proto::expr::binary_opts::BinaryOp;
10

11
/// Equalities, inequalities, and boolean operations over possibly null values.
12
///
13
/// For the equalities and inequalities, if either side is null, the result is null. The Boolean
14
/// operators obey [Kleene (three-valued) logic](https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics).
15
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
16
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17
pub enum Operator {
18
    // comparison
19
    Eq,
20
    NotEq,
21
    Gt,
22
    Gte,
23
    Lt,
24
    Lte,
25
    // boolean algebra
26
    And,
27
    Or,
28
    // arithmetic
29
    /// The sum of the arguments.
30
    ///
31
    /// Errs at runtime if the sum would overflow or underflow.
32
    ///
33
    /// The result is null at any index that either input is null.
34
    Add,
35
    /// The difference between the arguments.
36
    ///
37
    /// Errs at runtime if the sum would overflow or underflow.
38
    ///
39
    /// The result is null at any index that either input is null.
40
    Sub,
41
}
42

43
impl From<Operator> for i32 {
44
    fn from(value: Operator) -> Self {
20✔
45
        let op: BinaryOp = value.into();
20✔
46
        op.into()
20✔
47
    }
20✔
48
}
49

50
impl From<Operator> for BinaryOp {
51
    fn from(value: Operator) -> Self {
20✔
52
        match value {
20✔
53
            Operator::Eq => BinaryOp::Eq,
4✔
54
            Operator::NotEq => BinaryOp::NotEq,
1✔
55
            Operator::Gt => BinaryOp::Gt,
3✔
56
            Operator::Gte => BinaryOp::Gte,
1✔
57
            Operator::Lt => BinaryOp::Lt,
2✔
58
            Operator::Lte => BinaryOp::Lte,
1✔
59
            Operator::And => BinaryOp::And,
4✔
60
            Operator::Or => BinaryOp::Or,
3✔
61
            Operator::Add => BinaryOp::Add,
1✔
UNCOV
62
            Operator::Sub => BinaryOp::Sub,
×
63
        }
64
    }
20✔
65
}
66

67
impl TryFrom<i32> for Operator {
68
    type Error = VortexError;
69

UNCOV
70
    fn try_from(value: i32) -> Result<Self, Self::Error> {
×
UNCOV
71
        Ok(BinaryOp::try_from(value)?.into())
×
UNCOV
72
    }
×
73
}
74

75
impl From<BinaryOp> for Operator {
76
    fn from(value: BinaryOp) -> Self {
20✔
77
        match value {
20✔
78
            BinaryOp::Eq => Operator::Eq,
4✔
79
            BinaryOp::NotEq => Operator::NotEq,
1✔
80
            BinaryOp::Gt => Operator::Gt,
3✔
81
            BinaryOp::Gte => Operator::Gte,
1✔
82
            BinaryOp::Lt => Operator::Lt,
2✔
83
            BinaryOp::Lte => Operator::Lte,
1✔
84
            BinaryOp::And => Operator::And,
4✔
85
            BinaryOp::Or => Operator::Or,
3✔
86
            BinaryOp::Add => Operator::Add,
1✔
UNCOV
87
            BinaryOp::Sub => Operator::Sub,
×
88
        }
89
    }
20✔
90
}
91

92
impl Display for Operator {
93
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
17✔
94
        let display = match &self {
17✔
95
            Operator::Eq => "=",
1✔
96
            Operator::NotEq => "!=",
2✔
97
            Operator::Gt => ">",
1✔
98
            Operator::Gte => ">=",
3✔
99
            Operator::Lt => "<",
2✔
100
            Operator::Lte => "<=",
3✔
101
            Operator::And => "and",
3✔
102
            Operator::Or => "or",
2✔
103
            Operator::Add => "+",
×
104
            Operator::Sub => "-",
×
105
        };
106
        Display::fmt(display, f)
17✔
107
    }
17✔
108
}
109

110
impl Operator {
UNCOV
111
    pub fn inverse(self) -> Option<Self> {
×
112
        match self {
×
UNCOV
113
            Operator::Eq => Some(Operator::NotEq),
×
114
            Operator::NotEq => Some(Operator::Eq),
×
115
            Operator::Gt => Some(Operator::Lte),
×
116
            Operator::Gte => Some(Operator::Lt),
×
117
            Operator::Lt => Some(Operator::Gte),
×
118
            Operator::Lte => Some(Operator::Gt),
×
UNCOV
119
            Operator::And | Operator::Or | Operator::Add | Operator::Sub => None,
×
120
        }
UNCOV
121
    }
×
122

UNCOV
123
    pub fn logical_inverse(self) -> Option<Self> {
×
UNCOV
124
        match self {
×
125
            Operator::And => Some(Operator::Or),
×
126
            Operator::Or => Some(Operator::And),
×
UNCOV
127
            _ => None,
×
128
        }
UNCOV
129
    }
×
130

131
    /// Change the sides of the operator, where changing lhs and rhs won't change the result of the operation
132
    pub fn swap(self) -> Self {
508✔
133
        match self {
508✔
UNCOV
134
            Operator::Eq => Operator::Eq,
×
UNCOV
135
            Operator::NotEq => Operator::NotEq,
×
136
            Operator::Gt => Operator::Lt,
72✔
137
            Operator::Gte => Operator::Lte,
361✔
138
            Operator::Lt => Operator::Gt,
75✔
139
            Operator::Lte => Operator::Gte,
×
140
            Operator::And => Operator::And,
×
141
            Operator::Or => Operator::Or,
×
142
            Operator::Add => Operator::Add,
×
143
            Operator::Sub => Operator::Sub,
×
144
        }
145
    }
508✔
146

147
    pub fn maybe_cmp_operator(self) -> Option<compute::Operator> {
×
UNCOV
148
        match self {
×
UNCOV
149
            Operator::Eq => Some(compute::Operator::Eq),
×
UNCOV
150
            Operator::NotEq => Some(compute::Operator::NotEq),
×
151
            Operator::Lt => Some(compute::Operator::Lt),
×
152
            Operator::Lte => Some(compute::Operator::Lte),
×
153
            Operator::Gt => Some(compute::Operator::Gt),
×
154
            Operator::Gte => Some(compute::Operator::Gte),
×
155
            _ => None,
×
156
        }
157
    }
×
158
}
159

160
impl From<compute::Operator> for Operator {
UNCOV
161
    fn from(cmp_operator: compute::Operator) -> Self {
×
UNCOV
162
        match cmp_operator {
×
UNCOV
163
            compute::Operator::Eq => Operator::Eq,
×
UNCOV
164
            compute::Operator::NotEq => Operator::NotEq,
×
UNCOV
165
            compute::Operator::Gt => Operator::Gt,
×
UNCOV
166
            compute::Operator::Gte => Operator::Gte,
×
UNCOV
167
            compute::Operator::Lt => Operator::Lt,
×
UNCOV
168
            compute::Operator::Lte => Operator::Lte,
×
169
        }
UNCOV
170
    }
×
171
}
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

© 2025 Coveralls, Inc