Kontinuation commented on code in PR #12346: URL: https://github.com/apache/iceberg/pull/12346#discussion_r2008613986
########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -58,9 +58,16 @@ private Types() {} .put(BinaryType.get().toString(), BinaryType.get()) .put(UnknownType.get().toString(), UnknownType.get()) .put(VariantType.get().toString(), VariantType.get()) + .put(GeometryType.crs84().toString(), GeometryType.crs84()) + .put(GeographyType.crs84().toString(), GeographyType.crs84()) .buildOrThrow(); private static final Pattern FIXED = Pattern.compile("fixed\\[\\s*(\\d+)\\s*\\]"); + private static final Pattern GEOMETRY_PARAMETERS = + Pattern.compile("geometry\\s*(?:\\(\\s*([^,]+?)\\s*\\))?", Pattern.CASE_INSENSITIVE); + private static final Pattern GEOGRAPHY_PARAMETERS = + Pattern.compile( + "geography\\s*(?:\\(\\s*([^,]+)\\s*(?:,\\s*(\\w*)\\s*)?\\))?", Pattern.CASE_INSENSITIVE); Review Comment: I have tweaked the regex to make it work without requiring trimming, ########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -58,9 +58,16 @@ private Types() {} .put(BinaryType.get().toString(), BinaryType.get()) .put(UnknownType.get().toString(), UnknownType.get()) .put(VariantType.get().toString(), VariantType.get()) + .put(GeometryType.crs84().toString(), GeometryType.crs84()) + .put(GeographyType.crs84().toString(), GeographyType.crs84()) .buildOrThrow(); private static final Pattern FIXED = Pattern.compile("fixed\\[\\s*(\\d+)\\s*\\]"); + private static final Pattern GEOMETRY_PARAMETERS = + Pattern.compile("geometry\\s*(?:\\(\\s*([^,]+?)\\s*\\))?", Pattern.CASE_INSENSITIVE); Review Comment: Use `([^)]+?)` to capture more cases and check for `,` after matching. ########## api/src/main/java/org/apache/iceberg/types/Types.java: ########## @@ -70,6 +77,21 @@ public static Type fromTypeName(String typeString) { return TYPES.get(lowerTypeString); } + Matcher geometry = GEOMETRY_PARAMETERS.matcher(typeString); + if (geometry.matches()) { + String crs = geometry.group(1); + return GeometryType.of(crs != null ? crs.trim() : null); + } + + Matcher geography = GEOGRAPHY_PARAMETERS.matcher(typeString); + if (geography.matches()) { + String crs = geography.group(1); + String algorithmName = geography.group(2); + EdgeAlgorithm algorithm = + algorithmName == null ? null : EdgeAlgorithm.fromName(algorithmName.trim()); + return GeographyType.of(crs != null ? crs.trim() : null, algorithm); Review Comment: Removed trim, as the regex was modified to handle trimming. ########## 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() { Review Comment: Reordered. * Static members comes first * Then static factory methods * Then private members * Then no-arg constructor * Then other constructors -- 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