jiayuasu commented on code in PR #889:
URL: https://github.com/apache/sedona/pull/889#discussion_r1257730460
##########
docs/api/flink/Function.md:
##########
@@ -1787,3 +1787,26 @@ SELECT ST_ZMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6
7)'))
```
Output: `4.0`
+
+
+## ST_CoordDim
Review Comment:
1. Doc are sorted alphabetically.
2. Please include since `v1.5.0`
3. Do not say `Spark SQL example` since this doc is for Flink.
##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -1045,4 +1045,18 @@ public static Double hausdorffDistance(Geometry g1,
Geometry g2, double densityF
public static Double hausdorffDistance(Geometry g1, Geometry g2) throws
Exception{
return GeomUtils.getHausdorffDistance(g1, g2, -1);
}
+
+ public static int coordDim(Geometry geom) {
Review Comment:
No need to reimplement the function here. Just use nDim() func.
##########
flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java:
##########
@@ -853,6 +853,15 @@ public Double eval(@DataTypeHint(value = "RAW", bridgedTo
= org.locationtech.jts
}
}
+
+ public static class ST_CoordDim extends ScalarFunction {
+ @DataTypeHint("Integer")
+ public Integer eval(@DataTypeHint(value = "RAW", bridgedTo =
org.locationtech.jts.geom.Geometry.class) Object o) {
+ Geometry geom = (Geometry) o;
+ return org.apache.sedona.common.Functions.coordDim(geom);
Review Comment:
Directly use nDim func
##########
python/Pipfile:
##########
@@ -14,7 +14,7 @@ pytest-cov = "*"
shapely="<=1.8.5"
pandas="<=1.3.5"
geopandas="<=0.10.2"
-pyspark=">=2.3.0"
Review Comment:
You are not supposed to touch this file.
##########
core/src/main/java/org/apache/sedona/core/spatialOperator/JoinQuery.java:
##########
@@ -37,7 +38,6 @@
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function2;
import org.apache.spark.api.java.function.PairFunction;
-import org.apache.sedona.core.monitoring.Metrics;
Review Comment:
You are not supposed to touch this file.
##########
python/tests/sql/test_function.py:
##########
@@ -1177,3 +1177,9 @@ def test_hausdorffDistance(self):
actual_default = actual_df_default.take(1)[0][0]
assert expected == actual
assert expected == actual_default
+
+ def test_st_coord_dim(self):
+
+ point_df = self.spark.sql("SELECT ST_GeomFromWkt('POINT(7 8 6)') AS
geom")
Review Comment:
This test does not actually test `ST_CoordDim` python DataFrame API. Please
carefully read the test case examples in this file.
##########
docs/api/sql/Function.md:
##########
@@ -2094,3 +2094,24 @@ SELECT ST_ZMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6
7)'))
Output: `4.0`
+## ST_CoordDim
+
+Introduction: Returns the coordinate dimensions of the geometry.
Review Comment:
Same issue here
##########
pom.xml:
##########
@@ -18,12 +18,12 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <parent>
Review Comment:
You are not supposed to touch this file.
##########
flink/src/test/java/org/apache/sedona/flink/FunctionTest.java:
##########
@@ -948,4 +948,21 @@ public void testHausdorffDistance() {
assertEquals(expected, actual);
assertEquals(expectedDefault, actualDefault);
}
+
+ @Test
+ public void testCoordDimFor2D() {
+ Table polygonTable = tableEnv.sqlQuery("SELECT ST_GeomFromWKT('POINT(3
7)') AS " + polygonColNames[0]);
+ polygonTable =
polygonTable.select(call(Functions.ST_CoordDim.class.getSimpleName(),
$(polygonColNames[0])));
+ int result = (int) first(polygonTable).getField(0);
+ assertEquals(2, result, 0);
+ }
+
+ @Test
+ public void testCoordDim() {
Review Comment:
use name `testCoordDim for 3D`
##########
flink/src/main/java/org/apache/sedona/flink/expressions/Functions.java:
##########
@@ -893,6 +902,7 @@ public static class ST_Degrees extends ScalarFunction {
@DataTypeHint("Double")
public Double eval(@DataTypeHint("Double") Double angleInRadian) {
return org.apache.sedona.common.Functions.degrees(angleInRadian);
+
Review Comment:
Please do not make changes to irrelevant parts of the codebase
##########
sql/common/src/main/scala/org/apache/spark/sql/sedona_sql/expressions/st_functions.scala:
##########
@@ -380,5 +380,9 @@ object st_functions extends DataFrameAPI {
def ST_HausdorffDistance(g1: String, g2: String, densityFrac: Double) =
wrapExpression[ST_HausdorffDistance](g1, g2, densityFrac);
+ def ST_CoordDim(geometry: Column): Column =
wrapExpression[ST_CoordDim](geometry)
Review Comment:
You didn't implement test cases for testing this DataFrame style function.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]