Skip to content

Commit f353817

Browse files
authored
Port BinaryBooleanFn to BooleanKernel (#3147)
1 parent f3f663c commit f353817

File tree

10 files changed

+228
-178
lines changed

10 files changed

+228
-178
lines changed

encodings/fastlanes/benches/compute_between.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mod primitive {
6363
use vortex_array::arrays::ConstantArray;
6464
use vortex_array::compute::StrictComparison::NonStrict;
6565
use vortex_array::compute::{
66-
BetweenOptions, BinaryOperator, Operator, between, binary_boolean, compare,
66+
BetweenOptions, BooleanOperator, Operator, between, binary_boolean, compare,
6767
};
6868
use vortex_dtype::NativePType;
6969
use vortex_error::VortexExpect;
@@ -89,7 +89,7 @@ mod primitive {
8989
&compare(&arr, &ConstantArray::new(min, arr.len()), Operator::Gte)
9090
.vortex_expect(""),
9191
&compare(&arr, &ConstantArray::new(max, arr.len()), Operator::Lt).vortex_expect(""),
92-
BinaryOperator::And,
92+
BooleanOperator::And,
9393
)
9494
.vortex_expect("")
9595
})
@@ -132,7 +132,7 @@ mod bitpack {
132132
use vortex_array::arrays::ConstantArray;
133133
use vortex_array::compute::StrictComparison::NonStrict;
134134
use vortex_array::compute::{
135-
BetweenOptions, BinaryOperator, Operator, between, binary_boolean, compare,
135+
BetweenOptions, BooleanOperator, Operator, between, binary_boolean, compare,
136136
};
137137
use vortex_dtype::NativePType;
138138
use vortex_error::VortexExpect;
@@ -158,7 +158,7 @@ mod bitpack {
158158
&compare(&arr, &ConstantArray::new(min, arr.len()), Operator::Gte)
159159
.vortex_expect(""),
160160
&compare(&arr, &ConstantArray::new(max, arr.len()), Operator::Lt).vortex_expect(""),
161-
BinaryOperator::And,
161+
BooleanOperator::And,
162162
)
163163
})
164164
}
@@ -200,7 +200,7 @@ mod alp {
200200
use vortex_array::arrays::ConstantArray;
201201
use vortex_array::compute::StrictComparison::NonStrict;
202202
use vortex_array::compute::{
203-
BetweenOptions, BinaryOperator, Operator, between, binary_boolean, compare,
203+
BetweenOptions, BooleanOperator, Operator, between, binary_boolean, compare,
204204
};
205205
use vortex_dtype::NativePType;
206206
use vortex_error::VortexExpect;
@@ -226,7 +226,7 @@ mod alp {
226226
&compare(&arr, &ConstantArray::new(min, arr.len()), Operator::Gte)
227227
.vortex_expect(""),
228228
&compare(&arr, &ConstantArray::new(max, arr.len()), Operator::Lt).vortex_expect(""),
229-
BinaryOperator::And,
229+
BooleanOperator::And,
230230
)
231231
})
232232
}

vortex-array/src/arrays/bool/compute/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::Array;
22
use crate::arrays::BoolEncoding;
33
use crate::compute::{
4-
BinaryBooleanFn, CastFn, FillForwardFn, FillNullFn, InvertFn, IsConstantFn, IsSortedFn, MaskFn,
5-
MinMaxFn, ScalarAtFn, SliceFn, SumFn, TakeFn, ToArrowFn, UncompressedSizeFn,
4+
CastFn, FillForwardFn, FillNullFn, InvertFn, IsConstantFn, IsSortedFn, MaskFn, MinMaxFn,
5+
ScalarAtFn, SliceFn, SumFn, TakeFn, ToArrowFn, UncompressedSizeFn,
66
};
77
use crate::vtable::ComputeVTable;
88

@@ -24,14 +24,6 @@ mod to_arrow;
2424
mod uncompressed_size;
2525

