Skip to content

[GH-2720][GH-2721][GH-2722][GH-2723] Fix geometry function bugs#2730

Merged
jiayuasu merged 3 commits into
masterfrom
fix/geometry-bugs-2720-2723
Mar 12, 2026
Merged

[GH-2720][GH-2721][GH-2722][GH-2723] Fix geometry function bugs#2730
jiayuasu merged 3 commits into
masterfrom
fix/geometry-bugs-2720-2723

Conversation

@jiayuasu
Copy link
Copy Markdown
Member

Summary

Fixes four geometry function bugs:

[GH-2720] ST_FrechetDistance returns 0.0 instead of null for empty geometries

Changed getFrechetDistance to return Double.NaN (instead of 0.0) when either input geometry is empty, matching PostGIS and shapely/geopandas behavior. Updated return type from double to Double in GeomUtils, Functions, and Snowflake UDFs.

[GH-2721] ST_HausdorffDistance returns 0.0 instead of null for empty geometries

Changed getHausdorffDistance to return Double.NaN (instead of 0.0) when either input geometry is empty, matching PostGIS and shapely/geopandas behavior.

[GH-2722] ST_Equals throws IllegalArgumentException on GeometryCollection inputs

Replaced symDifference().isEmpty() with equalsTopo() in Predicates.equals(). JTS's symDifference does not support GeometryCollection arguments; equalsTopo is the JTS equivalent of DE-9IM topological equality and handles GeometryCollection inputs correctly.

[GH-2723] ST_VoronoiPolygons unnecessarily requires GeoTools on classpath

Moved voronoiPolygons from FunctionsGeoTools.java to Functions.java. The method only uses JTS classes (VoronoiDiagramBuilder, Geometry, Envelope) -- no GeoTools APIs -- consistent with ST_DelaunayTriangles which is already in Functions.java. Updated all callers in Spark, Flink, and Snowflake modules. Removed unused imports.

Changes

File Change
common/.../utils/GeomUtils.java Return Double.NaN for empty geoms in getFrechetDistance and getHausdorffDistance
common/.../Functions.java Change frechetDistance return type to Double; add voronoiPolygons method
common/.../FunctionsGeoTools.java Remove voronoiPolygons method and unused imports
common/.../Predicates.java Use equalsTopo() instead of symDifference().isEmpty()
flink/.../expressions/Functions.java Update ST_VoronoiPolygons to call Functions.voronoiPolygons
snowflake/.../UDFs.java Update ST_VoronoiPolygons and ST_FrechetDistance callers
snowflake/.../UDFsV2.java Update ST_VoronoiPolygons and ST_FrechetDistance callers
spark/.../expressions/Functions.scala Update ST_VoronoiPolygons to reference Functions.voronoiPolygons
common/.../FunctionsTest.java Update tests to expect NaN for empty geoms; use Functions.voronoiPolygons
common/.../PredicatesTest.java Add test for ST_Equals with GeometryCollection inputs

Closes #2720
Closes #2721
Closes #2722
Closes #2723

- ST_FrechetDistance: return Double.NaN instead of 0.0 for empty geometries
- ST_HausdorffDistance: return Double.NaN instead of 0.0 for empty geometries
- ST_Equals: use equalsTopo instead of symDifference to support GeometryCollection
- ST_VoronoiPolygons: move from FunctionsGeoTools to Functions (no GeoTools dependency)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes four geometry function bugs: returning NaN instead of 0.0 for empty geometry inputs in ST_FrechetDistance and ST_HausdorffDistance, using equalsTopo() instead of symDifference().isEmpty() in ST_Equals to support GeometryCollection inputs, and moving ST_VoronoiPolygons from FunctionsGeoTools to Functions since it has no GeoTools dependency.

Changes:

  • Changed getFrechetDistance and getHausdorffDistance in GeomUtils to return Double.NaN for empty geometries, with corresponding return type change to Double propagated through Functions, Snowflake UDFs.
  • Replaced symDifference().isEmpty() with equalsTopo() in Predicates.equals() to handle GeometryCollection inputs.
  • Moved voronoiPolygons from FunctionsGeoTools to Functions and updated all callers in Spark, Flink, and Snowflake modules.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
common/.../utils/GeomUtils.java Return Double.NaN for empty geometries in distance functions
common/.../Functions.java Change frechetDistance return type to Double; add voronoiPolygons
common/.../FunctionsGeoTools.java Remove voronoiPolygons and unused imports
common/.../Predicates.java Use equalsTopo() for topological equality
flink/.../expressions/Functions.java Update ST_VoronoiPolygons caller
snowflake/.../UDFs.java Update ST_VoronoiPolygons and ST_FrechetDistance callers
snowflake/.../UDFsV2.java Update ST_VoronoiPolygons and ST_FrechetDistance callers
spark/.../expressions/Functions.scala Update ST_VoronoiPolygons caller
common/.../FunctionsTest.java Update tests to expect NaN; use Functions.voronoiPolygons
common/.../PredicatesTest.java Add test for ST_Equals with GeometryCollection

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

…tions

Return Java null (boxed Double) instead of Double.NaN for empty geometry
inputs in getFrechetDistance and getHausdorffDistance. This ensures that
Spark SQL correctly treats the result as SQL null rather than a valid
NaN double value.
@jiayuasu jiayuasu requested a review from Copilot March 12, 2026 04:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


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

@jiayuasu jiayuasu requested a review from Copilot March 12, 2026 05:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


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

@jiayuasu jiayuasu merged commit ee5c897 into master Mar 12, 2026
47 of 49 checks passed
@jiayuasu jiayuasu deleted the fix/geometry-bugs-2720-2723 branch March 25, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants