Refine and document AggregateExec metrics (#24757)

## Which issue does this PR close?

* Part of #23570

## Rationale for this change

Aggregate-specific metrics are a user-visible observability surface in
`EXPLAIN ANALYZE`, but their phase boundaries and relationship to
individual aggregate expressions need to be clear and consistent.

In particular, users should be able to understand what each aggregate
timer measures, map indexed metrics such as `agg_expr_0_arguments_time`
back to the corresponding expression in the operator's `aggr=[...]`
list, and understand which metrics are available on different grouped
aggregation paths without reading the implementation.

This PR also tightens the timing boundaries of the grouped aggregate
metrics so that the documented metrics correspond more directly to the
work they describe.

## What changes are included in this PR?

* Documents `AggregateExec` operator-level and per-aggregate metrics,
including their phase boundaries, indexed naming convention, aggregate
expression labels, visibility, and path-specific coverage.
* Groups aggregate timing into explicit phases for:

  * group-key preparation,
  * aggregate argument and filter evaluation,
  * accumulator `update` / `merge` operations, and
  * output emission.
* Ensures accumulator `aggregation_time` measures a single interval
containing the relevant accumulator operations rather than accumulating
overlapping/prefix timing.
* Includes group interning and ordering setup in
`time_calculating_group_ids`.
* Includes collectively evaluated aggregate filters in
`aggregate_arguments_time`.
* Adds `topk_maintenance_time` for Grouped TopK priority-map maintenance
and avoids registering `aggregation_time` for that accumulator-free
path.
* Times grouped output materialization consistently with
`emitting_time`.
* Adds `EXPLAIN ANALYZE` coverage demonstrating how indexed
per-aggregate metrics map to multiple aggregate expressions and how
expression labels appear in verbose output.

## Are these changes tested?

Yes.

The patch adds and updates tests that verify:

* `EXPLAIN ANALYZE` reports `agg_expr_0_arguments_time`,
`agg_expr_1_arguments_time`, and `agg_expr_2_arguments_time` for a query
containing `SUM(c5)`, `SUM(c6)`, and `COUNT(c7)`.
* `EXPLAIN ANALYZE VERBOSE` associates those indexed metrics with the
corresponding rendered aggregate expressions.
* Grouped TopK reports `topk_maintenance_time` and
`time_calculating_group_ids` while not registering `aggregation_time`.
* Regular aggregate paths do not report `topk_maintenance_time`.
* Aggregate execution without grouped emission does not report
`emitting_time`.
* `GroupByMetrics::new_topk` does not register `aggregation_time`.

## Are there any user-facing changes?

Yes. Aggregate metrics shown through `EXPLAIN ANALYZE` are clarified and
their timing boundaries are made more consistent.

The metrics documentation now describes the `AggregateExec`
operator-level metrics and per-expression timer phases, explains how
indexed metrics map to aggregate expressions, and documents
path-specific differences such as Grouped TopK and non-grouped
aggregation.

These are observability and documentation changes; this PR does not
introduce a public API change.

## LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed.
9 files changed
tree: 7189ac319223aac906132eee522eaa6f34ad12e1
  1. .ai/
  2. .cargo/
  3. .devcontainer/
  4. .github/
  5. benchmarks/
  6. ci/
  7. datafusion/
  8. datafusion-cli/
  9. datafusion-examples/
  10. dev/
  11. docs/
  12. python/
  13. test-utils/
  14. xtask/
  15. .asf.yaml
  16. .dockerignore
  17. .editorconfig
  18. .gitattributes
  19. .gitignore
  20. .gitmodules
  21. AGENTS.md
  22. Cargo.lock
  23. Cargo.toml
  24. CHANGELOG.md
  25. clippy.toml
  26. CODE_OF_CONDUCT.md
  27. CONTRIBUTING.md
  28. doap.rdf
  29. LICENSE.txt
  30. licenserc.toml
  31. lychee.toml
  32. NOTICE.txt
  33. pre-commit.sh
  34. pyproject.toml
  35. README.md
  36. rust-toolchain.toml
  37. rustfmt.toml
  38. taplo.toml
  39. typos.toml
  40. uv.lock
README.md

Apache DataFusion

Crates.io Apache licensed Build Status Commit Activity Open Issues Pending PRs Discord chat Linkedin Crates.io MSRV Codecov

Website | API Docs | Chat

DataFusion is an extensible query engine written in Rust that uses Apache Arrow as its in-memory format.

This crate provides libraries and binaries for developers building fast and feature-rich database and analytic systems, customized for particular workloads. See use cases for examples. The following related subprojects target end users:

“Out of the box,” DataFusion offers SQL and DataFrame APIs, excellent performance, built-in support for CSV, Parquet, JSON, and Avro, extensive customization, and a great community.

DataFusion features a full query planner, a columnar, streaming, multi-threaded, vectorized execution engine, and partitioned data sources. You can customize DataFusion at almost all points including additional data sources, query languages, functions, custom operators and more. See the Architecture section for more details.

Here are links to important resources:

What can you do with this crate?

DataFusion is great for building projects such as domain-specific query engines, new database platforms and data pipelines, query languages and more. It lets you start quickly from a fully working engine, and then customize those features specific to your needs. See the list of known users.

Contributing to DataFusion

Please see the contributor guide and communication pages for more information.

We discuss our roadmap via GitHub issues and invite you to join the conversation. The current discussion is the DataFusion 2026 Q3-Q4 Roadmap Discussion.

Crate features

This crate has several features which can be specified in your Cargo.toml.

Default features:

  • nested_expressions: functions for working with nested types such as array_to_string
  • compression: reading files compressed with xz2, bzip2, flate2, and zstd
  • crypto_expressions: cryptographic functions such as md5 and sha256
  • datetime_expressions: date and time functions such as to_timestamp
  • encoding_expressions: encode and decode functions
  • parquet: support for reading the Apache Parquet format
  • sql: support for SQL parsing and planning
  • regex_expressions: regular expression functions, such as regexp_match
  • unicode_expressions: include Unicode-aware functions such as character_length
  • unparser: enables support to reverse LogicalPlans back into SQL
  • recursive_protection: uses recursive for stack overflow protection.

Optional features:

  • avro: support for reading the Apache Avro format
  • backtrace: include backtrace information in error messages
  • parquet_encryption: support for using Parquet Modular Encryption
  • serde: enable arrow-schema's serde feature

DataFusion API Evolution and Deprecation Guidelines

Public methods in Apache DataFusion evolve over time: while we try to maintain a stable API, we also improve the API over time. As a result, we typically deprecate methods before removing them, according to the deprecation guidelines.

Dependencies and Cargo.lock

Following the guidance on committing Cargo.lock files, this project commits its Cargo.lock file.

CI uses the committed Cargo.lock file, and dependencies are updated regularly using Dependabot PRs.