anoopj commented on code in PR #17578:
URL: https://github.com/apache/iceberg/pull/17578#discussion_r3750916965


##########
parquet/src/test/java/org/apache/iceberg/parquet/TestPruneColumns.java:
##########
@@ -305,6 +310,110 @@ public void testVariant() {
     assertThat(actual).as("Pruned schema should be 
matched").isEqualTo(expected);
   }
 
+  @Test
+  public void acceptsMatchingGeospatialParameters() {
+    MessageType fileSchema =
+        Types.buildMessage()
+            .optional(PrimitiveTypeName.BINARY)
+            .as(LogicalTypeAnnotation.geometryType(null))
+            .id(1)
+            .named("geom_default")
+            .optional(PrimitiveTypeName.BINARY)
+            .as(LogicalTypeAnnotation.geometryType("EPSG:3857"))
+            .id(2)
+            .named("geom_projected")
+            .optional(PrimitiveTypeName.BINARY)
+            .as(LogicalTypeAnnotation.geographyType(null, null))
+            .id(3)
+            .named("geog_default")
+            .optional(PrimitiveTypeName.BINARY)
+            .as(
+                LogicalTypeAnnotation.geographyType(
+                    "EPSG:4326", EdgeInterpolationAlgorithm.ANDOYER))
+            .id(4)
+            .named("geog_custom")
+            .named("table");
+
+    Schema projection =
+        new Schema(
+            NestedField.optional(1, "geom_default", GeometryType.crs84()),
+            NestedField.optional(2, "geom_projected", 
GeometryType.of("epsg:3857")),
+            NestedField.optional(3, "geog_default", GeographyType.crs84()),
+            NestedField.optional(
+                4, "geog_custom", GeographyType.of("epsg:4326", 
EdgeAlgorithm.ANDOYER)));
+
+    assertThat(ParquetSchemaUtil.pruneColumns(fileSchema, 
projection)).isEqualTo(fileSchema);
+  }
+
+  @Test
+  public void rejectsGeometryCrsMismatch() {
+    MessageType fileSchema =
+        Types.buildMessage()
+            .optional(PrimitiveTypeName.BINARY)
+            .as(LogicalTypeAnnotation.geometryType("EPSG:3857"))
+            .id(1)
+            .named("geom")
+            .named("table");
+    Schema projection = new Schema(NestedField.optional(1, "geom", 
GeometryType.crs84()));
+
+    assertThatThrownBy(() -> ParquetSchemaUtil.pruneColumns(fileSchema, 
projection))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining("Cannot read Parquet type")
+        .hasMessageContaining("geometry(OGC:CRS84)");
+  }
+
+  @Test
+  public void rejectsGeometryCrsMismatchWithoutIds() {
+    MessageType fileSchema =
+        Types.buildMessage()
+            .optional(PrimitiveTypeName.BINARY)
+            .as(LogicalTypeAnnotation.geometryType("EPSG:3857"))
+            .named("geom")
+            .named("table");
+    Schema projection = new Schema(NestedField.optional(1, "geom", 
GeometryType.crs84()));
+
+    assertThatThrownBy(() -> 
ParquetSchemaUtil.pruneColumnsFallback(fileSchema, projection))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining("Cannot read Parquet type")
+        .hasMessageContaining("geometry(OGC:CRS84)");
+  }
+
+  @Test
+  public void rejectsGeographyCrsMismatch() {
+    MessageType fileSchema =
+        Types.buildMessage()
+            .optional(PrimitiveTypeName.BINARY)
+            .as(
+                LogicalTypeAnnotation.geographyType(
+                    "EPSG:4326", EdgeInterpolationAlgorithm.SPHERICAL))
+            .id(1)
+            .named("geog")
+            .named("table");
+    Schema projection = new Schema(NestedField.optional(1, "geog", 
GeographyType.crs84()));
+
+    assertThatThrownBy(() -> ParquetSchemaUtil.pruneColumns(fileSchema, 
projection))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessageContaining("Cannot read Parquet type")
+        .hasMessageContaining("geography(OGC:CRS84, spherical)");
+  }
+
+  @Test
+  public void rejectsGeographyAlgorithmMismatch() {
+    MessageType fileSchema =
+        Types.buildMessage()
+            .optional(PrimitiveTypeName.BINARY)
+            .as(LogicalTypeAnnotation.geographyType("OGC:CRS84", 
EdgeInterpolationAlgorithm.KARNEY))
+            .id(1)
+            .named("geog")
+            .named("table");
+    Schema projection = new Schema(NestedField.optional(1, "geog", 
GeographyType.crs84()));
+
+    assertThatThrownBy(() -> ParquetSchemaUtil.pruneColumns(fileSchema, 
projection))

Review Comment:
   From what I understood, the exception is thrown because the algorithm is 
different (ie EdgeInterPolationAlgorithm.KARNEY). So shouldn't we be looking 
for that in the error 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to