Repository navigation
[GH-3174] Align ST_IsPolygonCW/ST_IsPolygonCCW with PostGIS polygon orientation semantics - #3292
Merged
jiayuasu merged 4 commits intoAug 30, 2026
Conversation
- Refactor isPolygonCW and isPolygonCCW methods to handle non-polygonal geometries and nested GeometryCollections, returning true when no polygonal components are present. - Update documentation for ST_IsPolygonCW and ST_IsPolygonCCW to reflect new behavior. - Add tests to verify correct handling of non-polygonal geometries and null inputs in both SQL and Flink contexts.
mvn spotless:apply on common/Functions.java (javadoc line wrapping) and the snowflake-tester test files (verifySqlSingleRes call wrapping), which CI's spotless-maven-plugin check flagged on the previous commit. Co-Authored-By: Claude Sonnet 5 <[email protected]>
jiayuasu
reviewed
Aug 28, 2026
| return true; | ||
| } | ||
| // No polygonal component to violate the orientation for remaining geometry types | ||
| return true; |
Member
There was a problem hiding this comment.
Could we keep the previous behavior for a direct Java null here? It looks like null misses both branches and falls through to true, so Functions.isPolygonCW(null) and isPolygonCCW(null) now both return true instead of the previous false. The SQL wrappers seem to handle null separately, but direct common callers can still reach this. Maybe add a null guard and a small common test?
jiayuasu
approved these changes
Aug 30, 2026
Member
|
Thank you! |
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 #3174.
What changes were proposed in this PR?
isPolygonCW/isPolygonCCWincommon/Functions.javato recursively inspect polygonal components (Polygon,MultiPolygon, and nestedGeometryCollectionat any depth) and vacuously returntruefor inputs with no polygonal components (points, line strings, empty geometry collections), matching PostGIS semantics. Both predicates share one recursive helper (allPolygonalComponentsMatchOrientation) to avoid duplicating the traversal logic.ST_IsPolygonCW/ST_IsPolygonCCWwrappers from primitivebooleanto nullableBooleanwith an explicit null check, so a SQLNULLinput now returnsNULLinstead offalse.ST_IsPolygonCW/ST_IsPolygonCCWacross the SQL, Flink, and Snowflake docs, and added a breaking-change entry to the Sedona 2.0.0 release notes.GEOMETRYCOLLECTIONrecursion, andNULLpropagation across the common, Spark SQL, Flink, and Snowflake test suites.No code changes were needed in the Snowflake or Spark UDF wrappers: Snowflake's Java UDF runtime already short-circuits
NULLinput before invoking the handler, and Spark'sInferredExpressionalready short-circuitsNULLgeometry arguments before calling the underlying common function.Since
masteris already2.0.0-SNAPSHOT, this breaking change lands directly at the major-version boundary called out in the issue, without needing a compatibility flag.How was this patch tested?
mvn -pl common -Dtest=FunctionsTest test(328 tests, including new coverage for nestedGeometryCollectionrecursion and mixed orientation)mvn -pl flink -Dtest=FunctionTest#testIsPolygonCW,testIsPolygonCCW,testIsPolygonOrientationForEmptyGeometries,testIsPolygonOrientationForNonPolygonalAndCollectionGeometries,testIsPolygonOrientationNullPropagation testmvn -Dsnowflake=true -pl snowflake-tester -am -DskipTests package(compiles cleanly; tests require live Snowflake credentials so were not executed)functionTestScala.scala. Could not get a fullspark/commonreactor build in the local dev environment due to a pre-existing, unrelatedprotobuf-java/generated-sources mismatch in the OSM PBF datasource reader (package proto4 does not exist); no code outside the added Scala test was touched in the Spark module, and the fix relies onInferredExpression's existing null-short-circuiting, which is exercised by many other predicates in this codebase.Did this PR include necessary documentation updates?