Class ReplaceSampledStatsBySampleAndStats


public class ReplaceSampledStatsBySampleAndStats extends PhysicalOptimizerRules.OptimizerRule<SampledAggregateExec>
If the original aggregate wrapped by the sampled aggregate cannot be pushed down to Lucene (which would execute exact and fast), sampling should be used to speed up the aggregation.

In that case, this rule replaces the sampled aggregate by a regular aggregate on top of a sample, with intermediate state corrections for sample-corrected aggregates (COUNT, SUM). The plan:

 FROM data | commands | SAMPLED_STATS[prob] aggs
 
is transformed into:
 FROM data | SAMPLE prob | commands | STATS aggs | EVAL sample_correction