You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ma...@apache.org on 2022/04/29 11:51:50 UTC
[incubator-sedona] branch AddSTGeomFromGeohash updated: Add support for null precision
This is an automated email from the ASF dual-hosted git repository.
malka pushed a commit to branch AddSTGeomFromGeohash
in repository https://gitbox.apache.org/repos/asf/incubator-sedona.git
The following commit(s) were added to refs/heads/AddSTGeomFromGeohash by this push:
new 5cb6db23 Add support for null precision
5cb6db23 is described below
commit 5cb6db2335eadb25c797b66b43a28ec813e29018
Author: Netanel Malka <ne...@gmail.com>
AuthorDate: Fri Apr 29 14:50:51 2022 +0300
Add support for null precision
---
.../apache/sedona/flink/expressions/Constructors.java | 7 +++++++
.../java/org/apache/sedona/flink/ConstructorTest.java | 18 ++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/flink/src/main/java/org/apache/sedona/flink/expressions/Constructors.java b/flink/src/main/java/org/apache/sedona/flink/expressions/Constructors.java
index dcd96166..3e3bb4b4 100644
--- a/flink/src/main/java/org/apache/sedona/flink/expressions/Constructors.java
+++ b/flink/src/main/java/org/apache/sedona/flink/expressions/Constructors.java
@@ -97,8 +97,15 @@ public class Constructors {
@DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class)
public Geometry eval(@DataTypeHint("String") String value,
@DataTypeHint("Int") Integer precision) throws ParseException {
+ // The default precision is the geohash length. Otherwise, use the precision given by the user
scala.Option<Object> optionPrecision = scala.Option.apply(precision);
return GeoHashDecoder.decode(value, optionPrecision);
}
+
+ @DataTypeHint(value = "RAW", bridgedTo = org.locationtech.jts.geom.Geometry.class)
+ public Geometry eval(@DataTypeHint("String") String value) throws ParseException {
+ scala.Option<Object> nonePrecision = scala.Option.apply(null);
+ return GeoHashDecoder.decode(value, nonePrecision);
+ }
}
}
\ No newline at end of file
diff --git a/flink/src/test/java/org/apache/sedona/flink/ConstructorTest.java b/flink/src/test/java/org/apache/sedona/flink/ConstructorTest.java
index 0900c883..e046679d 100644
--- a/flink/src/test/java/org/apache/sedona/flink/ConstructorTest.java
+++ b/flink/src/test/java/org/apache/sedona/flink/ConstructorTest.java
@@ -120,4 +120,22 @@ public class ConstructorTest extends TestBase{
assertEquals(result, expectedGeom);
}
+
+ @Test
+ public void testGeomFromGeoHashNullPrecision() {
+ List<Row> data = new ArrayList<>();
+ data.add(Row.of("2131s12fd", "polygon"));
+
+ Table geohashTable = createTextTable(data, polygonColNames);
+ Table geomTable = geohashTable
+ .select(call(Constructors.ST_GeomFromGeoHash.class.getSimpleName(),
+ $(polygonColNames[0]))
+ .as(polygonColNames[0]), $(polygonColNames[1]));
+ String result = first(geomTable)
+ .getFieldAs(0)
+ .toString();
+ String expectedGeom = "POLYGON ((-178.4168529510498 -37.69778251647949, -178.4168529510498 -37.697739601135254, -178.41681003570557 -37.697739601135254, -178.41681003570557 -37.69778251647949, -178.4168529510498 -37.69778251647949))";
+
+ assertEquals(result, expectedGeom);
+ }
}