RyanLin5967 opened a new issue, #4182:
URL: https://github.com/apache/iceberg-python/issues/4182
### Apache Iceberg version
0.12.0 (latest release)
### Please describe the bug 🐞
Currently, `older_than` converts its cutoff with `datetime_to_millis`, which
takes a naive datetime as UTC, so in Tokyo the docs' `older_than(datetime.now()
- timedelta(days=3))` keeps only 63 hours of snapshots. An aware datetime is
read correctly.
```python
import os, time, tempfile
os.environ["TZ"] = "Asia/Tokyo" # UTC+9, any zone east of UTC does it
time.tzset()
from datetime import datetime, timedelta
import pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
cat = SqlCatalog("c", uri="sqlite:///:memory:",
warehouse=f"file://{tempfile.mkdtemp()}")
cat.create_namespace("ns")
t = cat.create_table("ns.t", schema=pa.schema([("x", pa.int64())]))
for x in (1, 2, 3):
t.append(pa.table({"x": [x]}))
t.maintenance.expire_snapshots().older_than(datetime.now() -
timedelta(hours=1)).commit()
print(len(cat.load_table("ns.t").snapshots()))
# 1, should be 3
# all three snapshots are seconds old, so none is older than an hour
```
West of UTC the cutoff lands early instead, so it keeps snapshots it should
expire.
tested on pyiceberg 0.12.0 and main
### Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [ ] I would be willing to contribute a fix for this bug with guidance from
the Iceberg community
- [x] I cannot contribute a fix for this bug at this time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]