Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-199] Added ST_NDims to Apache Sedona #720

Merged
merged 21 commits into from
Dec 3, 2022
Merged

Conversation

Amrit-Bhaskar-abhask10
Copy link
Contributor

@Amrit-Bhaskar-abhask10 Amrit-Bhaskar-abhask10 commented Dec 2, 2022

Did you read the Contributor Guide?

Is this PR related to a JIRA ticket?

What changes were proposed in this PR?

Added ST_NDims functions to SQL

How was this patch tested?

Through unit tests written in Scala

Did this PR include necessary documentation updates?

Yes, I have updated the documentation.

Copy link
Member

@jiayuasu jiayuasu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Please make changes accordingly.

@@ -280,6 +280,19 @@ public static int nPoints(Geometry geometry) {
return geometry.getNumPoints();
}

public static int nDims(Geometry geometry) {
String str = geometry.getCoordinate().toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not directly check NaN using getX getY getZ getM from coordinate class?

@@ -1475,3 +1475,24 @@ SELECT ST_ZMin(ST_GeomFromText('LINESTRING(1 3 4, 5 6 7)'))
```

Output: `4.0`

## ST_NDims

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please add more elaboration and examples about dimension when the input has M or Z.
  2. The output should be 3 integer not 3.0 double. Please correct me if I am wrong.
  3. The doc should be sorted by the alphabetical order

@@ -459,6 +459,11 @@ class functionTestScala extends TestBaseScala with Matchers with GeometrySample

}

it("Passed ST_NDims") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more test cases for 2, 3, 4D (e.g., when Z and M present, or both present)

@Amrit-Bhaskar-abhask10
Copy link
Contributor Author

Hi @jiayuasu, The requested changes are fixed now. Please let us know if any more changes are required.

}

it("Passed ST_NDims with both Z and M coordinates") {
val test = sparkSession.sql("SELECT ST_NDims(ST_GeomFromWKT('POINTZM(1 1 1 0.5)'))")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to PostGIS doc (https://postgis.net/docs/ST_NDims.html), XYZM should return 4, but your case returns 3. If you cannot support M, I am ok with this. But please clearly state it in the API doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our Java function does support POINTZM values. And the test cases of Java with POINZM values give the expected result of 4 for POINTZM(1 1 1 0.5). But somehow, the same test case for Scala gives the value of 3.
For, POINTM(1 1 0.5), In the java test case, we get the output as 3, but in scala, we get the output as 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Kontinuation for clarifying my doubt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiayuasu, I made the updates with the test cases and documentation.

@jiayuasu jiayuasu merged commit 7b9396d into apache:master Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants