You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by gi...@apache.org on 2022/12/15 23:08:30 UTC

[calcite] branch site updated: [CALCITE-5417] Upgrade Proj4J from 1.1.5 to 1.2.2, and restore it as an included dependency

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

github-bot pushed a commit to branch site
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/site by this push:
     new 1d460c053a [CALCITE-5417] Upgrade Proj4J from 1.1.5 to 1.2.2, and restore it as an included dependency
1d460c053a is described below

commit 1d460c053a029c9859ea8e7e1c2d122e504511e7
Author: Julian Hyde <jh...@apache.org>
AuthorDate: Sat Dec 10 16:57:44 2022 -0800

    [CALCITE-5417] Upgrade Proj4J from 1.1.5 to 1.2.2, and restore it as an included dependency
    
    In [CALCITE-5399] we removed Proj4J as a dependency due to
    licensing issues with the EPSG data set. In this change we
    upgrade Proj4J to version 1.2.2, which no longer includes
    the EPSG data set and therefore can be distributed under the
    Apache license.
    
    This change mostly consists of a reversal of [CALCITE-5399],
    but also upgrades Proj4J.
---
 bom/build.gradle.kts                                           |  1 +
 core/build.gradle.kts                                          | 10 +++++-----
 .../main/java/org/apache/calcite/runtime/CalciteResource.java  |  3 +++
 .../java/org/apache/calcite/runtime/ProjectionTransformer.java |  8 --------
 .../java/org/apache/calcite/runtime/SpatialTypeFunctions.java  | 10 +++++++---
 .../org/apache/calcite/runtime/CalciteResource.properties      |  1 +
 gradle.properties                                              |  2 +-
 site/_docs/howto.md                                            |  2 --
 site/_docs/reference.md                                        | 10 ++++------
 site/_docs/spatial.md                                          |  9 ---------
 10 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts
