[GH-3075] Add geography support to SedonaFlink spatial predicates#3077
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Geography parity for SedonaFlink spatial predicates by introducing Geography-typed overloads for key predicate UDFs and validating behavior end-to-end via new Flink Table API tests.
Changes:
- Added
Geographyoverloads forST_Intersects,ST_Contains,ST_Within,ST_Equals, andST_DWithininPredicates.java, delegating toorg.apache.sedona.common.geography.Functions. - Introduced
GeographyPredicateTestto exercise the new overloads through the Flink Table API and confirm geometry overload resolution still works.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| flink/src/main/java/org/apache/sedona/flink/expressions/Predicates.java | Adds Geography overloads for core spatial predicates using RAW type hints and GeographyTypeSerializer. |
| flink/src/test/java/org/apache/sedona/flink/GeographyPredicateTest.java | Adds end-to-end predicate tests for Geography and verifies geometry overload selection remains intact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return org.apache.sedona.common.Predicates.within(geom1, geom2); | ||
| } | ||
|
|
||
| @DataTypeHint("Boolean") | ||
| public Boolean eval( |
There was a problem hiding this comment.
Added the NULL guard to ST_Within geometry overload (if (o1 == null || o2 == null) return null;), matching ST_Intersects/ST_Contains/ST_DWithin and the new geography overloads. Commit 0ffb38e.
| return org.apache.sedona.common.Predicates.equals(geom1, geom2); | ||
| } | ||
|
|
||
| @DataTypeHint("Boolean") | ||
| public Boolean eval( |
There was a problem hiding this comment.
Added the same NULL guard to ST_Equals geometry overload for consistent NULL propagation across the predicate family. Commit 0ffb38e.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes SedonaFlink: add geography support to spatial predicates #3075.What changes were proposed in this PR?
Part of the geography parity effort for SedonaFlink (#3054), building on the type serializer (#3058), constructors (#3061), and functions (#3073).
This adds
Geographysupport to the SedonaFlink spatial predicates, so geography columns can be compared, not just constructed and measured. Each of the following gains aGeographyevaloverload inflink/.../expressions/Predicates.java, delegating toorg.apache.sedona.common.geography.Functions:ST_Intersects(geog, geog)ST_Contains(geog, geog)ST_Within(geog, geog)ST_Equals(geog, geog)ST_DWithin(geog, geog, distanceMeters)Each overload uses
@DataTypeHint(value = "RAW", rawSerializer = GeographyTypeSerializer.class, bridgedTo = Geography.class)and propagates SQL NULL the same way the existing geometry overloads do. Flink resolves geometry vs geography by the RAWbridgedTotype, so a single registered name serves both types and no newCatalogentries are required.This mirrors Spark, where these predicates accept either
GeometryorGeography.Note on semantics: geography polygons follow the spherical right-hand rule — a CCW ring's interior is the enclosed region; a CW ring denotes the complementary region on the sphere. This is inherited from the
commonS2 layer and matches Spark.How was this patch tested?
Added
GeographyPredicateTest(6 tests) exercising each predicate end-to-end through the Flink Table API (true and false cases forST_Intersects/ST_Equals/ST_DWithin), plustestGeometryStillWorksconfirming the geometry overload still resolves on the shared predicate. No regressions: the geometryPredicateTest(22 tests) andModuleTestpass.Did this PR include necessary documentation updates?