[GH-2830] Adds Geography dual-dispatch to ST_Centroid#2852
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Geography support for ST_Centroid via dual-dispatch so Geography inputs return a Geography point (planar centroid computed in projected lon/lat space), aligning Spark SQL behavior with the new common geography function set introduced in the Geography workstream.
Changes:
- Add
org.apache.sedona.common.geography.Functions.centroid(Geography)and corresponding unit tests. - Update Spark SQL
ST_Centroidexpression to dual-dispatch between Geometry and Geography implementations. - Add Spark SQL integration coverage + new Geography SQL docs entry for
ST_Centroid.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala | Adds Geography overload to ST_Centroid via InferredExpression dual-dispatch. |
| common/src/main/java/org/apache/sedona/common/geography/Functions.java | Introduces Geography centroid implementation (JTS getCentroid() + wrap to WKBGeography). |
| common/src/test/java/org/apache/sedona/common/Geography/FunctionTest.java | Adds unit tests for Geography centroid behavior and null handling. |
| spark/common/src/test/scala/org/apache/sedona/sql/geography/GeographyFunctionTest.scala | Adds Spark SQL integration test for Geography centroid (currently uses an incompatible formatter). |
| docs/api/sql/geography/Geography-Functions/ST_Centroid.md | Adds Geography SQL doc page for ST_Centroid (example currently uses an incompatible formatter). |
| docs/api/sql/geography/Geography-Functions.md | Adds ST_Centroid to the Geography functions index table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…upport.st_centroid
|
@zhangfengcdt Are you sure this should go back to JTS and use planar geometry to get the centroid? Does S2 have something spherical? |
S2 returns weighted (non-unit) centroids; final step normalizes via S2PAoint.normalize. Returns null if the centroid is undefined (empty input or vectors that cancel).
…upport.st_centroid
…upport.st_centroid
Yes, you're right! I switched it to S2, need a bit more work on that though - S2 returns a non-unit weighted vector, so the result is normalized via S2Point.normalize before being wrapped as SinglePointGeography. |
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes #<issue_number>What changes were proposed in this PR?
How was this patch tested?
Did this PR include necessary documentation updates?