szehon-ho commented on code in PR #12346:
URL: https://github.com/apache/iceberg/pull/12346#discussion_r1980149907


##########
core/src/main/java/org/apache/iceberg/SchemaParser.java:
##########
@@ -141,11 +143,34 @@ static void toJson(Types.MapType map, JsonGenerator 
generator) throws IOExceptio
   }
 
   static void toJson(Type.PrimitiveType primitive, JsonGenerator generator) 
throws IOException {
-    generator.writeString(primitive.toString());
+    if (primitive.typeId() == Type.TypeID.GEOMETRY) {

Review Comment:
   Nit: use switch statement like rest of the code.



##########
build.gradle:
##########
@@ -292,6 +292,7 @@ project(':iceberg-api') {
 
   dependencies {
     implementation project(path: ':iceberg-bundled-guava', configuration: 
'shadow')
+    api libs.jts.core

Review Comment:
   I am not comfortable leaking the JTS API from Iceberg API, as this forces 
all the consumer to now depend on JTS.  Can we instead encapsulate this dep in 
iceberg-core?  Going to check with other Iceberg PMC's on this.



##########
api/src/main/java/org/apache/iceberg/Geography.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import java.io.Serializable;
+import java.util.Locale;
+import java.util.Objects;
+import org.locationtech.jts.geom.Geometry;
+
+/**
+ * Geospatial features from OGC – Simple feature access. The geometry is on a 
spherical or
+ * ellipsoidal surface. An edge-interpolation algorithm is used to evaluate 
spatial predicates.
+ */
+public class Geography implements Comparable<Geography>, Serializable {
+
+  /** The algorithm for interpolating edges. */
+  public enum EdgeInterpolationAlgorithm {
+    /** Edges are interpolated as geodesics on a sphere. */
+    SPHERICAL("spherical"),
+    /** See <a 
href="https://en.wikipedia.org/wiki/Vincenty%27s_formulae";>Vincenty's 
formulae</a> */
+    VINCENTY("vincenty"),
+    /**
+     * Thomas, Paul D. Spheroidal geodesics, reference systems, &amp; local 
geometry. US Naval
+     * Oceanographic Office, 1970.
+     */
+    THOMAS("thomas"),
+    /**
+     * Thomas, Paul D. Mathematical models for navigation systems. US Naval 
Oceanographic Office,
+     * 1965.
+     */
+    ANDOYER("andoyer"),
+    /**
+     * <a 
href="https://link.springer.com/content/pdf/10.1007/s00190-012-0578-z.pdf";>Karney,
 Charles
+     * FF. "Algorithms for geodesics." Journal of Geodesy 87 (2013): 43-55 
</a>, and <a
+     * href="https://geographiclib.sourceforge.io/";>GeographicLib</a>.
+     */
+    KARNEY("karney");
+
+    private final String value;
+
+    EdgeInterpolationAlgorithm(String value) {
+      this.value = value;
+    }
+
+    public String value() {
+      return value;
+    }
+
+    public static EdgeInterpolationAlgorithm fromName(String algorithmName) {
+      try {
+        return 
EdgeInterpolationAlgorithm.valueOf(algorithmName.toUpperCase(Locale.ENGLISH));
+      } catch (IllegalArgumentException e) {
+        throw new IllegalArgumentException(
+            String.format("Invalid edge interpolation algorithm name: %s", 
algorithmName), e);
+      }
+    }
+  }
+
+  private final Geometry geometry;
+
+  public Geography(Geometry geometry) {

Review Comment:
   Can we have a base class, and two implementing classes then?  its confusing 
as it is.



##########
core/src/main/java/org/apache/iceberg/SchemaParser.java:
##########
@@ -141,11 +143,34 @@ static void toJson(Types.MapType map, JsonGenerator 
generator) throws IOExceptio
   }
 
   static void toJson(Type.PrimitiveType primitive, JsonGenerator generator) 
throws IOException {
-    generator.writeString(primitive.toString());
+    if (primitive.typeId() == Type.TypeID.GEOMETRY) {
+      Types.GeometryType geometryType = (Types.GeometryType) primitive;
+      generator.writeStartObject();
+      generator.writeStringField("type", "geometry");

Review Comment:
   Nit: use the constant for "type"



##########
api/src/main/java/org/apache/iceberg/types/Types.java:
##########
@@ -70,6 +75,20 @@ public static Type fromTypeName(String typeString) {
       return TYPES.get(lowerTypeString);
     }
 
+    if (lowerTypeString.startsWith("geometry")) {

Review Comment:
   Why cant we put the startsWith in the regex, like DECIMAL and FIXED



##########
core/src/main/java/org/apache/iceberg/SchemaParser.java:
##########
@@ -141,11 +143,34 @@ static void toJson(Types.MapType map, JsonGenerator 
generator) throws IOExceptio
   }
 
   static void toJson(Type.PrimitiveType primitive, JsonGenerator generator) 
throws IOException {
-    generator.writeString(primitive.toString());
+    if (primitive.typeId() == Type.TypeID.GEOMETRY) {
+      Types.GeometryType geometryType = (Types.GeometryType) primitive;
+      generator.writeStartObject();
+      generator.writeStringField("type", "geometry");
+      String crs = geometryType.crs();
+      if (!crs.isEmpty()) {
+        generator.writeStringField("crs", geometryType.crs());

Review Comment:
   Nit: "crs" seems used frequently enough to warrant a constant.



##########
api/src/main/java/org/apache/iceberg/types/TypeUtil.java:
##########
@@ -535,6 +535,8 @@ private static int estimateSize(Type type) {
         return ((Types.FixedType) type).length();
       case BINARY:
       case VARIANT:
+      case GEOMETRY:
+      case GEOGRAPHY:

Review Comment:
   can we put a comment how we arrived at 80?



##########
api/src/main/java/org/apache/iceberg/expressions/Literal.java:
##########
@@ -71,6 +73,14 @@ static Literal<BigDecimal> of(BigDecimal value) {
     return new Literals.DecimalLiteral(value);
   }
 
+  static Literal<Geometry> of(Geometry value) {
+    return new Literals.GeometryLiteral(value);
+  }
+
+  static Literal<Geography> of(Geography value) {

Review Comment:
   I guess here, let's specifically not leak the Geography in the API, we 
should just have a wrapper class as well.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to