Skip to main content

StatisticsProvider

Trait StatisticsProvider 

Source
pub trait StatisticsProvider:
    Debug
    + Send
    + Sync {
    // Required method
    fn compute_statistics(
        &self,
        plan: &(dyn ExecutionPlan + 'static),
        child_stats: &[ExtendedStatistics],
    ) -> Result<StatisticsResult, DataFusionError>;
}
Expand description

Customize statistics computation for ExecutionPlan nodes.

Implementations can handle specific operator types or override default estimation logic. The chain of providers is traversed until one returns StatisticsResult::Computed.

§Implementing a Custom Provider

ⓘ
#[derive(Debug)]
struct MyStatisticsProvider;

impl StatisticsProvider for MyStatisticsProvider {
    fn compute_statistics(
        &self,
        plan: &dyn ExecutionPlan,
        child_stats: &[ExtendedStatistics],
    ) -> Result<StatisticsResult> {
        if let Some(my_exec) = plan.downcast_ref::<MyCustomExec>() {
            // Custom logic for MyCustomExec
            Ok(StatisticsResult::Computed(/* ... */))
        } else {
            // Let next provider handle it
            Ok(StatisticsResult::Delegate)
        }
    }
}

Required Methods§

Source

fn compute_statistics( &self, plan: &(dyn ExecutionPlan + 'static), child_stats: &[ExtendedStatistics], ) -> Result<StatisticsResult, DataFusionError>

Compute statistics for an ExecutionPlan node.

§Arguments
  • plan - The execution plan node to compute statistics for
  • child_stats - Extended statistics already computed for child nodes, in the same order as plan.children(). Empty for leaf nodes.
§Returns
  • StatisticsResult::Computed(stats) - Short-circuits the chain
  • StatisticsResult::Delegate - Passes to next provider in chain

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§