Skip to content

Commit 1974b37

Browse files
committed
Add stats rewrite session API
Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent b197676 commit 1974b37

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

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

12695+
pub fn vortex_array::expr::Expression::falsify(&self, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
12696+
1269512697
pub fn vortex_array::expr::Expression::fmt_sql(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1269612698

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

12701+
pub fn vortex_array::expr::Expression::satisfy(&self, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
12702+
1269912703
pub fn vortex_array::expr::Expression::scalar_fn(&self) -> &vortex_array::scalar_fn::ScalarFnRef
1270012704

1270112705
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>
@@ -19680,6 +19684,68 @@ pub fn vortex_array::stats::expr::stat(vortex_array::expr::Expression, vortex_ar
1968019684

1968119685
pub mod vortex_array::stats::flatbuffers
1968219686

19687+
pub mod vortex_array::stats::rewrite
19688+
19689+
pub struct vortex_array::stats::rewrite::StatsRewriteCtx<'a>
19690+
19691+
impl<'a> vortex_array::stats::StatsRewriteCtx<'a>
19692+
19693+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::falsify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19694+
19695+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::new(&'a vortex_session::VortexSession) -> Self
19696+
19697+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::satisfy(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19698+
19699+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::session(&self) -> &'a vortex_session::VortexSession
19700+
19701+
pub trait vortex_array::stats::rewrite::StatsRewriteRule: core::fmt::Debug + core::marker::Send + core::marker::Sync + 'static
19702+
19703+
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>>
19704+
19705+
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>>
19706+
19707+
pub fn vortex_array::stats::rewrite::StatsRewriteRule::scalar_fn_id(&self) -> vortex_array::scalar_fn::ScalarFnId
19708+
19709+
pub fn vortex_array::stats::rewrite::falsify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19710+
19711+
pub fn vortex_array::stats::rewrite::satisfy(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19712+
19713+
pub type vortex_array::stats::rewrite::StatsRewriteRuleRef = alloc::sync::Arc<dyn vortex_array::stats::StatsRewriteRule>
19714+
19715+
pub mod vortex_array::stats::session
19716+
19717+
pub struct vortex_array::stats::session::StatsRewriteSession
19718+
19719+
impl vortex_array::stats::StatsRewriteSession
19720+
19721+
pub fn vortex_array::stats::StatsRewriteSession::register<R: vortex_array::stats::StatsRewriteRule>(&self, R)
19722+
19723+
pub fn vortex_array::stats::StatsRewriteSession::register_ref(&self, vortex_array::stats::StatsRewriteRuleRef)
19724+
19725+
pub fn vortex_array::stats::StatsRewriteSession::rules_for(&self, vortex_array::scalar_fn::ScalarFnId) -> alloc::vec::Vec<vortex_array::stats::StatsRewriteRuleRef>
19726+
19727+
impl core::default::Default for vortex_array::stats::StatsRewriteSession
19728+
19729+
pub fn vortex_array::stats::StatsRewriteSession::default() -> vortex_array::stats::StatsRewriteSession
19730+
19731+
impl core::fmt::Debug for vortex_array::stats::StatsRewriteSession
19732+
19733+
pub fn vortex_array::stats::StatsRewriteSession::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
19734+
19735+
impl vortex_session::SessionVar for vortex_array::stats::StatsRewriteSession
19736+
19737+
pub fn vortex_array::stats::StatsRewriteSession::as_any(&self) -> &dyn core::any::Any
19738+
19739+
pub fn vortex_array::stats::StatsRewriteSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19740+
19741+
pub trait vortex_array::stats::session::StatsRewriteSessionExt: vortex_session::SessionExt
19742+
19743+
pub fn vortex_array::stats::session::StatsRewriteSessionExt::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
19744+
19745+
impl<S: vortex_session::SessionExt> vortex_array::stats::StatsRewriteSessionExt for S
19746+
19747+
pub fn S::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
19748+
1968319749
pub struct vortex_array::stats::ArrayStats
1968419750

1968519751
impl vortex_array::stats::ArrayStats
@@ -19740,6 +19806,42 @@ pub fn vortex_array::stats::MutTypedStatsSetRef<'_, '_>::is_empty(&self) -> bool
1974019806

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

19809+
pub struct vortex_array::stats::StatsRewriteCtx<'a>
19810+
19811+
impl<'a> vortex_array::stats::StatsRewriteCtx<'a>
19812+
19813+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::falsify(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19814+
19815+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::new(&'a vortex_session::VortexSession) -> Self
19816+
19817+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::satisfy(&self, &vortex_array::expr::Expression) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
19818+
19819+
pub fn vortex_array::stats::StatsRewriteCtx<'a>::session(&self) -> &'a vortex_session::VortexSession
19820+
19821+
pub struct vortex_array::stats::StatsRewriteSession
19822+
19823+
impl vortex_array::stats::StatsRewriteSession
19824+
19825+
pub fn vortex_array::stats::StatsRewriteSession::register<R: vortex_array::stats::StatsRewriteRule>(&self, R)
19826+
19827+
pub fn vortex_array::stats::StatsRewriteSession::register_ref(&self, vortex_array::stats::StatsRewriteRuleRef)
19828+
19829+
pub fn vortex_array::stats::StatsRewriteSession::rules_for(&self, vortex_array::scalar_fn::ScalarFnId) -> alloc::vec::Vec<vortex_array::stats::StatsRewriteRuleRef>
19830+
19831+
impl core::default::Default for vortex_array::stats::StatsRewriteSession
19832+
19833+
pub fn vortex_array::stats::StatsRewriteSession::default() -> vortex_array::stats::StatsRewriteSession
19834+
19835+
impl core::fmt::Debug for vortex_array::stats::StatsRewriteSession
19836+
19837+
pub fn vortex_array::stats::StatsRewriteSession::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result
19838+
19839+
impl vortex_session::SessionVar for vortex_array::stats::StatsRewriteSession
19840+
19841+
pub fn vortex_array::stats::StatsRewriteSession::as_any(&self) -> &dyn core::any::Any
19842+
19843+
pub fn vortex_array::stats::StatsRewriteSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19844+
1974319845
pub struct vortex_array::stats::StatsSet
1974419846

1974519847
impl vortex_array::stats::StatsSet
@@ -19908,14 +20010,36 @@ pub fn vortex_array::stats::TypedStatsSetRef<'_, '_>::len(&self) -> usize
1990820010

1990920011
pub const vortex_array::stats::PRUNING_STATS: &[vortex_array::expr::stats::Stat]
1991020012

20013+
pub trait vortex_array::stats::StatsRewriteRule: core::fmt::Debug + core::marker::Send + core::marker::Sync + 'static
20014+
20015+
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>>
20016+
20017+
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>>
20018+
20019+
pub fn vortex_array::stats::StatsRewriteRule::scalar_fn_id(&self) -> vortex_array::scalar_fn::ScalarFnId
20020+
20021+
pub trait vortex_array::stats::StatsRewriteSessionExt: vortex_session::SessionExt
20022+
20023+
pub fn vortex_array::stats::StatsRewriteSessionExt::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
20024+
20025+
impl<S: vortex_session::SessionExt> vortex_array::stats::StatsRewriteSessionExt for S
20026+
20027+
pub fn S::stats_rewrites(&self) -> vortex_session::Ref<'_, vortex_array::stats::StatsRewriteSession>
20028+
1991120029
pub fn vortex_array::stats::as_stat_bitset_bytes(&[vortex_array::expr::stats::Stat]) -> alloc::vec::Vec<u8>
1991220030

20031+
pub fn vortex_array::stats::falsify(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20032+
20033+
pub fn vortex_array::stats::satisfy(&vortex_array::expr::Expression, &vortex_session::VortexSession) -> vortex_error::VortexResult<core::option::Option<vortex_array::expr::Expression>>
20034+
1991320035
pub fn vortex_array::stats::stat(vortex_array::expr::Expression, vortex_array::aggregate_fn::AggregateFnRef) -> vortex_array::expr::Expression
1991420036

1991520037
pub fn vortex_array::stats::stats_from_bitset_bytes(&[u8]) -> alloc::vec::Vec<vortex_array::expr::stats::Stat>
1991620038

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

20041+
pub type vortex_array::stats::StatsRewriteRuleRef = alloc::sync::Arc<dyn vortex_array::stats::StatsRewriteRule>
20042+
1991920043
pub mod vortex_array::stream
1992020044

1992120045
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
@@ -13,9 +13,13 @@ pub use stats_set::*;
1313
mod array;
1414
pub mod expr;
1515
pub mod flatbuffers;
16+
pub mod rewrite;
17+
pub mod session;
1618
mod stats_set;
1719

1820
pub use array::*;
21+
pub use rewrite::*;
22+
pub use session::*;
1923
use vortex_error::VortexExpect;
2024

2125
use crate::expr::stats::Stat;

0 commit comments

Comments
 (0)