vortex_expr/analysis.rs
1use vortex_array::stats::Stat;
2
3use crate::{AccessPath, ExprRef};
4
5pub trait StatsCatalog {
6 /// Given an id, field and stat return an expression that when evaluated will return that stat
7 /// this would be a column reference or a literal value, if the value is known at planning time.
8 fn stats_ref(&mut self, _access_path: &AccessPath, _stat: Stat) -> Option<ExprRef> {
9 None
10 }
11}
12
13/// This can be used by expression to plug into vortex expression analysis, such as
14/// pruning or expression simplification
15pub trait AnalysisExpr {
16 /// An expression over zone-statistics which implies all records in the zone evaluate to false.
17 ///
18 /// Given an expression, `e`, if `e.stat_falsification(..)` evaluates to true, it is guaranteed
19 /// that `e` evaluates to false on all records in the zone. However, the inverse is not
20 /// necessarily true: even if the falsification evaluates to false, `e` need not evaluate to
21 /// true on all records.
22 ///
23 /// The `StatsCatalog` can be used to constrain or rename stats used in the final expr.
24 ///
25 /// # Examples
26 ///
27 /// - An expression over one variable: `x > 0` is false for all records in a zone if the maximum
28 /// value of the column `x` in that zone is less than or equal to zero: `max(x) <= 0`.
29 /// - An expression over two variables: `x > y` becomes `max(x) <= min(y)`.
30 /// - A conjunctive expression: `x > y AND z < x` becomes `max(x) <= min(y) OR min(z) >= max(x).
31 ///
32 /// Some expressions, in theory, have falsifications but this function does not support them
33 /// such as `x < (y < z)` or `x LIKE "needle%"`.
34 fn stat_falsification(&self, _catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
35 None
36 }
37
38 /// If an expression is returned, its value is an upper bound on the value of `expr`.
39 ///
40 /// We may return `None` for values which have no upper bound or values for which knowing the
41 /// upper bound is difficult.
42 fn max(&self, _catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
43 None
44 }
45 /// If an expression is returned, its value is an upper bound on the value of `expr`.
46 /// see `AnalysisExpr::max`
47 fn min(&self, _catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
48 None
49 }
50
51 fn field_path(&self) -> Option<AccessPath> {
52 None
53 }
54
55 // TODO: add containment
56}