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 58f76928 [SEDONA-303] Port all Sedona Spark function to Sedona Flink
-- ST_Collect (#902)
58f76928 is described below
commit 58f76928b0fa02255eaf31b7ed554a858c43c2cf
Author: Junhao Liu <[email protected]>
AuthorDate: Fri Jul 14 15:01:33 2023 +0800
[SEDONA-303] Port all Sedona Spark function to Sedona Flink -- ST_Collect
(#902)
---
docs/api/flink/Function.md | 52 ++++++++++++++++++++++
.../main/java/org/apache/sedona/flink/Catalog.java | 1 +
.../apache/sedona/flink/expressions/Functions.java | 17 +++++++
.../java/org/apache/sedona/flink/FunctionTest.java | 26 +++++++++++
4 files changed, 96 insertions(+)
diff --git a/docs/api/flink/Function.md b/docs/api/flink/Function.md
index 7dd69c29..c34bc585 100644
--- a/docs/api/flink/Function.md
+++ b/docs/api/flink/Function.md
@@ -471,6 +471,58 @@ Input: `g1: 'POLYGON ((190 150, 20 10, 160 70, 190 150))',
g2: ST_Buffer('POINT(
Output: `POINT(131.59149149528952 101.89887534906197)`
+## ST_Collect
+
+Introduction: Returns MultiGeometry object based on geometry column/s or array
with geometries
+
+Format
+
+`ST_Collect(*geom: geometry)`
+
+`ST_Collect(geom: array<geometry>)`
+
+Since: `v1.5.0`
+
+Example:
+
+```sql
+SELECT ST_Collect(
+ ST_GeomFromText('POINT(21.427834 52.042576573)'),
+ ST_GeomFromText('POINT(45.342524 56.342354355)')
+) AS geom
+```
+
+Result:
+
+```
++---------------------------------------------------------------+
+|geom |
++---------------------------------------------------------------+
+|MULTIPOINT ((21.427834 52.042576573), (45.342524 56.342354355))|
++---------------------------------------------------------------+
+```
+
+Example:
+
+```sql
+SELECT ST_Collect(
+ Array(
+ ST_GeomFromText('POINT(21.427834 52.042576573)'),
+ ST_GeomFromText('POINT(45.342524 56.342354355)')
+ )
+) AS geom
+```
+
+Result:
+
+```
++---------------------------------------------------------------+
+|geom |
++---------------------------------------------------------------+
+|MULTIPOINT ((21.427834 52.042576573), (45.342524 56.342354355))|
++---------------------------------------------------------------+
+```
+
## ST_CollectionExtract
Introduction: Returns a homogeneous multi-geometry from a given geometry
collection.
diff --git a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
index 5cfe8537..3087ec23 100644
--- a/flink/src/main/java/org/apache/sedona/flink/Catalog.java
+++ b/flink/src/main/java/org/apache/sedona/flink/Catalog.java
@@ -47,6 +47,7 @@ public class Catalog {
new Functions.ST_Buffer(),
new Functions.ST_ClosestPoint(),
new Functions.ST_Centroid(),
+ new Functions.ST_Collect(),
new Functions.ST_CollectionExtract(),
new Functions.ST_ConcaveHull(),
new Functions.ST_ConvexHull(),
diff --git
a/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
b/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
index 3f4b63eb..bff5913e 100644
--- a/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
+++ b/flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java
@@ -91,6 +91,23 @@ public class Functions {
return org.apache.sedona.common.Functions.getCentroid(geom);
}
}
+
+ public static class ST_Collect extends ScalarFunction {
+ @DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class)
+ public Geometry eval(@DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class) Object o1,
+ @DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class) Object o2 ) {
+ Geometry geom1 = (Geometry) o1;
+ Geometry geom2 = (Geometry) o2;
+ Geometry[] geoms = new Geometry[]{geom1, geom2};
+ return
org.apache.sedona.common.Functions.createMultiGeometry(geoms);
+ }
+
+ @DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class)
+ public Geometry eval(@DataTypeHint(inputGroup = InputGroup.ANY) Object
o) {
+ Geometry[] geoms = (Geometry[]) o;
+ return
org.apache.sedona.common.Functions.createMultiGeometry(geoms);
+ }
+ }
public static class ST_CollectionExtract extends ScalarFunction {
@DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class)
diff --git a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
index c7dea77f..219a9989 100644
--- a/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
@@ -100,6 +100,32 @@ public class FunctionTest extends TestBase{
assertEquals("POINT (1 1)", result.toString());
}
+ @Test
+ public void testCollectWithTwoInputs() {
+ Table pointTable = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('POINT (1
2)') AS g1, ST_GeomFromWKT('POINT (-2 3)') as g2");
+ Table resultTable =
pointTable.select(call(Functions.ST_Collect.class.getSimpleName(), $("g1"),
$("g2")));
+ Geometry result1 = (Geometry) first(resultTable).getField(0);
+ assertEquals("MULTIPOINT ((1 2), (-2 3))", result1.toString());
+
+ Table collectionTable = tableEnv.sqlQuery("SELECT
ST_GeomFromWKT('POINT (1 2)') AS g1, ST_GeomFromWKT('LINESTRING(1 2, 3 4)') as
g2");
+ resultTable =
collectionTable.select(call(Functions.ST_Collect.class.getSimpleName(),
$("g1"), $("g2")));
+ Geometry result2 = (Geometry) first(resultTable).getField(0);
+ assertEquals("GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (1 2, 3
4))", result2.toString());
+ }
+
+ @Test
+ public void testCollectWithArray() {
+ Table lineTable = tableEnv.sqlQuery("SELECT
array[ST_GeomFromText('LINESTRING(1 2, 3 4)'), ST_GeomFromText('LINESTRING(3 4,
4 5)')] as lines");
+ Table resultTable =
lineTable.select(call(Functions.ST_Collect.class.getSimpleName(), $("lines")));
+ Geometry result1 = (Geometry) first(resultTable).getField(0);
+ assertEquals("MULTILINESTRING ((1 2, 3 4), (3 4, 4 5))",
result1.toString());
+
+ Table collectionTable = tableEnv.sqlQuery("SELECT
array[ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING(3 4, 4 5)')]
as lines");
+ resultTable =
collectionTable.select(call(Functions.ST_Collect.class.getSimpleName(),
$("lines")));
+ Geometry result2 = (Geometry) first(resultTable).getField(0);
+ assertEquals("GEOMETRYCOLLECTION (POINT (0 0), LINESTRING (3 4, 4
5))", result2.toString());
+ }
+
@Test
public void testCollectionExtract() {
Table collectionTable = tableEnv.sqlQuery("SELECT
ST_GeomFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(1 1, 2 2))') as
collection");