Skip to content

Commit 54f5e31

Browse files
committed
Add stats rewrite session API
Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent 6a79bbc commit 54f5e31

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
@@ -12778,10 +12778,14 @@ pub fn vortex_array::expr::Expression::children(&self) -> &alloc::sync::Arc<allo
1277812778

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

12781+
pub fn vortex_array::expr::Expression::falsify(&self, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
12782+
1278112783
pub fn vortex_array::expr::Expression::fmt_sql(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1278212784

1278312785
pub fn vortex_array::expr::Expression::return_dtype(&self, &vortex_array::dtype::DType) -> vortex_error::VortexResult<vortex_array::dtype::DType>
1278412786

12787+
pub fn vortex_array::expr::Expression::satisfy(&self, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
12788+
1278512789
pub fn vortex_array::expr::Expression::scalar_fn(&self) -> &vortex_array::scalar_fn::ScalarFnRef
1278612790

1278712791
pub fn vortex_array::expr::Expression::stat_expression(&self, vortex_array::expr::stats::Stat, &dyn vortex_array::expr::pruning::StatsCatalog) -> core::option::Option<vortex_array::expr::Expression>
@@ -19774,6 +19778,68 @@ pub fn vortex_array::stats::expr::sum(vortex_array::expr::Expression) -> vortex_
1977419778

1977519779
pub mod vortex_array::stats::flatbuffers
1977619780

19781+
pub mod vortex_array::stats::rewrite
19782+
19783+
pub struct vortex_array::stats::rewrite::StatsRewriteCtx<'a>
19784+
19785+
impl<'a> vortex_array::stats::StatsRewriteCtx<'a>
19786+
19787+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::falsify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19788+
19789+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::new(&'a vortex_session::VortexSession) -> Self
19790+
19791+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::satisfy(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19792+
19793+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::session(&self) -> &'a vortex_session::VortexSession
19794+
19795+
pub trait vortex_array::stats::rewrite::StatsRewriteRule: core::fmt::Debug + core::marker::Send + core::marker::Sync + 'static
19796+
19797+
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>>
19798+
19799+
pub fn vortex_array::stats::rewrite::StatsRewriteRule::satisfy(&self, &vortex_array::expr::Expression, &vortex_array::stats::StatsRewriteCtx<'_>) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19800+
19801+
pub fn vortex_array::stats::rewrite::StatsRewriteRule::scalar_fn_id(&self) -> vortex_array::scalar_fn::ScalarFnId
19802+
19803+
pub fn vortex_array::stats::rewrite::falsify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19804+
19805+
pub fn vortex_array::stats::rewrite::satisfy(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19806+
19807+
pub type vortex_array::stats::rewrite::StatsRewriteRuleRef = alloc::sync::Arc<dyn vortex_array::stats::StatsRewriteRule>
19808+
19809+
pub mod vortex_array::stats::session
19810+
19811+
pub struct vortex_array::stats::session::StatsRewriteSession
19812+
19813+
impl vortex_array::stats::StatsRewriteSession
19814+
19815+
pub fn vortex_array::stats::StatsRewriteSession::register<R: vortex_array::stats::StatsRewriteRule>(&self, R)
19816+
19817+
pub fn vortex_array::stats::StatsRewriteSession::register_ref(&self, vortex_array::stats::StatsRewriteRuleRef)
19818+
19819+
pub fn vortex_array::stats::StatsRewriteSession::rules_for(&self, vortex_array::scalar_fn::ScalarFnId) -> alloc::vec::Vec<vortex_array::stats::StatsRewriteRuleRef>
19820+
19821+
impl core::default::Default for vortex_array::stats::StatsRewriteSession
19822+
19823+
pub fn vortex_array::stats::StatsRewriteSession::default() -> vortex_array::stats::StatsRewriteSession
19824+
19825+
impl core::fmt::Debug for vortex_array::stats::StatsRewriteSession
19826+
19827+
pub fn vortex_array::stats::StatsRewriteSession::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
19828+
19829+
impl vortex_session::SessionVar for vortex_array::stats::StatsRewriteSession
19830+
19831+
pub fn vortex_array::stats::StatsRewriteSession::as_any(&self) -> &dyn core::any::Any
19832+
19833+
pub fn vortex_array::stats::StatsRewriteSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19834+
19835+
pub trait vortex_array::stats::session::StatsRewriteSessionExt: vortex_session::SessionExt
19836+
19837+
pub fn vortex_array::stats::session::StatsRewriteSessionExt::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
19838+
19839+
impl<S: vortex_session::SessionExt> vortex_array::stats::StatsRewriteSessionExt for S
19840+
19841+
pub fn S::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
19842+
1977719843
pub struct vortex_array::stats::ArrayStats
1977819844

1977919845
impl vortex_array::stats::ArrayStats
@@ -19834,6 +19900,42 @@ pub fn vortex_array::stats::MutTypedStatsSetRef<'_, '_>::is_empty(&self) -> bool
1983419900

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

19903+
pub struct vortex_array::stats::StatsRewriteCtx<'a>
19904+
19905+
impl<'a> vortex_array::stats::StatsRewriteCtx<'a>
19906+
19907+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::falsify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19908+
19909+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::new(&'a vortex_session::VortexSession) -> Self
19910+
19911+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::satisfy(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19912+
19913+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::session(&self) -> &'a vortex_session::VortexSession
19914+
19915+
pub struct vortex_array::stats::StatsRewriteSession
19916+
19917+
impl vortex_array::stats::StatsRewriteSession
19918+
19919+
pub fn vortex_array::stats::StatsRewriteSession::register<R: vortex_array::stats::StatsRewriteRule>(&self, R)
19920+
19921+
pub fn vortex_array::stats::StatsRewriteSession::register_ref(&self, vortex_array::stats::StatsRewriteRuleRef)
19922+
19923+
pub fn vortex_array::stats::StatsRewriteSession::rules_for(&self, vortex_array::scalar_fn::ScalarFnId) -> alloc::vec::Vec<vortex_array::stats::StatsRewriteRuleRef>
19924+
19925+
impl core::default::Default for vortex_array::stats::StatsRewriteSession
19926+
19927+
pub fn vortex_array::stats::StatsRewriteSession::default() -> vortex_array::stats::StatsRewriteSession
19928+
19929+
impl core::fmt::Debug for vortex_array::stats::StatsRewriteSession
19930+
19931+
pub fn vortex_array::stats::StatsRewriteSession::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
19932+
19933+
impl vortex_session::SessionVar for vortex_array::stats::StatsRewriteSession
19934+
19935+
pub fn vortex_array::stats::StatsRewriteSession::as_any(&self) -> &dyn core::any::Any
19936+
19937+
pub fn vortex_array::stats::StatsRewriteSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19938+
1983719939
pub struct vortex_array::stats::StatsSet
1983819940

1983919941
impl vortex_array::stats::StatsSet
@@ -20002,14 +20104,34 @@ pub fn vortex_array::stats::TypedStatsSetRef<'_, '_>::len(&self) -> usize
2000220104

2000320105
pub const vortex_array::stats::PRUNING_STATS: &[vortex_array::expr::stats::Stat]
2000420106

20107+
pub trait vortex_array::stats::StatsRewriteRule: core::fmt::Debug + core::marker::Send + core::marker::Sync + 'static
20108+
20109+
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>>
20110+
20111+
pub fn vortex_array::stats::StatsRewriteRule::satisfy(&self, &vortex_array::expr::Expression, &vortex_array::stats::StatsRewriteCtx<'_>) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20112+
20113+
pub fn vortex_array::stats::StatsRewriteRule::scalar_fn_id(&self) -> vortex_array::scalar_fn::ScalarFnId
20114+
20115+
pub trait vortex_array::stats::StatsRewriteSessionExt: vortex_session::SessionExt
20116+
20117+
pub fn vortex_array::stats::StatsRewriteSessionExt::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
20118+
20119+
impl<S: vortex_session::SessionExt> vortex_array::stats::StatsRewriteSessionExt for S
20120+
20121+
pub fn S::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
20122+
2000520123
pub fn vortex_array::stats::as_stat_bitset_bytes(&[vortex_array::expr::stats::Stat]) -> alloc::vec::Vec<u8>
2000620124

20125+
pub fn vortex_array::stats::falsify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20126+
2000720127
pub fn vortex_array::stats::min_max(vortex_array::expr::Expression) -> vortex_array::expr::Expression
2000820128

2000920129
pub fn vortex_array::stats::nan_count(vortex_array::expr::Expression) -> vortex_array::expr::Expression
2001020130

2001120131
pub fn vortex_array::stats::null_count(vortex_array::expr::Expression) -> vortex_array::expr::Expression
2001220132

20133+
pub fn vortex_array::stats::satisfy(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20134+
2001320135
pub fn vortex_array::stats::stat(vortex_array::expr::Expression, vortex_array::aggregate_fn::AggregateFnRef) -> vortex_array::expr::Expression
2001420136

2001520137
pub fn vortex_array::stats::stats_from_bitset_bytes(&[u8]) -> alloc::vec::Vec<vortex_array::expr::stats::Stat>
@@ -20018,6 +20140,8 @@ pub fn vortex_array::stats::sum(vortex_array::expr::Expression) -> vortex_array:
2001820140

2001920141
pub type vortex_array::stats::StatsArray = [(vortex_array::expr::stats::Stat, vortex_array::expr::stats::Precision<vortex_array::scalar::ScalarValue>); 4]
2002020142

20143+
pub type vortex_array::stats::StatsRewriteRuleRef = alloc::sync::Arc<dyn vortex_array::stats::StatsRewriteRule>
20144+
2002120145
pub mod vortex_array::stream
2002220146

2002320147
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 satisfy(&self, session: &VortexSession) -> VortexResult<Option<Expression>> {
152+
crate::stats::rewrite::satisfy(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
@@ -17,9 +17,13 @@ pub use stats_set::*;
1717
mod array;
1818
pub mod expr;
1919
pub mod flatbuffers;
20+
pub mod rewrite;
21+
pub mod session;
2022
mod stats_set;
2123

2224
pub use array::*;
25+
pub use rewrite::*;
26+
pub use session::*;
2327
use vortex_error::VortexExpect;
2428

2529
use crate::expr::stats::Stat;

0 commit comments

Comments
 (0)