This is an automated email from the ASF dual-hosted git repository.

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new 194d4536f6 [GH-2137] bug: Make ST_LineMerge return merged lines 
instead of original when there are more than one (#2469)
194d4536f6 is described below

commit 194d4536f69c48c3e241d3f47a676a1a2fc70686
Author: Peter Nguyen <[email protected]>
AuthorDate: Sat Nov 1 21:54:15 2025 -0700

    [GH-2137] bug: Make ST_LineMerge return merged lines instead of original 
when there are more than one (#2469)
---
 common/src/main/java/org/apache/sedona/common/Functions.java   |  4 +++-
 docs/api/flink/Function.md                                     |  4 ++--
 docs/api/snowflake/vector-data/Function.md                     |  4 ++--
 docs/api/sql/Function.md                                       |  4 ++--
 .../test/scala/org/apache/sedona/sql/functionTestScala.scala   | 10 ++++++----
 5 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/common/src/main/java/org/apache/sedona/common/Functions.java 
b/common/src/main/java/org/apache/sedona/common/Functions.java
index 5139a885a1..0976316be9 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -1173,7 +1173,9 @@ public class Functions {
       } else {
         // if the merger couldn't join the lines, it will contain the 
individual lines, so return
         // the input
-        return geometry;
+        Object[] mergedLines = merger.getMergedLineStrings().toArray(new 
LineString[] {});
+        multiLineString = 
geometry.getFactory().createMultiLineString((LineString[]) mergedLines);
+        return multiLineString;
       }
     }
     return geometry.getFactory().createGeometryCollection();
diff --git a/docs/api/flink/Function.md b/docs/api/flink/Function.md
index c0563b3cd2..98a7dc1ba1 100644
--- a/docs/api/flink/Function.md
+++ b/docs/api/flink/Function.md
@@ -2616,10 +2616,10 @@ Output:
 
 ## ST_LineMerge
 
-Introduction: Returns a LineString formed by sewing together the constituent 
line work of a MULTILINESTRING.
+Introduction: Returns a LineString or MultiLineString formed by sewing 
together the constituent line work of a MULTILINESTRING.
 
 !!!note
-    Only works for MULTILINESTRING. Using other geometry will return a 
GEOMETRYCOLLECTION EMPTY. If the MultiLineString can't be merged, the original 
MULTILINESTRING is returned.
+    Only works for MULTILINESTRING. Using other geometry will return a 
GEOMETRYCOLLECTION EMPTY. If no merging can be performed, the original 
MULTILINESTRING is returned.
 
 Format: `ST_LineMerge (A: Geometry)`
 
diff --git a/docs/api/snowflake/vector-data/Function.md 
b/docs/api/snowflake/vector-data/Function.md
index c9ed83021d..14d9ca417e 100644
--- a/docs/api/snowflake/vector-data/Function.md
+++ b/docs/api/snowflake/vector-data/Function.md
@@ -1958,10 +1958,10 @@ Output:
 
 ## ST_LineMerge
 
-Introduction: Returns a LineString formed by sewing together the constituent 
line work of a MULTILINESTRING.
+Introduction: Returns a LineString or MultiLineString formed by sewing 
together the constituent line work of a MULTILINESTRING.
 
 !!!note
-    Only works for MULTILINESTRING. Using other geometry will return a 
GEOMETRYCOLLECTION EMPTY. If the MultiLineString can't be merged, the original 
MULTILINESTRING is returned.
+    Only works for MULTILINESTRING. Using other geometry will return a 
GEOMETRYCOLLECTION EMPTY. If no merging can be performed, the original 
MULTILINESTRING is returned.
 
 Format: `ST_LineMerge (A:geometry)`
 
diff --git a/docs/api/sql/Function.md b/docs/api/sql/Function.md
index eb524512cf..447707c329 100644
--- a/docs/api/sql/Function.md
+++ b/docs/api/sql/Function.md
@@ -2804,10 +2804,10 @@ Output:
 
 ## ST_LineMerge
 
-Introduction: Returns a LineString formed by sewing together the constituent 
line work of a MULTILINESTRING.
+Introduction: Returns a LineString or MultiLineString formed by sewing 
together the constituent line work of a MULTILINESTRING.
 
 !!!note
-    Only works for MULTILINESTRING. Using other geometry will return a 
GEOMETRYCOLLECTION EMPTY. If the MultiLineString can't be merged, the original 
MULTILINESTRING is returned.
+    Only works for MULTILINESTRING. Using other geometry will return a 
GEOMETRYCOLLECTION EMPTY. If no merging can be performed, the original 
MULTILINESTRING is returned.
 
 Format: `ST_LineMerge (A: Geometry)`
 
diff --git 
a/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala 
b/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
index 35634c6061..b305b9f7ae 100644
--- a/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
+++ b/spark/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
@@ -2232,8 +2232,9 @@ class functionTestScala
     val testData = Seq(
       ("MULTILINESTRING ((-29 -27, -30 -29.7, -45 -33), (-45 -33, -46 -32))"),
       ("MULTILINESTRING ((-29 -27, -30 -29.7, -36 -31, -45 -33), (-45.2 -33.2, 
-46 -32))"),
-      ("POLYGON ((8 25, 28 22, 15 11, 33 3, 56 30, 47 44, 35 36, 43 19, 24 39, 
8 25))")).toDF(
-      "Geometry")
+      ("POLYGON ((8 25, 28 22, 15 11, 33 3, 56 30, 47 44, 35 36, 43 19, 24 39, 
8 25))"),
+      ("MULTILINESTRING ((10 160, 60 120), (120 140, 60 120), (120 140, 180 
120), (100 180, 120 140))"))
+      .toDF("Geometry")
 
     When("Using ST_LineMerge")
     val testDF = testData.selectExpr("ST_LineMerge(ST_GeomFromText(Geometry)) 
as geom")
@@ -2245,8 +2246,9 @@ class functionTestScala
       .collect() should contain theSameElementsAs
       List(
         "LINESTRING (-29 -27, -30 -29.7, -45 -33, -46 -32)",
-        "MULTILINESTRING ((-29 -27, -30 -29.7, -36 -31, -45 -33), (-45.2 
-33.2, -46 -32))",
-        "GEOMETRYCOLLECTION EMPTY")
+        "MULTILINESTRING ((-45.2 -33.2, -46 -32), (-29 -27, -30 -29.7, -36 
-31, -45 -33))",
+        "GEOMETRYCOLLECTION EMPTY",
+        "MULTILINESTRING ((10 160, 60 120, 120 140), (100 180, 120 140), (120 
140, 180 120))")
   }
 
   it("Should pass ST_LocateAlong") {

Reply via email to