KartikGupta2007 opened a new issue, #4618:
URL: https://github.com/apache/iceberg-python/issues/4618
### Apache Iceberg version
main (development)
### Please describe the bug 🐞
`upsert` treats an unchanged row as updated when a float column holds NaN.
Upserting the exact data that is already in the table reports `rows_updated=1`
and commits two snapshots every time: an overwrite that rewrites the data file
and an append.
```python
import tempfile
import pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.schema import Schema
from pyiceberg.types import DoubleType, IntegerType, NestedField
tmp = tempfile.mkdtemp()
catalog = SqlCatalog("default", uri=f"sqlite:///{tmp}/catalog.db",
warehouse=f"file://{tmp}")
catalog.create_namespace("db")
schema = Schema(
NestedField(1, "id", IntegerType(), required=True),
NestedField(2, "v", DoubleType(), required=False),
identifier_field_ids=[1],
)
tbl = catalog.create_table("db.t", schema)
df = pa.Table.from_pylist(
[{"id": 1, "v": 1.0}, {"id": 2, "v": None}, {"id": 3, "v":
float("nan")}],
schema=pa.schema([pa.field("id", pa.int32(), nullable=False),
pa.field("v", pa.float64())]),
)
tbl.append(df)
print(len(tbl.snapshots())) # 1
print(tbl.upsert(df)) # same data again
print(len(tbl.snapshots()))
```
Output on main (9abf5b1), pyarrow 26.0.1:
```
1
UpsertResult(rows_updated=1, rows_inserted=0)
3
```
Without the NaN row the same script prints `rows_updated=0` and the table
stays at 1 snapshot.
`_values_differ` in `pyiceberg/table/upsert_util.py` compares with
`pc.equal`, and NaN never equals NaN there. Two nulls are already treated as
equal (`both_null`), but two NaNs are not. The description of #4334 says two
NaN values in the same column compare equal, but the code doesn't do that yet
and there is no NaN test.
A fix could OR `is_nan(source) & is_nan(target)` into `both_null` for
floating-point columns, with a test in `tests/table/test_upsert.py`. I can open
a PR with that if it sounds right.
### Willingness to contribute
- [x] 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
- [ ] 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]