Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyiceberg/utils/schema_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@

LOGICAL_FIELD_TYPE_MAPPING: Dict[Tuple[str, str], PrimitiveType] = {
("date", "int"): DateType(),
("time-millis", "int"): TimeType(),
("time-micros", "long"): TimeType(),
("timestamp-millis", "int"): TimestampType(),
("timestamp-millis", "long"): TimestampType(),
Comment on lines +71 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! heres the corresponding type conversion for timestamp-millis in java https://github.com/apache/iceberg/blob/d3d5662aee19dd1799fd12740c64eadcb7f8da8b/core/src/main/java/org/apache/iceberg/avro/GenericAvroReader.java#L184-L187

I see time-micros but I dont see time-millis in here though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I was just looking into the Avro Spec for logicalTypes and not in the iceberg Java Code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional since Iceberg does not support millis, just micros, and nanos in V3+

("timestamp-micros", "long"): TimestampType(),
("uuid", "fixed"): UUIDType(),
("uuid", "string"): UUIDType(),
Expand Down
15 changes: 14 additions & 1 deletion tests/utils/test_schema_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
StringType,
StructType,
TimestampType,
TimeType,
UnknownType,
UUIDType,
)
Expand Down Expand Up @@ -341,8 +342,20 @@ def test_convert_uuid_fixed_type() -> None:
assert actual == UUIDType()


def test_convert_time_millis_type() -> None:
avro_logical_type = {"type": "int", "logicalType": "time-millis"}
actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type)
assert actual == TimeType()
Comment on lines +345 to +348
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if theres a better way to test these type conversions..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could put them in 1 test and parameterize it with pytest



def test_convert_time_micros_type() -> None:
avro_logical_type = {"type": "long", "logicalType": "time-micros"}
actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type)
assert actual == TimeType()


def test_convert_timestamp_millis_type() -> None:
avro_logical_type = {"type": "int", "logicalType": "timestamp-millis"}
avro_logical_type = {"type": "long", "logicalType": "timestamp-millis"}
actual = AvroSchemaConversion()._convert_logical_type(avro_logical_type)
assert actual == TimestampType()

Expand Down