Skip to content

[GH-3061] Add geography constructors to SedonaFlink#3062

Open
jiayuasu wants to merge 1 commit into
apache:masterfrom
jiayuasu:flink-geography-constructors
Open

[GH-3061] Add geography constructors to SedonaFlink#3062
jiayuasu wants to merge 1 commit into
apache:masterfrom
jiayuasu:flink-geography-constructors

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?

This is the second step toward Geography type support in SedonaFlink (#3054), building on the GeographyTypeSerializer added in #3058.

It exposes the geography constructor/conversion functions to the Flink Table API / SQL, reaching parity with the 9 functions Spark already provides:

  • ST_GeogFromWKT (wkt, [srid])
  • ST_GeogFromText (wkt, [srid])
  • ST_GeogFromEWKT (ewkt)
  • ST_GeogCollFromText (wkt, [srid])
  • ST_GeogFromWKB (wkb, [srid])
  • ST_GeogFromEWKB (wkb)
  • ST_GeogFromGeoHash (geohash, [precision])
  • ST_GeogToGeometry (geography) → geometry
  • ST_GeomToGeography (geometry) → geography

Each is a ScalarFunction wrapper in a new expressions/GeographyConstructors.java (mirroring the dedicated geography package on the Spark side), delegating to org.apache.sedona.common.geography.Constructors with @DataTypeHint(value = "RAW", rawSerializer = GeographyTypeSerializer.class, bridgedTo = Geography.class). Optional-argument defaults match Spark (srid 0, geohash precision null). All 9 are registered in Catalog.java.

How was this patch tested?

Added GeographyConstructorTest (10 tests), exercising every function end-to-end through the Flink Table API — including geography↔geometry conversion round-trips. Because SedonaContext.create registers Catalog.getFuncs() as temporary system functions, the tests also verify the Catalog registration. mvn -pl flink test -Dtest=GeographyConstructorTest passes (10/10), and ModuleTest remains green.

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

This PR wires Sedona’s existing common-module Geography constructor/conversion APIs into SedonaFlink so they are usable from the Flink Table API / SQL, aiming for parity with Spark’s ST_Geog* constructor surface.

Changes:

  • Added flink Table API ScalarFunction wrappers for 9 geography constructor/conversion functions.
  • Registered the new ST_Geog* functions in flink’s Catalog so SedonaContext.create(...) can expose them as temporary system functions.
  • Added end-to-end Table API tests covering the new functions (including geography↔geometry conversions).

Reviewed changes

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

File Description
flink/src/main/java/org/apache/sedona/flink/expressions/GeographyConstructors.java New Flink ScalarFunction wrappers for geography constructors/conversions.
flink/src/main/java/org/apache/sedona/flink/Catalog.java Registers the new geography functions so they’re available via Flink SQL/Table API.
flink/src/test/java/org/apache/sedona/flink/GeographyConstructorTest.java Adds Table API tests to validate function behavior and registration.

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

Comment on lines +21 to +25
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.functions.ScalarFunction;
import org.apache.sedona.common.S2Geography.Geography;
import org.apache.sedona.common.geography.Constructors;
import org.apache.sedona.flink.GeographyTypeSerializer;
Comment on lines +126 to +132
Geometry point = new WKTReader().read("POINT (3 4)");
byte[] wkb = new WKBWriter().write(point);
Table src = sourceTable("wkb", wkb, PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO);
Geography result =
evalGeog(src, GeographyConstructors.ST_GeogFromEWKB.class.getSimpleName(), "wkb");
assertEquals(Constructors.geogFromWKB(wkb).toEWKT(), result.toEWKT());
}
@jiayuasu jiayuasu force-pushed the flink-geography-constructors branch from a39fb43 to fe95e07 Compare June 19, 2026 20:19
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 constructor functions (ST_Geog*)

2 participants