Class PushStatsToExternalSource


public class PushStatsToExternalSource extends PhysicalOptimizerRules.OptimizerRule<AggregateExec>
Pushes ungrouped aggregate functions (COUNT, MIN, MAX) to external sources when the required statistics are available in the file metadata. Replaces the AggregateExec + ExternalSourceExec subtree with a LocalSourceExec containing pre-computed results.

Handles intermediate EvalExec (from EVAL) and ProjectExec (from RENAME) nodes between the aggregate and external source by resolving aliased attribute names back to the original column names before metadata lookup.

Supports multi-split queries when per-split statistics are available in FileSplit.statistics(). Statistics are merged across splits (sum row counts, min-of-mins, max-of-maxes). Falls back to normal execution when any split lacks stats.

Note: MIN/MAX pushdown uses raw values from file metadata. For DATE/TIMESTAMP columns, the raw values may not match ESQL's millisecond representation. A future enhancement should convert these values using the column's data type.