Kontinuation commented on code in PR #12346: URL: https://github.com/apache/iceberg/pull/12346#discussion_r2008614030
########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -543,6 +565,148 @@ public int hashCode() { } } + public static class GeometryType extends PrimitiveType { + + private final String crs; + + private GeometryType(String crs) { Review Comment: Use this simplified version. ########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -543,6 +565,148 @@ public int hashCode() { } } + public static class GeometryType extends PrimitiveType { + + private final String crs; + + private GeometryType(String crs) { + if (crs != null) { + Preconditions.checkArgument(!crs.isEmpty(), "Invalid CRS: (empty string)"); + Preconditions.checkArgument( + crs.trim().equals(crs), "CRS must not have leading or trailing spaces: '%s'", crs); + this.crs = crs; + } else { + this.crs = null; + } + } + + private GeometryType() { + crs = null; + } + + public static GeometryType crs84() { + return new GeometryType(); + } + + public static GeometryType of(String crs) { + return new GeometryType(crs); + } + + @Override + public TypeID typeId() { + return TypeID.GEOMETRY; + } + + public String crs() { + return crs; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof GeometryType)) { + return false; + } + + GeometryType that = (GeometryType) o; + return Objects.equals(crs, that.crs); + } + + @Override + public int hashCode() { + return Objects.hash(GeometryType.class, crs); + } + + @Override + public String toString() { + if (crs == null) { + return "geometry"; + } + + return String.format("geometry(%s)", crs); + } + } + + public static class GeographyType extends PrimitiveType { + + public static final String DEFAULT_CRS = "OGC:CRS84"; + + private final String crs; + private final EdgeAlgorithm algorithm; + + private GeographyType(String crs, EdgeAlgorithm algorithm) { + if (crs != null) { + Preconditions.checkArgument(!crs.isEmpty(), "Invalid CRS: (empty string)"); + Preconditions.checkArgument( + crs.trim().equals(crs), "CRS must not have leading or trailing spaces: '%s'", crs); + this.crs = crs; + } else { + this.crs = null; + } + + this.algorithm = algorithm; + } + + private GeographyType() { + this.crs = null; + this.algorithm = null; + } + + public static GeographyType crs84() { + return new GeographyType(); + } + + public static GeographyType forCRS(String crs) { Review Comment: Renamed it back to `of`. ########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -543,6 +565,148 @@ public int hashCode() { } } + public static class GeometryType extends PrimitiveType { + + private final String crs; + + private GeometryType(String crs) { + if (crs != null) { + Preconditions.checkArgument(!crs.isEmpty(), "Invalid CRS: (empty string)"); + Preconditions.checkArgument( + crs.trim().equals(crs), "CRS must not have leading or trailing spaces: '%s'", crs); + this.crs = crs; + } else { + this.crs = null; + } + } + + private GeometryType() { + crs = null; + } + + public static GeometryType crs84() { + return new GeometryType(); + } + + public static GeometryType of(String crs) { + return new GeometryType(crs); + } + + @Override + public TypeID typeId() { + return TypeID.GEOMETRY; + } + + public String crs() { + return crs; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof GeometryType)) { + return false; + } + + GeometryType that = (GeometryType) o; + return Objects.equals(crs, that.crs); + } + + @Override + public int hashCode() { + return Objects.hash(GeometryType.class, crs); + } + + @Override + public String toString() { + if (crs == null) { + return "geometry"; + } + + return String.format("geometry(%s)", crs); + } + } + + public static class GeographyType extends PrimitiveType { + + public static final String DEFAULT_CRS = "OGC:CRS84"; + + private final String crs; + private final EdgeAlgorithm algorithm; + + private GeographyType(String crs, EdgeAlgorithm algorithm) { + if (crs != null) { + Preconditions.checkArgument(!crs.isEmpty(), "Invalid CRS: (empty string)"); + Preconditions.checkArgument( + crs.trim().equals(crs), "CRS must not have leading or trailing spaces: '%s'", crs); + this.crs = crs; + } else { + this.crs = null; + } + + this.algorithm = algorithm; + } + + private GeographyType() { + this.crs = null; + this.algorithm = null; + } + + public static GeographyType crs84() { Review Comment: Reordered static factory methods. ########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -543,6 +565,148 @@ public int hashCode() { } } + public static class GeometryType extends PrimitiveType { + + private final String crs; + + private GeometryType(String crs) { + if (crs != null) { + Preconditions.checkArgument(!crs.isEmpty(), "Invalid CRS: (empty string)"); + Preconditions.checkArgument( + crs.trim().equals(crs), "CRS must not have leading or trailing spaces: '%s'", crs); + this.crs = crs; + } else { + this.crs = null; + } + } + + private GeometryType() { + crs = null; + } + + public static GeometryType crs84() { + return new GeometryType(); + } + + public static GeometryType of(String crs) { + return new GeometryType(crs); + } + + @Override + public TypeID typeId() { + return TypeID.GEOMETRY; + } + + public String crs() { + return crs; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } else if (!(o instanceof GeometryType)) { + return false; + } + + GeometryType that = (GeometryType) o; + return Objects.equals(crs, that.crs); + } + + @Override + public int hashCode() { + return Objects.hash(GeometryType.class, crs); + } + + @Override + public String toString() { + if (crs == null) { + return "geometry"; + } + + return String.format("geometry(%s)", crs); + } + } + + public static class GeographyType extends PrimitiveType { + + public static final String DEFAULT_CRS = "OGC:CRS84"; + + private final String crs; + private final EdgeAlgorithm algorithm; + + private GeographyType(String crs, EdgeAlgorithm algorithm) { + if (crs != null) { + Preconditions.checkArgument(!crs.isEmpty(), "Invalid CRS: (empty string)"); + Preconditions.checkArgument( + crs.trim().equals(crs), "CRS must not have leading or trailing spaces: '%s'", crs); + this.crs = crs; + } else { + this.crs = null; Review Comment: Changed it to be similar to the constructor of `GeometryType`. ########## api/src/test/java/org/apache/iceberg/types/TestTypes.java: ########## @@ -79,6 +95,77 @@ public void fromPrimitiveString() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Types.fromPrimitiveString("abcdefghij")) .withMessage("Cannot parse type string to primitive: abcdefghij"); + + assertThat(Types.fromPrimitiveString("geometry")).isEqualTo(Types.GeometryType.crs84()); + assertThat(Types.fromPrimitiveString("Geometry")).isEqualTo(Types.GeometryType.crs84()); + assertThat(Types.fromPrimitiveString("geometry(srid:3857)")) + .isEqualTo(Types.GeometryType.of("srid:3857")); + assertThat(Types.fromPrimitiveString("geometry( srid:3857 )")) + .isEqualTo(Types.GeometryType.of("srid:3857")); + assertThat(Types.fromPrimitiveString("geometry( srid: 3857 )")) + .isEqualTo(Types.GeometryType.of("srid: 3857")); + assertThat(Types.fromPrimitiveString("Geometry( projjson:TestIdentifier )")) + .isEqualTo(Types.GeometryType.of("projjson:TestIdentifier")); + + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Types.fromPrimitiveString("geometry()")) + .withMessageContaining("Cannot parse type string to primitive"); Review Comment: I've tweaked the regex to match this regex with the first group being empty, now it will emit `Invalid CRS: (empty string)`. -- 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