2626
impl ComputeVTable for BoolEncoding {
27-
fn binary_boolean_fn(&self) -> Option<&dyn BinaryBooleanFn<&dyn Array>> {
28-
// We only implement this when other is a constant value, otherwise we fall back to the
29-
// default implementation that canonicalizes to Arrow.
30-
// TODO(ngates): implement this for constants.
31-
// other.is_constant().then_some(self)
32-
None
33-
}
34-
3527
fn cast_fn(&self) -> Option<&dyn CastFn<&dyn Array>> {
3628
Some(self)
3729
}

vortex-array/src/arrays/chunked/compute/boolean.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use vortex_dtype::DType;
22
use vortex_error::VortexResult;
33

44
use crate::arrays::{ChunkedArray, ChunkedEncoding};
5-
use crate::compute::{BinaryBooleanFn, BinaryOperator, binary_boolean, slice};
6-
use crate::{Array, ArrayRef};
5+
use crate::compute::{BooleanKernel, BooleanKernelAdapter, BooleanOperator, binary_boolean, slice};
6+
use crate::{Array, ArrayRef, register_kernel};
77

8-
impl BinaryBooleanFn<&ChunkedArray> for ChunkedEncoding {
8+
impl BooleanKernel for ChunkedEncoding {
99
fn binary_boolean(
1010
&self,
1111
lhs: &ChunkedArray,
1212
rhs: &dyn Array,
13-
op: BinaryOperator,
13+
op: BooleanOperator,
1414
) -> VortexResult<Option<ArrayRef>> {
1515
let mut idx = 0;
1616
let mut chunks = Vec::with_capacity(lhs.nchunks());
@@ -28,14 +28,16 @@ impl BinaryBooleanFn<&ChunkedArray> for ChunkedEncoding {
2828
}
2929
}
3030

31+
register_kernel!(BooleanKernelAdapter(ChunkedEncoding).lift());
32+
3133
#[cfg(test)]
3234
mod tests {
3335
use vortex_dtype::{DType, Nullability};
3436

3537
use crate::array::Array;
3638
use crate::arrays::{BoolArray, BooleanBuffer, ChunkedArray};
3739
use crate::canonical::ToCanonical;
38-
use crate::compute::{BinaryOperator, binary_boolean};
40+
use crate::compute::{BooleanOperator, binary_boolean};
3941

4042
#[test]
4143
fn test_bin_bool_chunked() {
@@ -49,7 +51,7 @@ mod tests {
4951
let chunked2 =
5052
ChunkedArray::try_new(vec![arr2, arr3], DType::Bool(Nullability::Nullable)).unwrap();
5153

52-
let result = binary_boolean(&chunked1, &chunked2, BinaryOperator::Or)
54+
let result = binary_boolean(&chunked1, &chunked2, BooleanOperator::Or)
5355
.unwrap()
5456
.to_bool()
5557
.unwrap();

vortex-array/src/arrays/chunked/compute/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use vortex_error::VortexResult;
44
use crate::arrays::ChunkedEncoding;
55
use crate::arrays::chunked::ChunkedArray;
66
use crate::compute::{
7-
BinaryBooleanFn, BinaryNumericFn, CastFn, FillNullFn, InvertFn, IsConstantFn, IsSortedFn,
8-
MaskFn, MinMaxFn, ScalarAtFn, SliceFn, SumFn, TakeFn, UncompressedSizeFn, try_cast,
7+
BinaryNumericFn, CastFn, FillNullFn, InvertFn, IsConstantFn, IsSortedFn, MaskFn, MinMaxFn,
8+
ScalarAtFn, SliceFn, SumFn, TakeFn, UncompressedSizeFn, try_cast,
99
};
1010
use crate::vtable::ComputeVTable;
1111
use crate::{Array, ArrayRef};
@@ -27,10 +27,6 @@ mod take;
2727
mod uncompressed_size;
2828

2929
impl ComputeVTable for ChunkedEncoding {
30-
fn binary_boolean_fn(&self) -> Option<&dyn BinaryBooleanFn<&dyn Array>> {
31-
Some(self)
32-
}
33-
3430
fn binary_numeric_fn(&self) -> Option<&dyn BinaryNumericFn<&dyn Array>> {
3531
Some(self)
3632
}

vortex-array/src/arrays/constant/compute/boolean.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use vortex_error::{VortexResult, vortex_bail, vortex_err};
33
use vortex_scalar::Scalar;
44

55
use crate::arrays::{ConstantArray, ConstantEncoding};
6-
use crate::compute::{BinaryBooleanFn, BinaryOperator};
7-
use crate::{Array, ArrayRef};
6+
use crate::compute::{BooleanKernel, BooleanKernelAdapter, BooleanOperator};
7+
use crate::{Array, ArrayRef, register_kernel};
88

9-
impl BinaryBooleanFn<&ConstantArray> for ConstantEncoding {
9+
impl BooleanKernel for ConstantEncoding {
1010
fn binary_boolean(
1111
&self,
1212
lhs: &ConstantArray,
1313
rhs: &dyn Array,
14-
op: BinaryOperator,
14+
op: BooleanOperator,
1515
) -> VortexResult<Option<ArrayRef>> {
1616
// We only implement this for constant <-> constant arrays, otherwise we allow fall back
1717
// to the Arrow implementation.
@@ -31,10 +31,10 @@ impl BinaryBooleanFn<&ConstantArray> for ConstantEncoding {
3131
.value();
3232

3333
let result = match op {
34-
BinaryOperator::And => and(lhs, rhs),
35-
BinaryOperator::AndKleene => kleene_and(lhs, rhs),
36-
BinaryOperator::Or => or(lhs, rhs),
37-
BinaryOperator::OrKleene => kleene_or(lhs, rhs),
34+
BooleanOperator::And => and(lhs, rhs),
35+
BooleanOperator::AndKleene => kleene_and(lhs, rhs),
36+
BooleanOperator::Or => or(lhs, rhs),
37+
BooleanOperator::OrKleene => kleene_or(lhs, rhs),
3838
};
3939

4040
let scalar = result
@@ -45,6 +45,8 @@ impl BinaryBooleanFn<&ConstantArray> for ConstantEncoding {
4545
}
4646
}
4747

48+
register_kernel!(BooleanKernelAdapter(ConstantEncoding).lift());
49+
4850
fn and(left: Option<bool>, right: Option<bool>) -> Option<bool> {
4951
left.zip(right).map(|(l, r)| l & r)
5052
}

vortex-array/src/arrays/constant/compute/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ use vortex_scalar::{FromPrimitiveOrF16, PrimitiveScalar, Scalar};
1515
use crate::arrays::ConstantEncoding;
1616
use crate::arrays::constant::ConstantArray;
1717
use crate::compute::{
18-
BinaryBooleanFn, BinaryNumericFn, CastFn, InvertFn, ScalarAtFn, SearchSortedFn, SliceFn, SumFn,
19-
TakeFn, UncompressedSizeFn,
18+
BinaryNumericFn, CastFn, InvertFn, ScalarAtFn, SearchSortedFn, SliceFn, SumFn, TakeFn,
19+
UncompressedSizeFn,
2020
};
2121
use crate::stats::Stat;
2222
use crate::vtable::ComputeVTable;
2323
use crate::{Array, ArrayRef};
2424

2525
impl ComputeVTable for ConstantEncoding {
26-
fn binary_boolean_fn(&self) -> Option<&dyn BinaryBooleanFn<&dyn Array>> {
27-
Some(self)
28-
}
29-
3026
fn binary_numeric_fn(&self) -> Option<&dyn BinaryNumericFn<&dyn Array>> {
3127
Some(self)
3228
}

vortex-array/src/compute/between.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use vortex_scalar::Scalar;
88
use crate::arcref::ArcRef;
99
use crate::arrays::ConstantArray;
1010
use crate::compute::{
11-
BinaryOperator, ComputeFn, ComputeFnVTable, InvocationArgs, Kernel, Operator, Options, Output,
11+
BooleanOperator, ComputeFn, ComputeFnVTable, InvocationArgs, Kernel, Operator, Options, Output,
1212
binary_boolean, compare,
1313
};
1414
use crate::{Array, ArrayRef, Canonical, Encoding, IntoArray};
@@ -19,7 +19,7 @@ use crate::{Array, ArrayRef, Canonical, Encoding, IntoArray};
1919
/// This semantics is equivalent to:
2020
/// ```
2121
/// use vortex_array::{Array, ArrayRef};
22-
/// use vortex_array::compute::{binary_boolean, compare, BetweenOptions, BinaryOperator, Operator};///
22+
/// use vortex_array::compute::{binary_boolean, compare, BetweenOptions, BooleanOperator, Operator};///
2323
/// use vortex_error::VortexResult;
2424
///
2525
/// fn between(
@@ -31,7 +31,7 @@ use crate::{Array, ArrayRef, Canonical, Encoding, IntoArray};
3131
/// binary_boolean(
3232
/// &compare(lower, arr, options.lower_strict.to_operator())?,
3333
/// &compare(arr, upper, options.upper_strict.to_operator())?,
34-
/// BinaryOperator::And
34+
/// BooleanOperator::And
3535
/// )
3636
/// }
3737
/// ```
@@ -142,7 +142,7 @@ impl ComputeFnVTable for Between {
142142
Ok(binary_boolean(
143143
&compare(lower, array, options.lower_strict.to_operator())?,
144144
&compare(array, upper, options.upper_strict.to_operator())?,
145-
BinaryOperator::And,
145+
BooleanOperator::And,
146146
)?
147147
.into())
148148
}

0 commit comments

Comments
 (0)