Skip to content

Commit 586a049

Browse files
committed
Add stats rewrite session API
Signed-off-by: "Nicholas Gates" <nick@nickgates.com>
1 parent 02d39d4 commit 586a049

6 files changed

Lines changed: 412 additions & 0 deletions

File tree

vortex-array/public-api.lock

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12824,6 +12824,8 @@ pub fn vortex_array::expr::Expression::children(&self) -> &alloc::sync::Arc<allo
1282412824

1282512825
pub fn vortex_array::expr::Expression::display_tree(&self) -> impl core::fmt::Display
1282612826

12827+
pub fn vortex_array::expr::Expression::falsify(&self, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
12828+
1282712829
pub fn vortex_array::expr::Expression::fmt_sql(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1282812830

1282912831
pub fn vortex_array::expr::Expression::return_dtype(&self, &vortex_array::dtype::DType) -> vortex_error::VortexResult<vortex_array::dtype::DType>
@@ -12842,6 +12844,8 @@ pub fn vortex_array::expr::Expression::try_new(vortex_array::scalar_fn::ScalarFn
1284212844

1284312845
pub fn vortex_array::expr::Expression::validity(&self) -> vortex_error::VortexResult<vortex_array::expr::Expression>
1284412846

12847+
pub fn vortex_array::expr::Expression::verify(&self, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
12848+
1284512849
pub fn vortex_array::expr::Expression::with_children(self, impl core::iter::traits::collect::IntoIterator<Item = vortex_array::expr::Expression>) -> vortex_error::VortexResult<Self>
1284612850

1284712851
impl vortex_array::expr::Expression
@@ -19820,6 +19824,68 @@ pub fn vortex_array::stats::expr::sum(vortex_array::expr::Expression) -> vortex_
1982019824

1982119825
pub mod vortex_array::stats::flatbuffers
1982219826

19827+
pub mod vortex_array::stats::rewrite
19828+
19829+
pub struct vortex_array::stats::rewrite::StatsRewriteCtx<'a>
19830+
19831+
impl<'a> vortex_array::stats::StatsRewriteCtx<'a>
19832+
19833+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::falsify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19834+
19835+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::new(&'a vortex_session::VortexSession) -> Self
19836+
19837+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::session(&self) -> &'a vortex_session::VortexSession
19838+
19839+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::verify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19840+
19841+
pub trait vortex_array::stats::rewrite::StatsRewriteRule: core::fmt::Debug + core::marker::Send + core::marker::Sync + 'static
19842+
19843+
pub fn vortex_array::stats::rewrite::StatsRewriteRule::falsify(&self, &vortex_array::expr::Expression, &vortex_array::stats::StatsRewriteCtx<'_>) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19844+
19845+
pub fn vortex_array::stats::rewrite::StatsRewriteRule::scalar_fn_id(&self) -> vortex_array::scalar_fn::ScalarFnId
19846+
19847+
pub fn vortex_array::stats::rewrite::StatsRewriteRule::verify(&self, &vortex_array::expr::Expression, &vortex_array::stats::StatsRewriteCtx<'_>) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19848+
19849+
pub fn vortex_array::stats::rewrite::falsify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19850+
19851+
pub fn vortex_array::stats::rewrite::verify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19852+
19853+
pub type vortex_array::stats::rewrite::StatsRewriteRuleRef = alloc::sync::Arc<dyn vortex_array::stats::StatsRewriteRule>
19854+
19855+
pub mod vortex_array::stats::session
19856+
19857+
pub struct vortex_array::stats::session::StatsRewriteSession
19858+
19859+
impl vortex_array::stats::StatsRewriteSession
19860+
19861+
pub fn vortex_array::stats::StatsRewriteSession::register<R: vortex_array::stats::StatsRewriteRule>(&self, R)
19862+
19863+
pub fn vortex_array::stats::StatsRewriteSession::register_ref(&self, vortex_array::stats::StatsRewriteRuleRef)
19864+
19865+
pub fn vortex_array::stats::StatsRewriteSession::rules_for(&self, vortex_array::scalar_fn::ScalarFnId) -> alloc::vec::Vec<vortex_array::stats::StatsRewriteRuleRef>
19866+
19867+
impl core::default::Default for vortex_array::stats::StatsRewriteSession
19868+
19869+
pub fn vortex_array::stats::StatsRewriteSession::default() -> vortex_array::stats::StatsRewriteSession
19870+
19871+
impl core::fmt::Debug for vortex_array::stats::StatsRewriteSession
19872+
19873+
pub fn vortex_array::stats::StatsRewriteSession::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
19874+
19875+
impl vortex_session::SessionVar for vortex_array::stats::StatsRewriteSession
19876+
19877+
pub fn vortex_array::stats::StatsRewriteSession::as_any(&self) -> &dyn core::any::Any
19878+
19879+
pub fn vortex_array::stats::StatsRewriteSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19880+
19881+
pub trait vortex_array::stats::session::StatsRewriteSessionExt: vortex_session::SessionExt
19882+
19883+
pub fn vortex_array::stats::session::StatsRewriteSessionExt::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
19884+
19885+
impl<S: vortex_session::SessionExt> vortex_array::stats::StatsRewriteSessionExt for S
19886+
19887+
pub fn S::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
19888+
1982319889
pub struct vortex_array::stats::ArrayStats
1982419890

1982519891
impl vortex_array::stats::ArrayStats
@@ -19880,6 +19946,42 @@ pub fn vortex_array::stats::MutTypedStatsSetRef<'_, '_>::is_empty(&self) -> bool
1988019946

1988119947
pub fn vortex_array::stats::MutTypedStatsSetRef<'_, '_>::len(&self) -> usize
1988219948

19949+
pub struct vortex_array::stats::StatsRewriteCtx<'a>
19950+
19951+
impl<'a> vortex_array::stats::StatsRewriteCtx<'a>
19952+
19953+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::falsify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19954+
19955+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::new(&'a vortex_session::VortexSession) -> Self
19956+
19957+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::session(&self) -> &'a vortex_session::VortexSession
19958+
19959+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::verify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19960+
19961+
pub struct vortex_array::stats::StatsRewriteSession
19962+
19963+
impl vortex_array::stats::StatsRewriteSession
19964+
19965+
pub fn vortex_array::stats::StatsRewriteSession::register<R: vortex_array::stats::StatsRewriteRule>(&self, R)
19966+
19967+
pub fn vortex_array::stats::StatsRewriteSession::register_ref(&self, vortex_array::stats::StatsRewriteRuleRef)
19968+
19969+
pub fn vortex_array::stats::StatsRewriteSession::rules_for(&self, vortex_array::scalar_fn::ScalarFnId) -> alloc::vec::Vec<vortex_array::stats::StatsRewriteRuleRef>
19970+
19971+
impl core::default::Default for vortex_array::stats::StatsRewriteSession
19972+
19973+
pub fn vortex_array::stats::StatsRewriteSession::default() -> vortex_array::stats::StatsRewriteSession
19974+
19975+
impl core::fmt::Debug for vortex_array::stats::StatsRewriteSession
19976+
19977+
pub fn vortex_array::stats::StatsRewriteSession::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
19978+
19979+
impl vortex_session::SessionVar for vortex_array::stats::StatsRewriteSession
19980+
19981+
pub fn vortex_array::stats::StatsRewriteSession::as_any(&self) -> &dyn core::any::Any
19982+
19983+
pub fn vortex_array::stats::StatsRewriteSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19984+
1988319985
pub struct vortex_array::stats::StatsSet
1988419986

1988519987
impl vortex_array::stats::StatsSet
@@ -20048,8 +20150,26 @@ pub fn vortex_array::stats::TypedStatsSetRef<'_, '_>::len(&self) -> usize
2004820150

2004920151
pub const vortex_array::stats::PRUNING_STATS: &[vortex_array::expr::stats::Stat]
2005020152

20153+
pub trait vortex_array::stats::StatsRewriteRule: core::fmt::Debug + core::marker::Send + core::marker::Sync + 'static
20154+
20155+
pub fn vortex_array::stats::StatsRewriteRule::falsify(&self, &vortex_array::expr::Expression, &vortex_array::stats::StatsRewriteCtx<'_>) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20156+
20157+
pub fn vortex_array::stats::StatsRewriteRule::scalar_fn_id(&self) -> vortex_array::scalar_fn::ScalarFnId
20158+
20159+
pub fn vortex_array::stats::StatsRewriteRule::verify(&self, &vortex_array::expr::Expression, &vortex_array::stats::StatsRewriteCtx<'_>) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20160+
20161+
pub trait vortex_array::stats::StatsRewriteSessionExt: vortex_session::SessionExt
20162+
20163+
pub fn vortex_array::stats::StatsRewriteSessionExt::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
20164+
20165+
impl<S: vortex_session::SessionExt> vortex_array::stats::StatsRewriteSessionExt for S
20166+
20167+
pub fn S::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
20168+
2005120169
pub fn vortex_array::stats::as_stat_bitset_bytes(&[vortex_array::expr::stats::Stat]) -> alloc::vec::Vec<u8>
2005220170

20171+
pub fn vortex_array::stats::falsify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20172+
2005320173
pub fn vortex_array::stats::min_max(vortex_array::expr::Expression) -> vortex_array::expr::Expression
2005420174

2005520175
pub fn vortex_array::stats::nan_count(vortex_array::expr::Expression) -> vortex_array::expr::Expression
@@ -20062,8 +20182,12 @@ pub fn vortex_array::stats::stats_from_bitset_bytes(&[u8]) -> alloc::vec::Vec<vo
2006220182

2006320183
pub fn vortex_array::stats::sum(vortex_array::expr::Expression) -> vortex_array::expr::Expression
2006420184

20185+
pub fn vortex_array::stats::verify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20186+
2006520187
pub type vortex_array::stats::StatsArray = [(vortex_array::expr::stats::Stat, vortex_array::expr::stats::Precision<vortex_array::scalar::ScalarValue>); 4]
2006620188

20189+
pub type vortex_array::stats::StatsRewriteRuleRef = alloc::sync::Arc<dyn vortex_array::stats::StatsRewriteRule>
20190+
2006720191
pub mod vortex_array::stream
2006820192

2006920193
pub struct vortex_array::stream::ArrayStreamAdapter<S>

vortex-array/src/expr/expression.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::sync::Arc;
1212
use itertools::Itertools;
1313
use vortex_error::VortexResult;
1414
use vortex_error::vortex_ensure;
15+
use vortex_session::VortexSession;
1516

1617
use crate::dtype::DType;
1718
use crate::expr::StatsCatalog;
@@ -135,6 +136,22 @@ impl Expression {
135136
self.scalar_fn().stat_falsification(self, catalog)
136137
}
137138

139+
/// Returns an expression that proves this predicate is definitely false from stats.
140+
///
141+
/// If the returned expression evaluates to `true` for a stats scope, this expression is
142+
/// guaranteed to be false for every row in that scope. `false` and `null` are unknown.
143+
pub fn falsify(&self, session: &VortexSession) -> VortexResult<Option<Expression>> {
144+
crate::stats::rewrite::falsify(self, session)
145+
}
146+
147+
/// Returns an expression that proves this predicate is definitely true from stats.
148+
///
149+
/// If the returned expression evaluates to `true` for a stats scope, this expression is
150+
/// guaranteed to be true for every row in that scope. `false` and `null` are unknown.
151+
pub fn verify(&self, session: &VortexSession) -> VortexResult<Option<Expression>> {
152+
crate::stats::rewrite::verify(self, session)
153+
}
154+
138155
/// Returns an expression representing the zoned statistic for the given stat, if available.
139156
///
140157
/// The [`StatsCatalog`] returns expressions that can be evaluated using the zone map as a

vortex-array/src/stats/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ mod array;
1818
pub mod expr;
1919
pub mod flatbuffers;
2020
pub(crate) mod legacy;
21+
pub mod rewrite;
22+
pub mod session;
2123
mod stats_set;
2224

2325
pub use array::*;
26+
pub use rewrite::*;
27+
pub use session::*;
2428
use vortex_error::VortexExpect;
2529

2630
use crate::expr::stats::Stat;

0 commit comments

Comments
 (0)