Repository navigation
[GH-3564] Report a geometry as invalid when the JTS validator throws - #3566
Merged
jiayuasu merged 2 commits intoNov 20, 2026
Merged
Conversation
ST_IsValid, ST_IsValidReason and ST_IsValidDetail no longer fail the query when IsValidOp throws while validating a geometry. ST_IsValid returns false, ST_IsValidReason returns the error as the reason and ST_IsValidDetail returns (false, reason, NULL). ST_IsValidReason and ST_IsValidDetail return NULL for a NULL geometry.
- Log the exception at debug level before ST_IsValid reports the geometry as invalid. - Return NULL from Spark ST_IsValidDetail for a NULL geometry before calling the validator. - Assert in FunctionsTest that the fixture still makes the JTS validator throw, and cover ordinary valid, invalid, empty and flag-dependent results. - Evaluate the Spark tests on repartitioned multi-row input so they run in executor tasks. - Add a Snowflake ST_IsValidDetail UDTF test. - Describe in the docs what the functions return when the validity checks cannot complete.
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_IsValid, ST_IsValidReason and ST_IsValidDetail fail the whole job when the JTS validator throws #3564What changes were proposed in this PR?
Problem.
ST_IsValid,ST_IsValidReasonandST_IsValidDetailfail the whole query when JTSIsValidOpthrows while validating a geometry (e.g.IllegalArgumentException: Segment vertex does not intersect ringfor the polygon in #3564).Cause.
Functions.isValid,isValidReasonandisValidDetailincommoncallIsValidOp.isValid()unguarded, so aRuntimeExceptionfrom the validator propagates to the engine.Change, following the fix proposed in the issue:
commonFunctions: only theisValidOp.isValid()call is guarded, catchingRuntimeException.isValidreturnsfalse.isValidReasonreturns the error as the reason, e.g.IllegalArgumentException: Segment vertex does not intersect ring.isValidDetailreturns(false, <reason>, null).isValidReasonandisValidDetailreturnnullfor anullgeometry.isValidnow reuses the existinggetIsValidOpObjecthelper instead of repeating the flag handling.ST_IsValidDetail: the expression dropped the reason whenever the location was null (it returned(valid, null, null)). It now keeps the reason, serializes the location only when present, and returnsNULLwhen the common function returnsnull.ST_IsValid,ST_IsValidReasonandST_IsValidDetailpages (SQL, Flink, Snowflake).Because the fix is in
common, Flink and Snowflake pick it up without changes (the SnowflakeST_IsValidDetailUDTF already serializes a null location as null).Alternative considered. Catching in each engine wrapper (Spark/Flink/Snowflake) would have needed the same code three times and left the common Java API throwing, so the guard is in
commonas the issue suggests. The guard is kept around the validator call only, so errors from anything else still surface.Note for review. Since
RuntimeExceptionis caught,Functions.isValid(null)in the common Java API now returnsfalserather than throwing aNullPointerException(the method returns a primitive, so it cannot return null). The SQL functions are unaffected because the engines handle NULL input before calling it. Happy to add an explicit null check that keeps throwing if you prefer.How was this patch tested?
FunctionsTest(common): new testsisValidWhenValidatorThrows,isValidReasonWhenValidatorThrows,isValidDetailWhenValidatorThrowsandisValidReasonAndDetailOfNullGeometry, using the polygon from the issue. All four fail without the fix (three with theIllegalArgumentException, one with aNullPointerException) and pass with it. FullFunctionsTestpasses locally (352 tests).functionTestScala(spark/common, Spark 3.5 / Scala 2.12): two new tests covering the three SQL functions with the issue's polygon and with a NULL geometry. Full suite passes locally (246 tests).mvn spotless:checkpasses oncommonandspark/common.I did not run the Flink, Snowflake or Python test suites locally.
Did this PR include necessary documentation updates?
This change was AI-assisted (Claude Code); I reproduced the failure and ran the tests listed above locally.