Skip to content

upsert rewrites unchanged rows that contain NaN on every call #4618

Backlog

Description

@KartikGupta2007

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.

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

  • 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

Activity

  1. ksaiharshavinay commented on Dec 4, 2026

    @ksaiharshavinay

    I'd like to take this one.

    Plan: reproduce with the script from the report, then fix the upsert row-matching so a NaN in a float column compares equal to NaN for matching purposes (checking how scans handled the analogous NaN case in #4346 for the house pattern), so re-upserting identical data reports no updates and commits no new snapshots. I'll add a regression test based on the repro.

    Disclosure: I work with AI assistance and review everything myself before posting.

  2. KartikGupta2007 commented on Dec 4, 2026

    @KartikGupta2007
    Author

    As mentioned in the report, I'd planned to send the fix and a test for this myself. I'll wait for a maintainer to say which way they'd like it to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions