use crate::ExecutionPlan;
use crate::displayable;
use crate::operator_statistics::{
ExtendedStatistics, StatisticsRegistry, StatisticsResult,
};
use datafusion_common::extensions::Extensions;
use datafusion_common::stats::Precision;
use datafusion_common::{
Result, Statistics, assert_eq_or_internal_err, assert_or_internal_err,
};
use log::debug;
use parking_lot::Mutex;
use std::collections::HashMap;
use std::ptr::from_ref;
use std::sync::Arc;
type CacheKey = (usize, Option<usize>);
fn cache_key(plan: &dyn ExecutionPlan, partition: Option<usize>) -> CacheKey {
(
from_ref::<dyn ExecutionPlan>(plan).cast::<()>() as usize,
partition,
)
}
#[derive(Debug)]
struct CacheEntry<T> {
_plan: Arc<dyn ExecutionPlan>,
value: T,
}
#[derive(Debug, Default)]
struct StatsCache {
statistics: HashMap<CacheKey, CacheEntry<Arc<Statistics>>>,
extensions: HashMap<CacheKey, CacheEntry<Extensions>>,
}
#[derive(Debug, Default, Clone)]
pub struct StatisticsArgs {
partition: Option<usize>,
}
impl StatisticsArgs {
pub fn new() -> Self {
Default::default()
}
pub fn set_partition(&mut self, partition: Option<usize>) {
self.partition = partition;
}
pub fn with_partition(mut self, partition: Option<usize>) -> Self {
self.set_partition(partition);
self
}
pub fn partition(&self) -> Option<usize> {
self.partition
}
}
pub(crate) fn with_per_partition_fetch(
input: Statistics,
fetch: Option<usize>,
n_partitions: usize,
args: &StatisticsArgs,
) -> Result<Statistics> {
let Some(fetch) = fetch else {
return Ok(input);
};
if args.partition().is_some() || n_partitions <= 1 {
return input.with_fetch(Some(fetch), 0, 1);
}
if matches!(input.num_rows, Precision::Exact(num_rows) if num_rows <= fetch) {
return Ok(input);
}
Ok(input
.with_fetch(Some(fetch.saturating_mul(n_partitions)), 0, 1)?
.to_inexact())
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChildStats {
At(Option<usize>),
Skip,
}
pub struct StatisticsContext {
cache: Mutex<StatsCache>,
registry: StatisticsRegistry,
}
impl Default for StatisticsContext {
fn default() -> Self {
Self::new()
}
}
impl StatisticsContext {
pub fn new() -> Self {
Self::new_with_registry(StatisticsRegistry::new())
}
pub fn new_with_registry(registry: StatisticsRegistry) -> Self {
Self {
cache: Mutex::new(StatsCache::default()),
registry,
}
}
pub fn reset_cache(&self) {
let mut cache = self.cache.lock();
cache.statistics.clear();
cache.extensions.clear();
}
pub fn compute(
&self,
plan: &dyn ExecutionPlan,
args: &StatisticsArgs,
) -> Result<Arc<Statistics>> {
self.compute_base(plan, None, args, false)
.map(|(statistics, _)| statistics)
}
pub fn compute_arc(
&self,
plan: &Arc<dyn ExecutionPlan>,
args: &StatisticsArgs,
) -> Result<Arc<Statistics>> {
self.compute_base(plan.as_ref(), Some(plan), args, false)
.map(|(statistics, _)| statistics)
}
pub fn compute_extended(
&self,
plan: &dyn ExecutionPlan,
args: &StatisticsArgs,
) -> Result<Arc<ExtendedStatistics>> {
self.compute_extended_base(plan, None, args)
}
pub fn compute_extended_arc(
&self,
plan: &Arc<dyn ExecutionPlan>,
args: &StatisticsArgs,
) -> Result<Arc<ExtendedStatistics>> {
self.compute_extended_base(plan.as_ref(), Some(plan), args)
}
fn compute_extended_base(
&self,
plan: &dyn ExecutionPlan,
retained_plan: Option<&Arc<dyn ExecutionPlan>>,
args: &StatisticsArgs,
) -> Result<Arc<ExtendedStatistics>> {
let (statistics, extensions) =
self.compute_base(plan, retained_plan, args, true)?;
Ok(Arc::new(ExtendedStatistics::new_with_extensions(
statistics,
extensions.unwrap_or_default(),
)))
}
fn compute_base(
&self,
plan: &dyn ExecutionPlan,
retained_plan: Option<&Arc<dyn ExecutionPlan>>,
args: &StatisticsArgs,
read_cached_extensions: bool,
) -> Result<(Arc<Statistics>, Option<Extensions>)> {
let partition = args.partition();
if let Some(idx) = partition {
let partition_count = plan.properties().partitioning.partition_count();
assert_or_internal_err!(
idx < partition_count,
"Invalid partition index: {}, the partition count is {}",
idx,
partition_count
);
}
if let Some(cached) = self.cached_statistics(plan, partition) {
let extensions =
if read_cached_extensions && !self.registry.providers().is_empty() {
self.cached_extensions(plan, partition)
} else {
None
};
return Ok((cached, extensions));
}
let children = plan.children();
let (statistics, extensions) =
match self.try_provider_stats(plan, retained_plan, &children, args)? {
Some(computed) => computed,
None => {
let requests = plan.child_stats_requests(partition);
self.validate_child_requests(plan, &children, &requests)?;
let child_statistics =
self.resolve_children(plan, &children, &requests)?;
(plan.statistics_from_inputs(&child_statistics, args)?, None)
}
};
if let Some(owner) = retained_plan {
self.store_statistics(owner, partition, Arc::clone(&statistics));
}
Ok((statistics, extensions))
}
fn validate_child_requests(
&self,
plan: &dyn ExecutionPlan,
children: &[&Arc<dyn ExecutionPlan>],
requests: &[ChildStats],
) -> Result<()> {
assert_eq_or_internal_err!(
requests.len(),
children.len(),
"{} child_stats_requests returned {} entries for {} children",
plan.name(),
requests.len(),
children.len()
);
for (child, directive) in children.iter().zip(requests) {
if let ChildStats::At(Some(idx)) = directive {
let count = child.properties().partitioning.partition_count();
assert_or_internal_err!(
*idx < count,
"{} requested invalid partition {idx} for child {} with {count} partitions",
plan.name(),
child.name()
);
}
}
Ok(())
}
fn resolve_children(
&self,
plan: &dyn ExecutionPlan,
children: &[&Arc<dyn ExecutionPlan>],
requests: &[ChildStats],
) -> Result<Vec<Arc<Statistics>>> {
children
.iter()
.zip(requests)
.enumerate()
.map(|(i, (child, directive))| match directive {
ChildStats::At(p) => self
.compute_base(
child.as_ref(),
Some(child),
&StatisticsArgs::new().with_partition(*p),
false,
)
.map(|(statistics, _)| statistics)
.map_err(|e| {
e.context(format!(
"computing statistics for child {i} ({}) of {} at partition {p:?}",
child.name(),
plan.name()
))
}),
ChildStats::Skip => {
Ok(Arc::new(Statistics::new_unknown(child.schema().as_ref())))
}
})
.collect()
}
fn try_provider_stats(
&self,
plan: &dyn ExecutionPlan,
retained_plan: Option<&Arc<dyn ExecutionPlan>>,
children: &[&Arc<dyn ExecutionPlan>],
args: &StatisticsArgs,
) -> Result<Option<(Arc<Statistics>, Option<Extensions>)>> {
let providers = self.registry.providers();
if providers.is_empty() {
return Ok(None);
}
let partition = args.partition();
for provider in providers {
if !provider.matches(plan) {
continue;
}
let requests = provider.child_stats_requests(plan, partition);
self.validate_child_requests(plan, children, &requests)?;
let child_statistics = match self.resolve_children(plan, children, &requests)
{
Ok(child_statistics) => child_statistics,
Err(e) => {
debug!(
"Statistics provider {provider:?} skipped for {}: child statistics resolution failed: {e}",
displayable(plan).one_line().to_string().trim_end()
);
continue;
}
};
let child_extended =
self.child_extended_stats(children, &requests, &child_statistics);
if let StatisticsResult::Computed(computed) =
provider.compute_statistics_with_args(plan, &child_extended, args)?
{
let (statistics, extensions) = computed.into_parts();
let extensions = if extensions.is_empty() {
None
} else {
if let Some(owner) = retained_plan {
self.store_extensions(owner, partition, extensions.clone());
}
Some(extensions)
};
return Ok(Some((statistics, extensions)));
}
}
Ok(None)
}
fn child_extended_stats(
&self,
children: &[&Arc<dyn ExecutionPlan>],
requests: &[ChildStats],
child_statistics: &[Arc<Statistics>],
) -> Vec<ExtendedStatistics> {
children
.iter()
.zip(requests)
.zip(child_statistics)
.map(|((child, directive), statistics)| {
let extensions = match directive {
ChildStats::At(p) => self.cached_extensions(child.as_ref(), *p),
ChildStats::Skip => None,
};
match extensions {
Some(extensions) => ExtendedStatistics::new_with_extensions(
Arc::clone(statistics),
extensions,
),
None => ExtendedStatistics::new_arc(Arc::clone(statistics)),
}
})
.collect()
}
fn cached_statistics(
&self,
plan: &dyn ExecutionPlan,
partition: Option<usize>,
) -> Option<Arc<Statistics>> {
self.cache
.lock()
.statistics
.get(&cache_key(plan, partition))
.map(|entry| Arc::clone(&entry.value))
}
fn store_cache_entry<T>(
cache: &mut HashMap<CacheKey, CacheEntry<T>>,
owner: &Arc<dyn ExecutionPlan>,
partition: Option<usize>,
value: T,
) {
cache.insert(
cache_key(owner.as_ref(), partition),
CacheEntry {
_plan: Arc::clone(owner),
value,
},
);
}
fn store_statistics(
&self,
owner: &Arc<dyn ExecutionPlan>,
partition: Option<usize>,
statistics: Arc<Statistics>,
) {
Self::store_cache_entry(
&mut self.cache.lock().statistics,
owner,
partition,
statistics,
);
}
fn cached_extensions(
&self,
plan: &dyn ExecutionPlan,
partition: Option<usize>,
) -> Option<Extensions> {
self.cache
.lock()
.extensions
.get(&cache_key(plan, partition))
.map(|entry| entry.value.clone())
}
fn store_extensions(
&self,
owner: &Arc<dyn ExecutionPlan>,
partition: Option<usize>,
extensions: Extensions,
) {
Self::store_cache_entry(
&mut self.cache.lock().extensions,
owner,
partition,
extensions,
);
}
}
#[cfg(all(test, feature = "test_utils"))]
mod tests {
use super::*;
use crate::coalesce_partitions::CoalescePartitionsExec;
use crate::operator_statistics::StatisticsProvider;
use crate::test::exec::StatisticsExec;
use crate::union::UnionExec;
use arrow::datatypes::{DataType, Field, Schema};
use datafusion_common::{ColumnStatistics, stats::Precision};
#[derive(Debug)]
struct FixedRowCountProvider(usize);
impl StatisticsProvider for FixedRowCountProvider {
fn compute_statistics(
&self,
plan: &dyn ExecutionPlan,
_child_stats: &[ExtendedStatistics],
) -> Result<StatisticsResult> {
let mut stats = Statistics::new_unknown(&plan.schema());
stats.num_rows = Precision::Exact(self.0);
Ok(StatisticsResult::Computed(ExtendedStatistics::new(stats)))
}
}
#[derive(Debug)]
struct PartitionRowCountProvider;
impl StatisticsProvider for PartitionRowCountProvider {
fn compute_statistics_with_args(
&self,
plan: &dyn ExecutionPlan,
_child_stats: &[ExtendedStatistics],
args: &StatisticsArgs,
) -> Result<StatisticsResult> {
let marker = 700 + args.partition().map_or(0, |p| p + 1);
let mut stats = Statistics::new_unknown(&plan.schema());
stats.num_rows = Precision::Exact(marker);
Ok(StatisticsResult::Computed(ExtendedStatistics::new(stats)))
}
}
#[derive(Debug, Clone, PartialEq)]
struct Tag(u32);
#[derive(Debug)]
struct TagLeafProvider {
rows: usize,
tag: u32,
}
impl StatisticsProvider for TagLeafProvider {
fn compute_statistics(
&self,
plan: &dyn ExecutionPlan,
child_stats: &[ExtendedStatistics],
) -> Result<StatisticsResult> {
if !child_stats.is_empty() {
return Ok(StatisticsResult::Delegate);
}
let mut stats = Statistics::new_unknown(&plan.schema());
stats.num_rows = Precision::Exact(self.rows);
let mut extended = ExtendedStatistics::new(stats);
extended.set_extension(Tag(self.tag));
Ok(StatisticsResult::Computed(extended))
}
}
#[derive(Debug)]
struct TagDoublingProvider;
impl StatisticsProvider for TagDoublingProvider {
fn compute_statistics(
&self,
plan: &dyn ExecutionPlan,
child_stats: &[ExtendedStatistics],
) -> Result<StatisticsResult> {
let Some(Tag(v)) = child_stats.first().and_then(|c| c.get_extension::<Tag>())
else {
return Ok(StatisticsResult::Delegate);
};
let mut extended =
ExtendedStatistics::new(Statistics::new_unknown(&plan.schema()));
extended.set_extension(Tag(v * 2));
Ok(StatisticsResult::Computed(extended))
}
}
fn ctx_with(provider: Arc<dyn StatisticsProvider>) -> StatisticsContext {
StatisticsContext::new_with_registry(StatisticsRegistry::with_providers(vec![
provider,
]))
}
fn make_stats_leaf(num_rows: usize) -> Arc<dyn ExecutionPlan> {
let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
let col_stats = vec![ColumnStatistics {
null_count: Precision::Exact(0),
max_value: Precision::Absent,
min_value: Precision::Absent,
sum_value: Precision::Absent,
distinct_count: Precision::Absent,
byte_size: Precision::Absent,
}];
Arc::new(StatisticsExec::new(
Statistics {
num_rows: Precision::Exact(num_rows),
total_byte_size: Precision::Absent,
column_statistics: col_stats,
},
schema,
))
}
#[test]
fn coalesce_returns_overall_stats_for_any_partition() {
let leaf = make_stats_leaf(100);
let plan: Arc<dyn ExecutionPlan> = Arc::new(CoalescePartitionsExec::new(leaf));
let ctx = StatisticsContext::new();
let stats = ctx
.compute(
plan.as_ref(),
&StatisticsArgs::new().with_partition(Some(0)),
)
.unwrap();
assert_eq!(stats.num_rows, Precision::Exact(100));
let stats_none = ctx.compute(plan.as_ref(), &StatisticsArgs::new()).unwrap();
assert_eq!(stats_none.num_rows, Precision::Exact(100));
}
#[test]
fn context_caches_within_walk() {
let leaf = make_stats_leaf(42);
let ctx = StatisticsContext::new();
let args = StatisticsArgs::new();
let s1 = ctx.compute_arc(&leaf, &args).unwrap();
assert!(!ctx.cache.lock().statistics.is_empty());
let s2 = ctx.compute_arc(&leaf, &args).unwrap();
assert!(Arc::ptr_eq(&s1, &s2));
}
#[test]
fn context_cache_retains_plan_lifetime() {
let leaf = make_stats_leaf(10);
let weak = Arc::downgrade(&leaf);
let ctx = StatisticsContext::new();
let _ = ctx.compute_arc(&leaf, &StatisticsArgs::new()).unwrap();
drop(leaf);
assert!(weak.upgrade().is_some());
ctx.reset_cache();
assert!(weak.upgrade().is_none());
}
#[test]
fn owned_parent_and_leaf_are_released_by_reset() {
let leaf = make_stats_leaf(10);
let leaf_weak = Arc::downgrade(&leaf);
let parent: Arc<dyn ExecutionPlan> =
Arc::new(CoalescePartitionsExec::new(Arc::clone(&leaf)));
let parent_weak = Arc::downgrade(&parent);
let ctx = StatisticsContext::new();
let _ = ctx.compute_arc(&parent, &StatisticsArgs::new()).unwrap();
drop(parent);
drop(leaf);
assert!(parent_weak.upgrade().is_some());
assert!(leaf_weak.upgrade().is_some());
ctx.reset_cache();
assert!(parent_weak.upgrade().is_none());
assert!(leaf_weak.upgrade().is_none());
}
#[test]
fn owned_parent_and_leaf_are_released_when_context_drops() {
let leaf = make_stats_leaf(10);
let leaf_weak = Arc::downgrade(&leaf);
let parent: Arc<dyn ExecutionPlan> =
Arc::new(CoalescePartitionsExec::new(Arc::clone(&leaf)));
let parent_weak = Arc::downgrade(&parent);
{
let ctx = StatisticsContext::new();
let _ = ctx.compute_arc(&parent, &StatisticsArgs::new()).unwrap();
drop(parent);
drop(leaf);
assert!(parent_weak.upgrade().is_some());
assert!(leaf_weak.upgrade().is_some());
}
assert!(parent_weak.upgrade().is_none());
assert!(leaf_weak.upgrade().is_none());
}
#[test]
fn borrowed_parent_is_not_cached_but_retains_children() {
let leaf = make_stats_leaf(10);
let weak = Arc::downgrade(&leaf);
let parent: Arc<dyn ExecutionPlan> =
Arc::new(CoalescePartitionsExec::new(Arc::clone(&leaf)));
let parent_key = cache_key(parent.as_ref(), None);
let ctx = StatisticsContext::new();
let _ = ctx
.compute(parent.as_ref(), &StatisticsArgs::new())
.unwrap();
assert!(
!ctx.cache.lock().statistics.contains_key(&parent_key),
"borrowed roots must not be memoized"
);
drop(parent);
drop(leaf);
assert!(weak.upgrade().is_some());
ctx.reset_cache();
assert!(weak.upgrade().is_none());
}
#[test]
fn borrowed_compute_hits_root_cached_by_compute_arc() {
let leaf = make_stats_leaf(10);
let ctx = StatisticsContext::new();
let args = StatisticsArgs::new();
let owned = ctx.compute_arc(&leaf, &args).unwrap();
let borrowed = ctx.compute(leaf.as_ref(), &args).unwrap();
assert!(Arc::ptr_eq(&owned, &borrowed));
}
#[test]
fn extension_cache_retains_plan_lifetime() {
let leaf = make_stats_leaf(10);
let weak = Arc::downgrade(&leaf);
let ctx = ctx_with(Arc::new(TagLeafProvider { rows: 10, tag: 7 }));
let _ = ctx
.compute_extended_arc(&leaf, &StatisticsArgs::new())
.unwrap();
ctx.cache.lock().statistics.clear();
drop(leaf);
assert!(weak.upgrade().is_some());
ctx.reset_cache();
assert!(weak.upgrade().is_none());
}
#[test]
fn reset_cache_clears_entries() {
let leaf = make_stats_leaf(10);
let ctx = StatisticsContext::new();
let _ = ctx.compute_arc(&leaf, &StatisticsArgs::new()).unwrap();
assert!(!ctx.cache.lock().statistics.is_empty());
ctx.reset_cache();
assert!(ctx.cache.lock().statistics.is_empty());
}
#[test]
fn partition_aware_provider_applies_per_partition() {
let leaf = make_stats_leaf(10);
let ctx = ctx_with(Arc::new(PartitionRowCountProvider));
let per_part = ctx
.compute(
leaf.as_ref(),
&StatisticsArgs::new().with_partition(Some(0)),
)
.unwrap();
assert_eq!(per_part.num_rows, Precision::Exact(701));
}
#[test]
fn extensions_reach_parent_provider() {
let leaf = make_stats_leaf(100);
let parent: Arc<dyn ExecutionPlan> = Arc::new(CoalescePartitionsExec::new(leaf));
let ctx = StatisticsContext::new_with_registry(
StatisticsRegistry::with_providers(vec![
Arc::new(TagLeafProvider { rows: 100, tag: 7 }),
Arc::new(TagDoublingProvider),
]),
);
let extended = ctx
.compute_extended(parent.as_ref(), &StatisticsArgs::new())
.unwrap();
assert_eq!(extended.get_extension::<Tag>(), Some(&Tag(14)));
}
#[test]
fn cached_node_keeps_extensions() {
let leaf = make_stats_leaf(100);
let parent: Arc<dyn ExecutionPlan> =
Arc::new(CoalescePartitionsExec::new(Arc::clone(&leaf)));
let ctx = ctx_with(Arc::new(TagLeafProvider { rows: 100, tag: 7 }));
let _ = ctx
.compute(parent.as_ref(), &StatisticsArgs::new())
.unwrap();
let first = ctx
.compute_extended(leaf.as_ref(), &StatisticsArgs::new())
.unwrap();
let second = ctx
.compute_extended(leaf.as_ref(), &StatisticsArgs::new())
.unwrap();
assert_eq!(first.get_extension::<Tag>(), Some(&Tag(7)));
assert_eq!(second.get_extension::<Tag>(), Some(&Tag(7)));
assert!(Arc::ptr_eq(first.base_arc(), second.base_arc()));
}
#[test]
fn walk_returns_provider_extensions_directly() {
let leaf = make_stats_leaf(100);
let ctx = ctx_with(Arc::new(TagLeafProvider { rows: 100, tag: 7 }));
let args = StatisticsArgs::new();
let (_, extensions) = ctx
.compute_base(leaf.as_ref(), Some(&leaf), &args, false)
.unwrap();
assert_eq!(extensions.unwrap().get::<Tag>(), Some(&Tag(7)));
assert!(
ctx.cache
.lock()
.extensions
.contains_key(&cache_key(leaf.as_ref(), None))
);
let (_, extensions) = ctx
.compute_base(leaf.as_ref(), Some(&leaf), &args, false)
.unwrap();
assert!(extensions.is_none());
let (_, extensions) = ctx
.compute_base(leaf.as_ref(), Some(&leaf), &args, true)
.unwrap();
assert_eq!(extensions.unwrap().get::<Tag>(), Some(&Tag(7)));
}
#[test]
fn builtin_fallback_drops_extensions() {
let leaf = make_stats_leaf(100);
let parent: Arc<dyn ExecutionPlan> =
Arc::new(CoalescePartitionsExec::new(Arc::clone(&leaf)));
let ctx = ctx_with(Arc::new(TagLeafProvider { rows: 100, tag: 7 }));
let leaf_extended = ctx
.compute_extended(leaf.as_ref(), &StatisticsArgs::new())
.unwrap();
assert_eq!(leaf_extended.get_extension::<Tag>(), Some(&Tag(7)));
let parent_extended = ctx
.compute_extended(parent.as_ref(), &StatisticsArgs::new())
.unwrap();
assert_eq!(parent_extended.get_extension::<Tag>(), None);
assert_eq!(parent_extended.base().num_rows, Precision::Exact(100));
}
#[test]
fn per_partition_union_with_registry_no_out_of_bounds() {
let union =
UnionExec::try_new(vec![make_stats_leaf(10), make_stats_leaf(20)]).unwrap();
let ctx = ctx_with(Arc::new(FixedRowCountProvider(999)));
let p3 = ctx
.compute(
union.as_ref(),
&StatisticsArgs::new().with_partition(Some(3)),
)
.unwrap();
assert_eq!(p3.num_rows, Precision::Absent);
let overall = ctx.compute(union.as_ref(), &StatisticsArgs::new()).unwrap();
assert_eq!(overall.num_rows, Precision::Exact(999));
}
#[test]
fn per_partition_fetch_keeps_exactness_only_for_exact_counts() -> Result<()> {
let schema = Schema::new(vec![Field::new("a", DataType::Int32, true)]);
let fetch_10_of_4 = |num_rows| {
let mut input = Statistics::new_unknown(&schema);
input.num_rows = num_rows;
input.column_statistics[0].null_count = Precision::Exact(3);
with_per_partition_fetch(input, Some(10), 4, &StatisticsArgs::new())
};
let exact = fetch_10_of_4(Precision::Exact(8))?;
assert_eq!(exact.num_rows, Precision::Exact(8));
assert_eq!(exact.column_statistics[0].null_count, Precision::Exact(3));
let estimate = fetch_10_of_4(Precision::Inexact(8))?;
assert_eq!(estimate.num_rows, Precision::Inexact(8));
assert_eq!(
estimate.column_statistics[0].null_count,
Precision::Inexact(3)
);
Ok(())
}
#[test]
fn per_partition_fetch_counts_every_partition() -> Result<()> {
let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
let overall = StatisticsArgs::new();
let first_partition = StatisticsArgs::new().with_partition(Some(0));
let num_rows = |input_rows, fetch, n_partitions, args: &StatisticsArgs| {
let mut input = Statistics::new_unknown(&schema);
input.num_rows = input_rows;
with_per_partition_fetch(input, fetch, n_partitions, args)
.map(|stats| stats.num_rows)
};
assert_eq!(
num_rows(Precision::Exact(400), Some(10), 4, &overall)?,
Precision::Inexact(40)
);
assert_eq!(
num_rows(Precision::Exact(25), Some(10), 4, &overall)?,
Precision::Inexact(25)
);
assert_eq!(
num_rows(Precision::Exact(8), Some(10), 4, &overall)?,
Precision::Exact(8)
);
assert_eq!(
num_rows(Precision::Absent, Some(10), 4, &overall)?,
Precision::Inexact(40)
);
assert_eq!(
num_rows(Precision::Exact(100), Some(10), 4, &first_partition)?,
Precision::Exact(10)
);
assert_eq!(
num_rows(Precision::Exact(400), Some(10), 1, &overall)?,
Precision::Exact(10)
);
assert_eq!(
num_rows(Precision::Exact(400), None, 4, &overall)?,
Precision::Exact(400)
);
Ok(())
}
}