You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by zo...@apache.org on 2023/04/12 08:06:09 UTC

[sedona] branch fix/move-sql-st-functions-implementation-to-commons updated (744960ee -> e3d8e87f)

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

zongsizhang pushed a change to branch fix/move-sql-st-functions-implementation-to-commons
in repository https://gitbox.apache.org/repos/asf/sedona.git


 discard 744960ee move 3 ST functions implementation to common Functions
     new e3d8e87f move 3 ST functions implementation to common Functions

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (744960ee)
            \
             N -- N -- N   refs/heads/fix/move-sql-st-functions-implementation-to-commons (e3d8e87f)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 common/src/main/java/org/apache/sedona/common/Functions.java       | 2 +-
 .../org/apache/spark/sql/sedona_sql/expressions/Functions.scala    | 7 +------
 2 files changed, 2 insertions(+), 7 deletions(-)


[sedona] 01/01: move 3 ST functions implementation to common Functions

Posted by zo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zongsizhang pushed a commit to branch fix/move-sql-st-functions-implementation-to-commons
in repository https://gitbox.apache.org/repos/asf/sedona.git

commit e3d8e87fd2d878a354ed183abe6181db43dd759b
Author: zongsi.zhang <kr...@gmail.com>
AuthorDate: Wed Apr 12 16:02:43 2023 +0800

    move 3 ST functions implementation to common Functions
---
 .../main/java/org/apache/sedona/common/Functions.java | 19 +++++++++++++++++++
 .../spark/sql/sedona_sql/expressions/Functions.scala  | 11 +++--------
 2 files changed, 22 insertions(+), 8 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 2c90d06b..6889741d 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -37,6 +37,7 @@ import org.locationtech.jts.operation.linemerge.LineMerger;
 import org.locationtech.jts.operation.valid.IsSimpleOp;
 import org.locationtech.jts.operation.valid.IsValidOp;
 import org.locationtech.jts.precision.GeometryPrecisionReducer;
+import org.locationtech.jts.simplify.TopologyPreservingSimplifier;
 import org.opengis.referencing.FactoryException;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -575,4 +576,22 @@ public class Functions {
         }
         return S2Utils.roundCellsToSameLevel(new ArrayList<>(cellIds), level).stream().map(S2CellId::id).collect(Collectors.toList()).toArray(new Long[cellIds.size()]);
     }
+
+    // create static function named simplifyPreserveTopology
+    public static Geometry simplifyPreserveTopology(Geometry geometry, double distanceTolerance) {
+        return TopologyPreservingSimplifier.simplify(geometry, distanceTolerance);
+    }
+
+    public static String geometryType(Geometry geometry) {
+        return "ST_" + geometry.getGeometryType();
+    }
+
+    public static Geometry startPoint(Geometry geometry) {
+        if (geometry instanceof LineString) {
+            LineString line = (LineString) geometry;
+            return line.getStartPoint();
+        }
+        return null;
+    }
+
 }
diff --git a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
index 9de64be9..dc31bb66 100644
--- a/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
+++ b/sql/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/Functions.scala
@@ -310,7 +310,7 @@ case class ST_IsSimple(inputExpressions: Seq[Expression])
   *                         second arg is distance tolerance for the simplification(all vertices in the simplified geometry will be within this distance of the original geometry)
   */
 case class ST_SimplifyPreserveTopology(inputExpressions: Seq[Expression])
-  extends InferredBinaryExpression(TopologyPreservingSimplifier.simplify) with FoldableExpression {
+  extends InferredBinaryExpression(Functions.simplifyPreserveTopology) with FoldableExpression {
 
   protected def withNewChildrenInternal(newChildren: IndexedSeq[Expression]) = {
     copy(inputExpressions = newChildren)
@@ -383,7 +383,7 @@ case class ST_GeometryType(inputExpressions: Seq[Expression])
   extends UnaryGeometryExpression with FoldableExpression with CodegenFallback {
 
   override protected def nullSafeEval(geometry: Geometry): Any = {
-    UTF8String.fromString("ST_" + geometry.getGeometryType)
+    UTF8String.fromString(Functions.geometryType(geometry))
   }
 
   override def dataType: DataType = StringType
@@ -447,12 +447,7 @@ case class ST_StartPoint(inputExpressions: Seq[Expression])
   extends UnaryGeometryExpression with FoldableExpression with CodegenFallback {
 
   override protected def nullSafeEval(geometry: Geometry): Any = {
-    geometry match {
-      case line: LineString => {
-        line.getPointN(0)
-      }
-      case _ => null
-    }
+    Functions.startPoint(geometry)
   }
 
   override def dataType: DataType = GeometryUDT