Skip to content

Commit

Permalink
[SEDONA-199] Update documentation for ST_NDims as it now supports M d…
Browse files Browse the repository at this point in the history
…imension. (#768)
  • Loading branch information
Kontinuation authored and zzs-wherobots committed Feb 19, 2023
1 parent a78b82c commit 63d3140
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/api/flink/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ FROM polygondf

## ST_NDims

Introduction: Returns the coordinate dimension of the geometry. It supports 2 - (x,y) , 3 - (x,y,z). Currently the geometry serializer in sedona-sql does not support M dimension, 4D geometries with ZM coordinates will have their M coordinates dropped and became 3D geometries. We're working on a new geometry serializer to resolve this issue.
Introduction: Returns the coordinate dimension of the geometry.

Format: `ST_NDims(geom: geometry)`

Expand Down
2 changes: 1 addition & 1 deletion docs/api/sql/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ Result:
```
## ST_NDims

Introduction: Returns the coordinate dimension of the geometry. It supports 2 - (x,y) , 3 - (x,y,z). Currently the geometry serializer in sedona-sql does not support M dimension, 4D geometries with ZM coordinates will have their M coordinates dropped and became 3D geometries. We're working on a new geometry serializer to resolve this issue.
Introduction: Returns the coordinate dimension of the geometry.

Format: `ST_NDims(geom: geometry)`

Expand Down
9 changes: 9 additions & 0 deletions flink/src/test/java/org/apache/sedona/flink/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ public void testNDims() {
int result = (int) first(polygonTable).getField(0);
assertEquals(3, result, 0);
}

@Test
public void testNDimsForMCoordinate() {
Object result = first(tableEnv.sqlQuery("SELECT ST_NDims(ST_GeomFromWKT('POINT M (1 2 3)'))")).getField(0);
assertEquals(result, 3);
result = first(tableEnv.sqlQuery("SELECT ST_NDims(ST_GeomFromWKT('POINT ZM (1 2 3 4)'))")).getField(0);
assertEquals(result, 4);
}

@Test
public void testXMax() {
Table polygonTable = createPolygonTable(1);
Expand Down
10 changes: 10 additions & 0 deletions sql/src/test/scala/org/apache/sedona/sql/functionTestScala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,16 @@ class functionTestScala extends TestBaseScala with Matchers with GeometrySample
assert(test.take(1)(0).get(0).asInstanceOf[Int] == 3)
}

it("Passed ST_NDims with XYM point") {
val test = sparkSession.sql("SELECT ST_NDims(ST_GeomFromWKT('POINT M(1 2 3)'))")
assert(test.take(1)(0).get(0).asInstanceOf[Int] == 3)
}

it("Passed ST_NDims with XYZM point") {
val test = sparkSession.sql("SELECT ST_NDims(ST_GeomFromWKT('POINT ZM(1 2 3 4)'))")
assert(test.take(1)(0).get(0).asInstanceOf[Int] == 4)
}

it("Passed ST_GeometryType") {
var test = sparkSession.sql("SELECT ST_GeometryType(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'))")
assert(test.take(1)(0).get(0).asInstanceOf[String].toUpperCase() == "ST_LINESTRING")
Expand Down

0 comments on commit 63d3140

Please sign in to comment.