Skip to content

[GH-3075] Add geography support to SedonaFlink spatial predicates#3077

Merged
jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:flink-geography-predicates
Jun 21, 2026
Merged

[GH-3075] Add geography support to SedonaFlink spatial predicates#3077
jiayuasu merged 2 commits into
apache:masterfrom
jiayuasu:flink-geography-predicates

Conversation

@jiayuasu

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

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 Geography support to the SedonaFlink spatial predicates, so geography columns can be compared, not just constructed and measured. Each of the following gains a Geography eval overload in flink/.../expressions/Predicates.java, delegating to org.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 RAW bridgedTo type, so a single registered name serves both types and no new Catalog entries are required.

This mirrors Spark, where these predicates accept either Geometry or Geography.

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 common S2 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 for ST_Intersects/ST_Equals/ST_DWithin), plus testGeometryStillWorks confirming the geometry overload still resolves on the shared predicate. No regressions: the geometry PredicateTest (22 tests) and ModuleTest pass.

Did this PR include necessary documentation updates?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Geography overloads for ST_Intersects, ST_Contains, ST_Within, ST_Equals, and ST_DWithin in Predicates.java, delegating to org.apache.sedona.common.geography.Functions.
  • Introduced GeographyPredicateTest to 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.

Comment on lines 198 to +202
return org.apache.sedona.common.Predicates.within(geom1, geom2);
}

@DataTypeHint("Boolean")
public Boolean eval(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment on lines 328 to +332
return org.apache.sedona.common.Predicates.equals(geom1, geom2);
}

@DataTypeHint("Boolean")
public Boolean eval(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added the same NULL guard to ST_Equals geometry overload for consistent NULL propagation across the predicate family. Commit 0ffb38e.

@jiayuasu jiayuasu merged commit ec7846c into apache:master Jun 21, 2026
19 checks passed
@jiayuasu jiayuasu added this to the sedona-1.9.1 milestone Jun 21, 2026
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.

SedonaFlink: add geography support to spatial predicates

2 participants