Skip to content

Commit 78b7915

Browse files
authored
fix[vortex-expr]: implement stat_falsification for BetweenExpr (#4977)
This would otherwise cause chunks to not be pruned when they could be with range filters. Signed-off-by: Alfonso Subiotto Marques <[email protected]>
1 parent 3e7f585 commit 78b7915

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

vortex-expr/src/exprs/between.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use vortex_proto::expr as pb;
2222

2323
use crate::display::{DisplayAs, DisplayFormat};
2424
use crate::{
25-
AnalysisExpr, BinaryExpr, ExprEncodingRef, ExprId, ExprRef, IntoExpr, Scope, VTable, vtable,
25+
AnalysisExpr, BinaryExpr, ExprEncodingRef, ExprId, ExprRef, IntoExpr, Scope, StatsCatalog,
26+
VTable, vtable,
2627
};
2728

2829
vtable!(Between);
@@ -219,7 +220,11 @@ impl DisplayAs for BetweenExpr {
219220
}
220221
}
221222

222-
impl AnalysisExpr for BetweenExpr {}
223+
impl AnalysisExpr for BetweenExpr {
224+
fn stat_falsification(&self, catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
225+
self.to_binary_expr().stat_falsification(catalog)
226+
}
227+
}
223228

224229
/// Creates an expression that checks if values are between two bounds.
225230
///

vortex-expr/src/pruning/pruning_expr.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ pub fn checked_pruning_expr(
102102
#[cfg(test)]
103103
mod tests {
104104
use rstest::{fixture, rstest};
105+
use vortex_array::compute::{BetweenOptions, StrictComparison};
105106
use vortex_array::stats::Stat;
106107
use vortex_dtype::{FieldName, FieldPath, FieldPathSet};
107108

108109
use crate::pruning::pruning_expr::HashMap;
109110
use crate::pruning::{checked_pruning_expr, field_path_stat_field_name};
110-
use crate::{HashSet, and, col, eq, get_item, gt, gt_eq, lit, lt, lt_eq, not_eq, or, root};
111+
use crate::{
112+
HashSet, and, between, col, eq, get_item, gt, gt_eq, lit, lt, lt_eq, not_eq, or, root,
113+
};
111114

112115
// Implement some checked pruning expressions.
113116
#[fixture]
@@ -463,4 +466,29 @@ mod tests {
463466
)
464467
)
465468
}
469+
470+
#[rstest]
471+
fn pruning_between(available_stats: FieldPathSet) {
472+
let expr = between(
473+
col("a"),
474+
lit(10),
475+
lit(50),
476+
BetweenOptions {
477+
lower_strict: StrictComparison::NonStrict,
478+
upper_strict: StrictComparison::NonStrict,
479+
},
480+
);
481+
let (converted, refs) = checked_pruning_expr(&expr, &available_stats).unwrap();
482+
assert_eq!(
483+
refs.map(),
484+
&HashMap::from_iter([(
485+
FieldPath::from_name("a"),
486+
HashSet::from_iter([Stat::Min, Stat::Max])
487+
)])
488+
);
489+
assert_eq!(
490+
&converted,
491+
&or(gt(lit(10), col("a_max")), gt(col("a_min"), lit(50)))
492+
);
493+
}
466494
}

0 commit comments

Comments
 (0)