Class PushStatsToExternalSource


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.

Supports both SINGLE and INITIAL modes. In SINGLE mode the replacement produces final-value blocks (one block per aggregate). In INITIAL mode the replacement produces intermediate-format blocks matching AggregateExec.intermediateAttributes(): for each aggregate, a typed value block followed by a seen boolean block.

Handles intermediate EvalExec (from EVAL), ProjectExec (from RENAME), and FilterExec nodes between the aggregate and external source by resolving aliased attribute names back to the original column names before metadata lookup, and by classifying filters against per-split statistics when present.

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

Substitution from metadata statistics is skipped when ExternalSourceExec carries ExternalSourceExec.pushedExpressions() or ExternalSourceExec.pushedFilter(): those predicates narrow the scanned rows; footer split stats do not reflect them after PushFiltersToSource removes the enclosing FilterExec.

Note: MIN/MAX pushdown uses values from file metadata. Temporal columns (DATE/TIMESTAMP/INT96) are decoded to ESQL's epoch-millisecond representation at stat-publication time by the format reader (see ParquetColumnDecoding#decodeTemporalStat), so the pushed values already match the scan path.