jiayuasu commented on a change in pull request #528:
URL: https://github.com/apache/incubator-sedona/pull/528#discussion_r635828960



##########
File path: 
sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/subdivide/implicits.scala
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.spark.sql.sedona_sql.expressions.subdivide
+
+import org.locationtech.jts.geom.Geometry
+

Review comment:
       There is an implicits.scala in the directory that is one level up. It 
basically provides the same functionalities. Will you be able to merge them 
together?

##########
File path: docs/api/sql/Function.md
##########
@@ -612,3 +612,64 @@ Spark SQL example:
 ```SQL
 SELECT ST_MinimumBoundingCircle(ST_GeomFromText('POLYGON((1 1,0 0, -1 1, 1 
1))'))
 ```
+
+## ST_SubDivide
+
+Introduction: Returns list of geometries divided based of given maximum number 
of vertices.
+
+Format: `ST_SubDivide(geom: geometry, maxVertices: int)`
+
+Since: `v1.0.2`
+
+Spark SQL example:
+```SQL
+SELECT ST_SubDivide(ST_GeomFromText("POLYGON((35 10, 45 45, 15 40, 10 20, 35 
10), (20 30, 35 35, 30 20, 20 30))"), 5)
+
+```
+
+Output:
+```
+[
+    POLYGON((37.857142857142854 20, 35 10, 10 20, 37.857142857142854 20)),
+    POLYGON((15 20, 10 20, 15 40, 15 20)),
+    POLYGON((20 20, 15 20, 15 30, 20 30, 20 20)),
+    POLYGON((26.428571428571427 20, 20 20, 20 30, 26.4285714 23.5714285, 
26.4285714 20)),
+    POLYGON((15 30, 15 40, 20 40, 20 30, 15 30)),
+    POLYGON((20 40, 26.4285714 40, 26.4285714 32.1428571, 20 30, 20 40)),
+    POLYGON((37.8571428 20, 30 20, 34.0476190 32.1428571, 37.8571428 
32.1428571, 37.8571428 20)),
+    POLYGON((34.0476190 34.6825396, 26.4285714 32.1428571, 26.4285714 40, 
34.0476190 40, 34.0476190 34.6825396)),
+    POLYGON((34.0476190 32.1428571, 35 35, 37.8571428 35, 37.8571428 
32.1428571, 34.0476190 32.1428571)),
+    POLYGON((35 35, 34.0476190 34.6825396, 34.0476190 35, 35 35)),
+    POLYGON((34.0476190 35, 34.0476190 40, 37.8571428 40, 37.8571428 35, 
34.0476190 35)),
+    POLYGON((30 20, 26.4285714 20, 26.4285714 23.5714285, 30 20)),
+    POLYGON((15 40, 37.8571428 43.8095238, 37.8571428 40, 15 40)),
+    POLYGON((45 45, 37.8571428 20, 37.8571428 43.8095238, 45 45))
+]
+```
+
+Spark SQL example:
+
+```SQL
+SELECT ST_SubDivide(ST_GeomFromText("LINESTRING(0 0, 85 85, 100 100, 120 120, 
21 21, 10 10, 5 5)"), 5)
+```
+
+Output:
+```
+[
+    LINESTRING(0 0, 5 5)
+    LINESTRING(5 5, 10 10)
+    LINESTRING(10 10, 21 21)
+    LINESTRING(21 21, 60 60)
+    LINESTRING(60 60, 85 85)
+    LINESTRING(85 85, 100 100)
+    LINESTRING(100 100, 120 120)
+]
+```
+
+## ST_SubDivideExplode
+
+Introduction: It works the same as ST_SubDivide but returns new rows with 
geometries instead of list.
+
+Format: `ST_SubDivideExplode(geom: geometry, maxVertices: int)`

Review comment:
       Can you add an example usage for this? Probably both in Spark Scala DSL 
and pure SQL "lateral view"?

##########
File path: 
sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
##########
@@ -1122,4 +1123,48 @@ case class ST_FlipCoordinates(inputExpressions: 
Seq[Expression])
   override def dataType: DataType = GeometryUDT
 
   override def children: Seq[Expression] = inputExpressions
+}
+
+
+case class ST_SubDivide(inputExpressions: Seq[Expression])
+  extends Expression with CodegenFallback {
+  override def nullable: Boolean = true
+
+  override def eval(input: InternalRow): Any = {
+    inputExpressions.validateLength(2)
+    val geometryRaw = inputExpressions.head
+    val maxVerticesRaw = inputExpressions(1)
+    geometryRaw.toGeometry(input) match {
+      case geom: Geometry => ArrayData.toArrayData(
+        GeometrySubDivider.subDivide(geom, 
maxVerticesRaw.toInt(input)).map(_.toGenericArrayData)
+      )
+      case null => null
+    }
+
+  }
+
+  override def dataType: DataType = ArrayType(GeometryUDT)
+
+  override def children: Seq[Expression] = inputExpressions
+}
+
+case class ST_SubDivideExplode(children: Seq[Expression]) extends Generator {

Review comment:
       I noticed that in Spark 3.1, the behavior of generator seems to be 
changed in "Lateral view". Can you add one test case to test 
ST_SubDivideExplode in Lateral View? 
https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-lateral-view.html

##########
File path: 
sql/src/test/scala/org/apache/sedona/sql/functions/FunctionsHelper.scala
##########
@@ -0,0 +1,31 @@
+///*

Review comment:
       Can this be merged with implicits.scala as well?
   
   Can you also remove the "//" in the header?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to