Skip to content

docs: add DataFrame aggregation example (select vs aggregate) #26597

Description

@cj-zhukov

Is your feature request related to a problem or challenge?

Follow-up to #25482 (closes #17874), which allowed aggregate functions in DataFrame::select. That PR added tests but no examples, and the examples were left for a follow-up.

Right now datafusion-examples has no example about aggregation with the DataFrame API. aggregate(vec![], ...) only shows up inside other examples (subqueries, UDAFs), and nothing shows the new select form. A user reading the examples will not find out that select(vec![count(col("a")), sum(col("b"))]) works, or when they still need aggregate.

Describe the solution you'd like

Add a new aggregate example to the dataframe group in datafusion-examples (cargo run --example dataframe -- aggregate) that shows, side by side:

  • global aggregation with aggregate(vec![], aggs) and with select(aggs) — same result
    expressions on top of aggregates (for example max(speed) - min(speed)) the old way (aggregate then select with aliases) and the new way (one select)
  • grouped aggregation, which still uses aggregate(group_by, aggs), and a note that select does not infer a GROUP BY
  • the difference between an aggregate in select (one row) and a window function in select (one row per input row)

Plus generated row in the examples README.

Describe alternatives you've considered

Adding the examples to dataframe/dataframe.rs. That file is already long and covers reading/writing data, so a separate example is easier to find.

Additional context

#25482 — the PR that added aggregate support to select
#21021 — the first attempt, which included a version of these examples

Willingness to contribute

I plan to contribute to this feature independently

Activity

  1. cj-zhukov commented on Oct 22, 2026

    @cj-zhukov
    ContributorAuthor

    take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions