diff --git a/pyiceberg/utils/schema_conversion.py b/pyiceberg/utils/schema_conversion.py index ec2fccd509..c73b3ada7d 100644 --- a/pyiceberg/utils/schema_conversion.py +++ b/pyiceberg/utils/schema_conversion.py @@ -69,8 +69,10 @@ LOGICAL_FIELD_TYPE_MAPPING: Dict[Tuple[str, str], PrimitiveType] = { ("date", "int"): DateType(), ("time-micros", "long"): TimeType(), + ("timestamp-millis", "int"): TimestampType(), ("timestamp-micros", "long"): TimestampType(), ("uuid", "fixed"): UUIDType(), + ("uuid", "string"): UUIDType(), } AvroType = Union[str, Any] diff --git a/tests/utils/test_schema_conversion.py b/tests/utils/test_schema_conversion.py index e60a89563f..a5c45447ff 100644 --- a/tests/utils/test_schema_conversion.py +++ b/tests/utils/test_schema_conversion.py @@ -33,7 +33,9 @@ NestedField, StringType, StructType, + TimestampType, UnknownType, + UUIDType, ) from pyiceberg.utils.schema_conversion import AvroSchemaConversion @@ -327,6 +329,30 @@ def test_convert_date_type() -> None: assert actual == DateType() +def test_convert_uuid_str_type() -> None: + avro_logical_type = {"type": "string", "logicalType": "uuid"} + actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type) + assert actual == UUIDType() + + +def test_convert_uuid_fixed_type() -> None: + avro_logical_type = {"type": "fixed", "logicalType": "uuid"} + actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type) + assert actual == UUIDType() + + +def test_convert_timestamp_millis_type() -> None: + avro_logical_type = {"type": "int", "logicalType": "timestamp-millis"} + actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type) + assert actual == TimestampType() + + +def test_convert_timestamp_micros_type() -> None: + avro_logical_type = {"type": "int", "logicalType": "timestamp-micros"} + actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type) + assert actual == TimestampType() + + def test_unknown_logical_type() -> None: """Test raising a ValueError when converting an unknown logical type as part of an Avro schema conversion""" avro_logical_type = {"type": "bytes", "logicalType": "date"}