feat(rust/sedona-expr): Add GroupsAccumulator to framework and implementation for ST_Envelope_Agg#510
Merged
paleolimbot merged 11 commits intoapache:mainfrom Jan 16, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements GroupsAccumulator support for aggregate functions in the Sedona Rust framework, specifically implementing it for ST_Envelope_Agg(). The GroupsAccumulator is a performance optimization in DataFusion for efficiently aggregating many small groups.
Changes:
- Extended the
SedonaAccumulatortrait with optionalgroups_accumulator_supported()andgroups_accumulator()methods - Implemented
BoundsGroupsAccumulator2DforST_Envelope_Agg()to optimize grouped aggregations - Enhanced
AggregateUdfTesterwithaggregate_groups()method to test groups accumulator functionality
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| rust/sedona-testing/src/testers.rs | Added aggregate_groups() method and refactored shared schema/expression initialization |
| rust/sedona-functions/src/st_envelope_agg.rs | Implemented BoundsGroupsAccumulator2D and added comprehensive grouped aggregation tests |
| rust/sedona-expr/src/aggregate_udf.rs | Added groups_accumulator_supported() and create_groups_accumulator() to the UDF framework |
| python/sedonadb/tests/functions/test_aggregate.py | Added integration tests for ST_Envelope_Agg including grouped aggregations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Member
|
Did you see any performance gain from this? |
Member
Author
|
For this particular example (ST_Envelope) it's hugely beneficial: import sedona.db
sd = sedona.db.connect()
# 10 million points
sd.sql("""SELECT * FROM sd_random_geometry('{"target_rows": 10000000}')""").to_memtable().to_view("pts")
# pip install --pre --force-reinstall sedonadb --extra-index-url=https://repo.fury.io/sedona-nightlies/
%time sd.sql("""SELECT ST_Envelope_Agg(geometry) as e FROM pts GROUP BY id % 1000""").execute()
%time sd.sql("""SELECT ST_Envelope_Agg(geometry) as e FROM pts GROUP BY id % 10000""").execute()
%time sd.sql("""SELECT ST_Envelope_Agg(geometry) as e FROM pts GROUP BY id % 100000""").execute()
#> CPU times: user 885 ms, sys: 29.9 ms, total: 915 ms
#> Wall time: 95.7 ms
#> CPU times: user 1.03 s, sys: 13.5 ms, total: 1.04 s
#> Wall time: 99.2 ms
#> CPU times: user 15.8 s, sys: 146 ms, total: 15.9 s
#> Wall time: 1.44 s
# pip install python/sedonadb
%time sd.sql("""SELECT ST_Envelope_Agg(geometry) as e FROM pts GROUP BY id % 1000""").execute()
%time sd.sql("""SELECT ST_Envelope_Agg(geometry) as e FROM pts GROUP BY id % 10000""").execute()
%time sd.sql("""SELECT ST_Envelope_Agg(geometry) as e FROM pts GROUP BY id % 100000""").execute()
#> CPU times: user 283 ms, sys: 34.6 ms, total: 317 ms
#> Wall time: 43.1 ms
#> CPU times: user 238 ms, sys: 7.81 ms, total: 246 ms
#> Wall time: 25.7 ms
#> CPU times: user 407 ms, sys: 58 ms, total: 465 ms
#> Wall time: 44.5 ms |
Member
|
Great work! |
Kontinuation
approved these changes
Jan 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allows aggregate functions implemented using the
SedonaAccumulatorto implement their ownGroupsAccumulator(which they should usually do for performance on tiny groups). This also implements one forST_Envelope_Agg()and the appropriate extension to theAggregateUdfTester(since I couldn't seem to trigger all the features of theGroupsAccumulatorreliably with simple queries).This would also benefit other aggregate functions (but they would require that implementation to exist and it might take a bit).
Closes #167.