Skip to content

Commit 442d6df

Browse files
authored
Add pruning support to between exprs (#2596)
1 parent c88e532 commit 442d6df

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

vortex-expr/src/between.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use vortex_dtype::DType;
88
use vortex_dtype::DType::Bool;
99
use vortex_error::VortexResult;
1010

11-
use crate::{ExprRef, VortexExpr};
11+
use crate::{BinaryExpr, ExprRef, VortexExpr};
1212

1313
#[derive(Debug, Eq, Hash)]
1414
#[allow(clippy::derived_hash_with_manual_eq)]
@@ -33,6 +33,20 @@ impl Between {
3333
options,
3434
})
3535
}
36+
37+
pub fn to_binary_expr(&self) -> ExprRef {
38+
let lhs = BinaryExpr::new_expr(
39+
self.lower.clone(),
40+
self.options.lower_strict.to_operator().into(),
41+
self.arr.clone(),
42+
);
43+
let rhs = BinaryExpr::new_expr(
44+
self.arr.clone(),
45+
self.options.upper_strict.to_operator().into(),
46+
self.upper.clone(),
47+
);
48+
BinaryExpr::new_expr(lhs, crate::Operator::And, rhs)
49+
}
3650
}
3751

3852
impl Display for Between {

vortex-expr/src/operators.rs

+13
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@ impl Operator {
7373
}
7474
}
7575
}
76+
77+
impl From<compute::Operator> for Operator {
78+
fn from(cmp_operator: compute::Operator) -> Self {
79+
match cmp_operator {
80+
compute::Operator::Eq => Operator::Eq,
81+
compute::Operator::NotEq => Operator::NotEq,
82+
compute::Operator::Gt => Operator::Gt,
83+
compute::Operator::Gte => Operator::Gte,
84+
compute::Operator::Lt => Operator::Lt,
85+
compute::Operator::Lte => Operator::Lte,
86+
}
87+
}
88+
}

vortex-expr/src/pruning.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use vortex_dtype::{FieldName, Nullability};
1313
use vortex_error::{VortexExpect as _, VortexResult};
1414
use vortex_scalar::Scalar;
1515

16+
use crate::between::Between;
1617
use crate::{
1718
BinaryExpr, ExprRef, GetItem, Identity, Literal, Not, Operator, VortexExprExt, and, eq,
1819
get_item, gt, ident, lit, not, or,
@@ -226,6 +227,10 @@ fn convert_to_pruning_expression(expr: &ExprRef) -> PruningPredicateStats {
226227
};
227228
}
228229

230+
if let Some(between_expr) = expr.as_any().downcast_ref::<Between>() {
231+
return convert_to_pruning_expression(&between_expr.to_binary_expr());
232+
}
233+
229234
not_prunable()
230235
}
231236

0 commit comments

Comments
 (0)