[GH-2720][GH-2721][GH-2722][GH-2723] Fix geometry function bugs#2730
Conversation
- 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)
There was a problem hiding this comment.
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
getFrechetDistanceandgetHausdorffDistanceinGeomUtilsto returnDouble.NaNfor empty geometries, with corresponding return type change toDoublepropagated throughFunctions, Snowflake UDFs. - Replaced
symDifference().isEmpty()withequalsTopo()inPredicates.equals()to handleGeometryCollectioninputs. - Moved
voronoiPolygonsfromFunctionsGeoToolstoFunctionsand 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Summary
Fixes four geometry function bugs:
[GH-2720] ST_FrechetDistance returns 0.0 instead of null for empty geometries
Changed
getFrechetDistanceto returnDouble.NaN(instead of0.0) when either input geometry is empty, matching PostGIS and shapely/geopandas behavior. Updated return type fromdoubletoDoubleinGeomUtils,Functions, and Snowflake UDFs.[GH-2721] ST_HausdorffDistance returns 0.0 instead of null for empty geometries
Changed
getHausdorffDistanceto returnDouble.NaN(instead of0.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()withequalsTopo()inPredicates.equals(). JTS'ssymDifferencedoes not supportGeometryCollectionarguments;equalsTopois the JTS equivalent of DE-9IM topological equality and handlesGeometryCollectioninputs correctly.[GH-2723] ST_VoronoiPolygons unnecessarily requires GeoTools on classpath
Moved
voronoiPolygonsfromFunctionsGeoTools.javatoFunctions.java. The method only uses JTS classes (VoronoiDiagramBuilder,Geometry,Envelope) -- no GeoTools APIs -- consistent withST_DelaunayTriangleswhich is already inFunctions.java. Updated all callers in Spark, Flink, and Snowflake modules. Removed unused imports.Changes
common/.../utils/GeomUtils.javaDouble.NaNfor empty geoms ingetFrechetDistanceandgetHausdorffDistancecommon/.../Functions.javafrechetDistancereturn type toDouble; addvoronoiPolygonsmethodcommon/.../FunctionsGeoTools.javavoronoiPolygonsmethod and unused importscommon/.../Predicates.javaequalsTopo()instead ofsymDifference().isEmpty()flink/.../expressions/Functions.javaST_VoronoiPolygonsto callFunctions.voronoiPolygonssnowflake/.../UDFs.javaST_VoronoiPolygonsandST_FrechetDistancecallerssnowflake/.../UDFsV2.javaST_VoronoiPolygonsandST_FrechetDistancecallersspark/.../expressions/Functions.scalaST_VoronoiPolygonsto referenceFunctions.voronoiPolygonscommon/.../FunctionsTest.javaNaNfor empty geoms; useFunctions.voronoiPolygonscommon/.../PredicatesTest.javaST_EqualswithGeometryCollectioninputsCloses #2720
Closes #2721
Closes #2722
Closes #2723