feat(query): Support Geometry aggregate functions#19620
feat(query): Support Geometry aggregate functions#19620b41sh wants to merge 2 commits intodatabendlabs:mainfrom
Conversation
🤖 CI Job Analysis (Retry 1)
📊 Summary
❌ NO RETRY NEEDEDAll failures appear to be code/test issues requiring manual fixes. 🔍 Job Details
🤖 AboutAutomated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed). |
e20d6f7 to
8cb2f1f
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds new spatial (Geometry/Geography) scalar and aggregate functions and introduces a shared overlay/aggregation implementation in the expression layer, with updated output formatting and extensive test coverage updates.
Changes:
- Add Geometry/Geography overlay-based scalar functions (centroid/envelope/union/intersection/difference/symdifference and boolean predicates) and new aggregates (union/intersection/envelope/collect).
- Introduce a geography projection model (best-SRID selection + project/overlay/unproject with coordinate rounding) and a unified aggregate implementation for spatial types.
- Update result formatting/serialization (notably Geography EWKT/EWKB) and refresh SQL logic + golden test outputs accordingly.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| THIRD-PARTY-NOTICES.txt | Adds third-party license notices/text for adapted GEOS/PostGIS-derived components. |
| tests/sqllogictests/suites/query/functions/02_0076_function_geography.test | Updates Geography outputs (EWKT includes SRID) and adds new scalar/aggregate test cases. |
| tests/sqllogictests/suites/query/functions/02_0060_function_geometry.test | Adds new Geometry scalar/aggregate test cases. |
| src/query/service/src/servers/http/v1/query/blocks_serializer.rs | Adjusts HTTP result serialization for Geography, forcing SRID=4326 for EWKT/EWKB. |
| src/query/functions/tests/it/scalars/testdata/geometry.txt | Updates golden outputs and adds coverage for new Geometry scalar functions. |
| src/query/functions/tests/it/scalars/testdata/function_list.txt | Registers new function overloads in the golden function list. |
| src/query/functions/tests/it/scalars/geometry.rs | Adds scalar integration tests for new Geometry functions. |
| src/query/functions/tests/it/scalars/geography.rs | Adds scalar integration tests for new Geography functions/predicates. |
| src/query/functions/tests/it/aggregates/testdata/agg.txt | Adds aggregate golden outputs for new spatial aggregates (incl. Geography). |
| src/query/functions/tests/it/aggregates/testdata/agg_group_by.txt | Adds group-by aggregate golden outputs for new spatial aggregates. |
| src/query/functions/tests/it/aggregates/agg.rs | Adds aggregate test cases and new sample datasets for spatial aggregates. |
| src/query/functions/src/scalars/geographic/src/register.rs | Introduces shared registration helpers for Geometry/Geography scalar functions and SRID checks. |
| src/query/functions/src/scalars/geographic/src/lib.rs | Wires in the new scalar registration module. |
| src/query/functions/src/aggregates/mod.rs | Switches spatial aggregates to the new unified aggregate module. |
| src/query/functions/src/aggregates/aggregator.rs | Registers new spatial aggregate functions in the aggregate factory. |
| src/query/functions/src/aggregates/aggregate_st_collect.rs | Removes the old Geometry-only st_collect aggregate implementation. |
| src/query/functions/src/aggregates/aggregate_geographic_agg.rs | Adds unified spatial aggregates: st_collect, st_union_agg, st_intersection_agg, st_envelope_agg. |
| src/query/formats/src/field_encoder/values.rs | Updates Geography field encoding for text/CSV/etc output formats (SRID handling for EWKT/EWKB). |
| src/query/expression/src/utils/display.rs | Adjusts internal scalar display formatting for Geography (via ToGeo + WKT). |
| src/query/expression/src/lib.rs | Exposes the new geographic module from the expression crate. |
| src/query/expression/src/geographic/mod.rs | Adds the expression-layer geographic module wiring. |
| src/query/expression/src/geographic/srid.rs | Adds best-SRID selection and projection/unprojection with rounding for Geography overlay execution. |
| src/query/expression/src/geographic/gbox.rs | Adds geocentric bounds (gbox) computations used for best-SRID selection. |
| src/query/expression/src/geographic/aggregate.rs | Adds overlay-based aggregate ops used by both scalar and aggregate functions. |
| src/query/expression/Cargo.toml | Adds proj4rs dependency for projection support. |
| src/common/io/src/lib.rs | Re-exports new geography formatting helper(s). |
| src/common/io/src/geometry.rs | Adds rect_to_polygon helper used by envelope-related ops. |
| src/common/io/src/geography.rs | Adds geography_format helper for consistent Geography formatting across output types. |
| Cargo.toml | Bumps geo-index and proj4rs workspace dependency versions. |
| Cargo.lock | Updates lockfile entries for the bumped/added dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
be3f973 to
a8d32fe
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a8d32fe170
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 29 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a8d32fe to
d376bba
Compare
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
This PR introduces
geometryscalar and aggregate functions, implements a consistent overlay pipeline forunion/intersection/difference.New Functions
Scalar Functions
st_centroid— returns the centroid of a geometry/geography.st_envelope— returns the bounding rectangle as a polygon.st_union— returns the union of two geometries/geographies.st_intersection— returns the intersection of two geometries/geographies.st_difference— returns the portion of the first geometry/geography not in the second.st_symdifference— returns the symmetric difference of two geometries/geographies.Aggregate Functions
st_union_agg— unions all input geometries/geographies into one.st_intersection_agg— intersects all input geometries/geographies into one.st_envelope_agg— returns a bounding polygon for all inputs.st_collect— collects inputs into aMulti*orGeometryCollection.Union,IntersectionandDifferenceoverlay operations detailspoints/lines/polygons), performsunion/intersection/difference/symdifferenceand assembles the result as a unified geometry (Multi*when homogenous,GeometryCollectionwhen mixed).fixes: #[Link the issue here]
Tests
Type of change
This change is