@@ -379,6 +379,10 @@ def _convert_logical_type(self, avro_logical_type: Dict[str, Any]) -> IcebergTyp
379379 physical_type = avro_logical_type ["type" ]
380380 if logical_type == "decimal" :
381381 return self ._convert_logical_decimal_type (avro_logical_type )
382+ elif logical_type == "geography" :
383+ return self ._convert_logical_geography_type (avro_logical_type )
384+ elif logical_type == "geometry" :
385+ return self ._convert_logical_geometry_type (avro_logical_type )
382386 elif logical_type == "map" :
383387 return self ._convert_logical_map_type (avro_logical_type )
384388 elif logical_type == "timestamp-micros" :
@@ -418,6 +422,58 @@ def _convert_logical_decimal_type(self, avro_type: Dict[str, Any]) -> DecimalTyp
418422 """
419423 return DecimalType (precision = avro_type ["precision" ], scale = avro_type ["scale" ])
420424
425+ def _convert_logical_geography_type (self , avro_type : Dict [str , Any ]) -> GeographyType :
426+ """Convert an avro type to an Iceberg GeographyType.
427+
428+ Args:
429+ avro_type: The Avro type.
430+
431+ Examples:
432+ >>> from pyiceberg.utils.schema_conversion import AvroSchemaConversion
433+ >>> avro_geography_type = {
434+ ... "type": "bytes",
435+ ... "logicalType": "geography",
436+ ... "crs": 'OGC:CRS84',
437+ ... "edge_algorithm": 'spherical'
438+ ... }
439+ >>> actual = AvroSchemaConversion()._convert_logical_decimal_type(geography)
440+ >>> expected = GeographyType(
441+ ... crs='OGC:CRS84',
442+ ... edge_algorithm=EdgeAlgorithm.SPHERICAL
443+ ... )
444+ >>> actual == expected
445+ True
446+
447+ Returns:
448+ A Iceberg GeographyType.
449+ """
450+ return GeographyType (crs = avro_type ["crs" ], edge_algorithm = avro_type ["edge_algorithm" ])
451+
452+ def _convert_logical_geometry_type (self , avro_type : Dict [str , Any ]) -> GeometryType :
453+ """Convert an avro type to an Iceberg GeometryType.
454+
455+ Args:
456+ avro_type: The Avro type.
457+
458+ Examples:
459+ >>> from pyiceberg.utils.schema_conversion import AvroSchemaConversion
460+ >>> avro_geometry_type = {
461+ ... "type": "bytes",
462+ ... "logicalType": "geometry",
463+ ... "crs": "OGC:CRS84
464+ ... }
465+ >>> actual = AvroSchemaConversion()._convert_logical_decimal_type(avro_geometry_type)
466+ >>> expected = GeometryType(
467+ ... crs="OGC:CRS84"
468+ ... )
469+ >>> actual == expected
470+ True
471+
472+ Returns:
473+ A Iceberg GeometryType.
474+ """
475+ return GeometryType (crs = avro_type ["crs" ])
476+
421477 def _convert_logical_map_type (self , avro_type : Dict [str , Any ]) -> MapType :
422478 """Convert an avro map type to an Iceberg MapType.
423479
@@ -643,17 +699,17 @@ def visit_binary(self, binary_type: BinaryType) -> AvroType:
643699
644700 def visit_geography (self , geography_type : GeographyType ) -> AvroType :
645701 return {
646- "type" : "bytes" ,
647- "logicalType" : "geography" ,
648- "crs" : geography_type .crs ,
702+ "type" : "bytes" ,
703+ "logicalType" : "geography" ,
704+ "crs" : geography_type .crs ,
649705 "edge_algorithm" : geography_type .edge_algorithm ,
650706 }
651707
652708 def visit_geometry (self , geometry_type : GeometryType ) -> AvroType :
653709 return {
654- "type" : "bytes" ,
655- "logicalType" : "geometry" ,
656- "crs" : geometry_type .crs ,
710+ "type" : "bytes" ,
711+ "logicalType" : "geometry" ,
712+ "crs" : geometry_type .crs ,
657713 }
658714
659715 def visit_unknown (self , unknown_type : UnknownType ) -> AvroType :
0 commit comments