Skip to content

[GH-2702] Fix ST_LineMerge returning empty collection for LineString input#2707

Merged
jiayuasu merged 1 commit into
masterfrom
fix-linemerge-linestring-passthrough
Mar 11, 2026
Merged

[GH-2702] Fix ST_LineMerge returning empty collection for LineString input#2707
jiayuasu merged 1 commit into
masterfrom
fix-linemerge-linestring-passthrough

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?

ST_LineMerge returns GEOMETRYCOLLECTION EMPTY for LineString input instead of passing it through unchanged. This is inconsistent with PostGIS/GEOS behavior, where a single LineString is already "merged" and should be returned as-is.

Fix: Added a LineString instanceof check in Functions.lineMerge() before the MultiLineString block, so that a single LineString is returned unchanged.

if (geometry instanceof LineString) {
  return geometry;
}

Behavior after fix:

Input type Result
LineString Returned unchanged (was: GEOMETRYCOLLECTION EMPTY)
LineString Returned unchanch

All 223 tests in functionTestScala pass locally. No regressions.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

ST_LineMerge now passes through a single LineString unchanged,
consistent with PostGIS/GEOS behavior. Previously it fell through
to the default branch and returned GEOMETRYCOLLECTION EMPTY.

Fixes #2702
@jiayuasu jiayuasu requested a review from Copilot March 11, 2026 06:10
@jiayuasu jiayuasu added this to the sedona-1.9.0 milestone Mar 11, 2026
@jiayuasu jiayuasu merged commit 69e95a9 into master Mar 11, 2026
37 of 41 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes ST_LineMerge to match PostGIS/GEOS behavior by returning a LineString input unchanged instead of incorrectly producing GEOMETRYCOLLECTION EMPTY.

Changes:

  • Add an early LineString type check in Functions.lineMerge() to return the input geometry as-is.
  • Extend the existing Spark SQL Scala test for ST_LineMerge to cover LineString passthrough behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
common/src/main/java/org/apache/sedona/common/Functions.java Fixes lineMerge behavior for LineString inputs by returning them unchanged.
spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala Adds a regression test case to ensure ST_LineMerge preserves LineString inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1199 to +1201
if (geometry instanceof LineString) {
return geometry;
}

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description’s “Behavior after fix” table appears corrupted/duplicated (truncated rows like “Returned unchanch| …”). Please clean up the PR description so reviewers can clearly see the intended behavior matrix.

Copilot uses AI. Check for mistakes.
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_LineMerge returns GEOMETRYCOLLECTION EMPTY for LineString input instead of passing it through

2 participants