Apache Iceberg version
None
Please describe the bug 🐞
While looking at the partitioning code I noticed that _to_partition_representation (pyiceberg/partitioning.py) doesn't handle
the v3 nano timestamp types.
For a normal TimestampType column, a datetime partition value gets converted to microseconds since epoch. For
TimestampNanoType / TimestamptzNanoType there is no handler, so the value just passes through unchanged:
from datetime import datetime
from pyiceberg.partitioning import _to_partition_representation
from pyiceberg.types import TimestampType, TimestampNanoType
dt = datetime(2020, 1, 1)
_to_partition_representation(TimestampType(), dt) # 1577836800000000
_to_partition_representation(TimestampNanoType(), dt) # datetime.datetime(2020, 1, 1, 0, 0) — not converted
That datetime object then ends up in the DataFile.partition record, and the manifest writer expects an int there
(TimestampNanoWriter calls write_int), so writing to a table with an identity partition on a timestamp_ns column would fail.
Users can't hit this today because writing v3 is still blocked (#1551), but it will surface once that lands. It looks like an
oversight #1632 added nano support to transforms, readers/writers and conversions, but partitioning.py was never updated.
Expected: datetime values for nano timestamp columns should convert to nanoseconds since epoch, the same way the microsecond
types convert to micros.
Willingness to contribute
Apache Iceberg version
None
Please describe the bug 🐞
While looking at the partitioning code I noticed that
_to_partition_representation(pyiceberg/partitioning.py) doesn't handlethe v3 nano timestamp types.
For a normal
TimestampTypecolumn, adatetimepartition value gets converted to microseconds since epoch. ForTimestampNanoType/TimestamptzNanoTypethere is no handler, so the value just passes through unchanged:That
datetimeobject then ends up in theDataFile.partitionrecord, and the manifest writer expects an int there(
TimestampNanoWritercallswrite_int), so writing to a table with an identity partition on atimestamp_nscolumn would fail.Users can't hit this today because writing v3 is still blocked (#1551), but it will surface once that lands. It looks like an
oversight #1632 added nano support to transforms, readers/writers and conversions, but
partitioning.pywas never updated.Expected:
datetimevalues for nano timestamp columns should convert to nanoseconds since epoch, the same way the microsecondtypes convert to micros.
Willingness to contribute