index 019994894d..69d535eeea 100644
--- a/bom/build.gradle.kts
+++ b/bom/build.gradle.kts
@@ -58,6 +58,7 @@ dependencies {
         apiv("org.locationtech.jts:jts-core")
         apiv("org.locationtech.jts.io:jts-io-common")
         apiv("org.locationtech.proj4j:proj4j")
+        apiv("org.locationtech.proj4j:proj4j-epsg", "proj4j")
         apiv("com.fasterxml.jackson.core:jackson-databind")
         apiv("com.github.kstyrc:embedded-redis")
         apiv("com.github.stephenc.jcip:jcip-annotations")
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index ce8e3e9d27..eb9ab2f881 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -48,11 +48,7 @@ dependencies {
 
     api("org.locationtech.jts:jts-core")
     api("org.locationtech.jts.io:jts-io-common")
-
-    // Due to restricting terms of use, we cannot include Proj4J as an API dependency.
-    compileOnly("org.locationtech.proj4j:proj4j")
-    testRuntimeOnly("org.locationtech.proj4j:proj4j")
-
+    api("org.locationtech.proj4j:proj4j")
     api("com.fasterxml.jackson.core:jackson-annotations")
     api("com.google.errorprone:error_prone_annotations")
     api("com.google.guava:guava")
@@ -101,6 +97,10 @@ dependencies {
     testImplementation(kotlin("stdlib-jdk8"))
     testImplementation(kotlin("test"))
     testImplementation(kotlin("test-junit5"))
+
+    // proj4j-epsg must not be converted to 'implementation' due to its license
+    testRuntimeOnly("org.locationtech.proj4j:proj4j-epsg")
+
     testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
 }
 
diff --git a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
index 4e6ee08241..6723291911 100644
--- a/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
+++ b/core/src/main/java/org/apache/calcite/runtime/CalciteResource.java
@@ -63,6 +63,9 @@ public interface CalciteResource {
   @BaseMessage("Geo-spatial extensions and the GEOMETRY data type are not enabled")
   ExInst<SqlValidatorException> geometryDisabled();
 
+  @BaseMessage("Proj4J EPSG is missing from the classpath; to resolve this problem, download the EPSG data set and agree to its terms of use")
+  ExInst<CalciteException> proj4jEpsgIsMissing();
+
   @BaseMessage("Illegal INTERVAL literal {0}; at {1}")
   @Property(name = "SQLSTATE", value = "42000")
   ExInst<CalciteException> illegalIntervalLiteral(String a0, String a1);
diff --git a/core/src/main/java/org/apache/calcite/runtime/ProjectionTransformer.java b/core/src/main/java/org/apache/calcite/runtime/ProjectionTransformer.java
index f199ebeb50..825d5e7de1 100644
--- a/core/src/main/java/org/apache/calcite/runtime/ProjectionTransformer.java
+++ b/core/src/main/java/org/apache/calcite/runtime/ProjectionTransformer.java
@@ -40,14 +40,6 @@ import java.util.stream.Stream;
 
 /**
  * Transforms the projection of a geometry.
- *
- * This class uses Proj4J to transform the projection of a geometry
- * and should not be used beyond the scope of the Spatial Type Extensions.
- * Proj4J is released under the Apache License 2.0, however, it also uses the EPSG dataset,
- * which has restricting <a href="https://epsg.org/terms-of-use.html">terms of use</a>.
- * As a result, Proj4J is not suitable for inclusion in Apache Calcite
- * and this class will throw {@code ClassNotFoundException}s
- * if Proj4J is not added to the classpath by the user.
  */
 public class ProjectionTransformer extends GeometryTransformer {
 
diff --git a/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java
index bba3e13edf..b3704ed95f 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SpatialTypeFunctions.java
@@ -76,6 +76,7 @@ import static org.apache.calcite.runtime.SpatialTypeUtils.fromGeoJson;
 import static org.apache.calcite.runtime.SpatialTypeUtils.fromGml;
 import static org.apache.calcite.runtime.SpatialTypeUtils.fromWkb;
 import static org.apache.calcite.runtime.SpatialTypeUtils.fromWkt;
+import static org.apache.calcite.util.Static.RESOURCE;
 
 /**
  * Helper methods to implement spatial type (ST) functions in generated code.
@@ -1180,9 +1181,12 @@ public class SpatialTypeFunctions {
    * {@code srid}.
    */
   public static Geometry ST_Transform(Geometry geom, int srid) {
-    ProjectionTransformer projectionTransformer =
-        new ProjectionTransformer(geom.getSRID(), srid);
-    return projectionTransformer.transform(geom);
+    try {
+      ProjectionTransformer projectionTransformer = new ProjectionTransformer(geom.getSRID(), srid);
+      return projectionTransformer.transform(geom);
+    } catch (IllegalStateException e) {
+      throw RESOURCE.proj4jEpsgIsMissing().ex();
+    }
   }
 
   /**
diff --git a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
index 04d4d6844e..aaefd10b0a 100644
--- a/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
+++ b/core/src/main/resources/org/apache/calcite/runtime/CalciteResource.properties
@@ -29,6 +29,7 @@ IdentifierTooLong=Length of identifier ''{0}'' must be less than or equal to {1,
 BadFormat=not in format ''{0}''
 BetweenWithoutAnd=BETWEEN operator has no terminating AND
 GeometryDisabled=Geo-spatial extensions and the GEOMETRY data type are not enabled
+Proj4jEpsgIsMissing=Proj4J EPSG is missing from the classpath; to resolve this problem, download the EPSG data set and agree to its terms of use
 IllegalIntervalLiteral=Illegal INTERVAL literal {0}; at {1}
 IllegalMinusDate=Illegal expression. Was expecting "(DATETIME - DATETIME) INTERVALQUALIFIER"
 IllegalOverlaps=Illegal overlaps expression. Was expecting expression on the form "(DATETIME, EXPRESSION) OVERLAPS (DATETIME, EXPRESSION)"
diff --git a/gradle.properties b/gradle.properties
index f50de1ee46..f75d2e8f4e 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -97,7 +97,7 @@ elasticsearch.version=7.10.2
 embedded-redis.version=0.6
 jts-core.version=1.19.0
 jts-io-common.version=1.19.0
-proj4j.version=1.1.5
+proj4j.version=1.2.2
 foodmart-data-hsqldb.version=0.5
 foodmart-data-json.version=0.4
 foodmart-queries.version=0.4.1
diff --git a/site/_docs/howto.md b/site/_docs/howto.md
index a3833997a1..921a962ce9 100644
--- a/site/_docs/howto.md
+++ b/site/_docs/howto.md
@@ -841,8 +841,6 @@ your key to the keyservers used by Nexus, see above.
   that the `META-INF` directory contains `LICENSE`,
   `NOTICE`
 * Check PGP, per [this](https://httpd.apache.org/dev/verification.html)
-* Check that Proj4J is not among the api and implementation dependencies,
-  as the EPSG database is not redistributable.
 
 Verify the staged artifacts in the Nexus repository:
 
diff --git a/site/_docs/reference.md b/site/_docs/reference.md
index 86f4819d20..8cb0083638 100644
--- a/site/_docs/reference.md
+++ b/site/_docs/reference.md
@@ -2420,12 +2420,10 @@ Not implemented:
 
 #### Geometry projection functions
 
-Projection functions rely on Proj4J to transform the geometries.
-Proj4J is released under the Apache License 2.0, however, it also uses the EPSG dataset,
-which has restricting [terms of use](https://epsg.org/terms-of-use.html).
-As a result, Proj4J is not suitable for inclusion in Apache Calcite
-and some of these functions may throw `ClassNotFoundException`s.
-Users can still use these functions by including Proj4J in their classpath.
+The EPSG dataset is released separately from Proj4J due
+to its restrictive [terms of use](https://epsg.org/terms-of-use.html).
+In order to use the projection functions in Apache Calcite,
+users must include the EPSG dataset in their dependencies.
 
 | C | Operator syntax      | Description
 |:- |:-------------------- |:-----------
diff --git a/site/_docs/spatial.md b/site/_docs/spatial.md
index 2fe588e789..d0b2ec85d4 100644
--- a/site/_docs/spatial.md
+++ b/site/_docs/spatial.md
@@ -148,15 +148,6 @@ These rewrites are worth performing because they are much quicker to apply,
 and often allow range scans on the Hilbert index.
 But for safety, Calcite applies the original predicate, to remove false positives.
 
-## Limitations
-
-Some spatial functions rely on Proj4J to transform the projection of spatial objects.
-Proj4J is released under the Apache License 2.0, however, it also uses the EPSG dataset,
-which has restricting [terms of use](https://epsg.org/terms-of-use.html).
-As a result, Proj4J is not suitable for inclusion in Apache Calcite
-and these functions will throw `ClassNotFoundException`s.
-Users can still use these functions by including Proj4J in their classpath.
-
 ## Acknowledgements
 
 Calcite's OpenGIS implementation uses the