diff --git a/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java b/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java index d1ff5db66ad4..bb3880b44c5f 100644 --- a/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java +++ b/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java @@ -166,6 +166,8 @@ private static String convertToTypeString(Type type) { return "timestamp"; case FIXED: case BINARY: + case GEOMETRY: + case GEOGRAPHY: return "binary"; case VARIANT: return "unknown"; diff --git a/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveSchemaUtil.java b/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveSchemaUtil.java index 59c19a5d095d..12cf235f62a1 100644 --- a/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveSchemaUtil.java +++ b/hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveSchemaUtil.java @@ -33,6 +33,7 @@ import org.apache.iceberg.Schema; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.types.EdgeAlgorithm; import org.apache.iceberg.types.Type; import org.apache.iceberg.types.Types; import org.junit.jupiter.api.Test; @@ -212,6 +213,44 @@ public void testVariantTypeConvertToHiveSchema() { assertThat(hiveSchema).containsExactly(new FieldSchema("variant_field", "unknown", null)); } + @Test + public void testGeometryTypeConvertToHiveSchema() { + Schema schema = new Schema(optional(0, "geometry_field", Types.GeometryType.crs84())); + List hiveSchema = HiveSchemaUtil.convert(schema); + assertThat(hiveSchema).containsExactly(new FieldSchema("geometry_field", "binary", null)); + } + + @Test + public void testGeometryTypeWithCustomCrsConvertToHiveSchema() { + Schema schema = new Schema(optional(0, "geometry_field", Types.GeometryType.of("EPSG:3857"))); + List hiveSchema = HiveSchemaUtil.convert(schema); + assertThat(hiveSchema).containsExactly(new FieldSchema("geometry_field", "binary", null)); + } + + @Test + public void testGeographyTypeConvertToHiveSchema() { + Schema schema = new Schema(optional(0, "geography_field", Types.GeographyType.crs84())); + List hiveSchema = HiveSchemaUtil.convert(schema); + assertThat(hiveSchema).containsExactly(new FieldSchema("geography_field", "binary", null)); + } + + @Test + public void testGeographyTypeWithCustomCrsConvertToHiveSchema() { + Schema schema = new Schema(optional(0, "geography_field", Types.GeographyType.of("EPSG:4326"))); + List hiveSchema = HiveSchemaUtil.convert(schema); + assertThat(hiveSchema).containsExactly(new FieldSchema("geography_field", "binary", null)); + } + + @Test + public void testGeographyTypeWithVincentyAlgorithmConvertToHiveSchema() { + Schema schema = + new Schema( + optional( + 0, "geography_field", Types.GeographyType.of("OGC:CRS84", EdgeAlgorithm.VINCENTY))); + List hiveSchema = HiveSchemaUtil.convert(schema); + assertThat(hiveSchema).containsExactly(new FieldSchema("geography_field", "binary", null)); + } + protected List getSupportedFieldSchemas() { List fields = Lists.newArrayListWithCapacity(10); fields.add(new FieldSchema("c_float", serdeConstants.FLOAT_TYPE_NAME, "float comment"));