Skip to content

Comments

fix(rust/sedona-functions): Ensure WkbView types can be aggregated using the groups accumulator for ST_Envelope_Agg#656

Open
paleolimbot wants to merge 3 commits intoapache:mainfrom
paleolimbot:envelope-agg-issue
Open

fix(rust/sedona-functions): Ensure WkbView types can be aggregated using the groups accumulator for ST_Envelope_Agg#656
paleolimbot wants to merge 3 commits intoapache:mainfrom
paleolimbot:envelope-agg-issue

Conversation

@paleolimbot
Copy link
Member

Fixes the aggregation from a view type: we had been assuming that the state was identical to the input; however, this is not the case if the input is a view type for the grouped accumulator.

import sedona.db 

sd = sedona.db.connect()

url = "https://github.com/geoarrow/geoarrow-data/releases/download/v0.2.0/ns-water_water-point.parquet"
sd.read_parquet(url).to_view("pts")

sd.sql("""SELECT COUNT(*) AS n, ST_Envelope_Agg(geometry) FROM pts GROUP BY "FEAT_CODE" """).show()
#> ┌───────┬──────────────────────────────────────────────────────────────────────────────────────────┐
#> │   n   ┆                               st_envelope_agg(pts.geometry)                              │
#> │ int64 ┆                                         geometry                                         │
#> ╞═══════╪══════════════════════════════════════════════════════════════════════════════════════════╡
#> │    90 ┆ POLYGON((270897.72809999995 4826136.883300001,270897.72809999995 5187201.8673,701852.51… │
#> ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
#> │     1 ┆ POINT(421205.36319999956 4983412.968)                                                    │
#> ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
#> │   193 ┆ POLYGON((267934.5273000002 4851581.779999999,267934.5273000002 5169404.282400001,671731… │
#> ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
#> │ 44406 ┆ POLYGON((228998.02589999977 4807909.8791000005,228998.02589999977 5234453.594900001,758… │
#> └───────┴──────────────────────────────────────────────────────────────────────────────────────────┘

Closes #653.

@paleolimbot paleolimbot marked this pull request as ready for review February 24, 2026 04:01
@paleolimbot paleolimbot changed the title fix(rust/sedona-functions): Ensure WkbView types can be aggregated using the groups accumulator fix(rust/sedona-functions): Ensure WkbView types can be aggregated using the groups accumulator for ST_Envelope_Agg Feb 24, 2026
@paleolimbot paleolimbot requested a review from Copilot February 24, 2026 04:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in ST_Envelope_Agg where grouped aggregation would fail when the input geometry was stored as a view type (WkbView). The root cause was that the merge_batch method incorrectly assumed the state type was identical to the input type, when in fact the state is always represented as WKB_GEOMETRY regardless of the input type.

Changes:

  • Added sentinel constants for view geometry types with item CRS to support testing and type handling
  • Modified the execute_update method to accept an explicit input_type parameter, distinguishing between input and state types
  • Updated merge_batch to always use WKB_GEOMETRY for state deserialization, consistent with other aggregate functions

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
rust/sedona-schema/src/datatypes.rs Added WKB_VIEW_GEOMETRY_ITEM_CRS and WKB_VIEW_GEOGRAPHY_ITEM_CRS sentinel constants for view types with item CRS metadata
rust/sedona-functions/src/st_envelope_agg.rs Fixed merge_batch to use WKB_GEOMETRY for state and parameterized execute_update to handle input type separately; added comprehensive tests for view types
python/sedonadb/tests/functions/test_aggregate.py Added integration test with real-world parquet data to verify grouped aggregation works with view types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rust/sedona-functions: Grouped ST_Envelope_Agg can fail

1 participant