[GH-3359] Return 2D results from ST_NDims, ST_CoordDim and ST_Zmflag for empty geometries - #3360
Merged
Merged
Conversation
…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.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes ST_NDims, ST_CoordDim and ST_ZMFlag throw NullPointerException on empty geometries #3359What changes were proposed in this PR?
Functions.nDimsandFunctions.zmFlagdereferenceGeometry.getCoordinate(), which JTS returns asnullfor empty geometries, soST_NDims,ST_CoordDimandST_Zmflagfailed the whole query with aNullPointerExceptionwhenever the column contained an empty geometry.ST_NDims/ST_CoordDimreturn 2 andST_Zmflagreturns 0. This matches PostGIS (ST_NDims('POINT EMPTY')= 2,ST_Zmflag('POINT EMPTY')= 0) and the existingST_HasZ/ST_HasMhandling, which already null-check the same call.ST_NDims,ST_CoordDimandST_Zmflagpages and add a release-notes entry.How was this patch tested?
FunctionsTest:nDims,nDimsEmptyGeometriesandtestZmFlagEmptyGeometriescover 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;FunctionsTestruns 308 tests green.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?