Skip to content

[GH-3359] Return 2D results from ST_NDims, ST_CoordDim and ST_Zmflag for empty geometries - #3360

Merged
jiayuasu merged 1 commit into
masterfrom
fix/ndims-empty-geometry
Sep 13, 2026
Merged

[GH-3359] Return 2D results from ST_NDims, ST_CoordDim and ST_Zmflag for empty geometries#3360
jiayuasu merged 1 commit into
masterfrom
fix/ndims-empty-geometry

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?

Functions.nDims and Functions.zmFlag dereference Geometry.getCoordinate(), which JTS returns as null for empty geometries, so ST_NDims, ST_CoordDim and ST_Zmflag failed the whole query with a NullPointerException whenever the column contained an empty geometry.

  • Guard the null coordinate in both functions and report empty geometries as 2D: ST_NDims / ST_CoordDim return 2 and ST_Zmflag returns 0. This matches PostGIS (ST_NDims('POINT EMPTY') = 2, ST_Zmflag('POINT EMPTY') = 0) and the existing ST_HasZ / ST_HasM handling, which already null-check the same call.
  • Spark, Flink and Snowflake all delegate to the common implementation, so the fix covers every engine.
  • Document the empty-geometry result on the ST_NDims, ST_CoordDim and ST_Zmflag pages and add a release-notes entry.

How was this patch tested?

  • New unit tests in FunctionsTest: nDims, nDimsEmptyGeometries and testZmFlagEmptyGeometries cover every empty geometry type from WKT plus factory-created empties. Both empty-geometry tests fail with the reported NPE before the fix and pass after it; FunctionsTest runs 308 tests green.
  • New Spark SQL tests in functionTestScala (ST_NDims and ST_CoordDim with empty geometries, ST_Zmflag with empty geometries); the full suite passes on Spark 3.5 / Scala 2.12 (239 tests).

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

…for empty geometries

Functions.nDims and Functions.zmFlag dereferenced Geometry.getCoordinate(),
which JTS returns as null for empty geometries, so any empty input failed
the whole query with a NullPointerException. Guard the null coordinate and
report empties as 2D (nDims = 2, zmFlag = 0), matching PostGIS and the
existing ST_HasZ / ST_HasM behavior. Spark, Flink and Snowflake all
delegate to the common implementation.
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Sep 13, 2026
@jiayuasu
jiayuasu merged commit 04cfcbf into master Sep 13, 2026
43 checks passed
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.

ST_NDims, ST_CoordDim and ST_ZMFlag throw NullPointerException on empty geometries

1 participant