Skip to content

Iceberg partition transforms diverge from the spec: decimal bucket, string truncate, pre-1970 hour #7648

Closed

Description

@YuangGao

Describe the bug

Three Iceberg partition transforms compute values that differ from the spec and from PyIceberg / Java:

  • bucket on decimals hashes the wrong bytes for negatives, zero, and values whose leading bit is set (e.g. 1.28, unscaled 128). The spec hashes the minimal two's-complement bytes, sign bit included (0x00 0x80 for 128).
  • truncate on strings slices bytes rather than code points, so non-ASCII strings fail.
  • hour divides toward zero, so timestamps before 1970 land one hour late.

Daft uses these both to partition writes and to prune reads, so filters such as col == Decimal("-12.34") silently drop matching rows from tables written by Spark or PyIceberg, and Daft-written tables are mispartitioned for other engines.

To Reproduce

import datetime
import decimal

from pyiceberg.transforms import BucketTransform, HourTransform
from pyiceberg.types import DecimalType, TimestampType

import daft
from daft.functions import partition_hours, partition_iceberg_bucket, partition_iceberg_truncate

dec, ts = decimal.Decimal("1.28"), datetime.datetime(1969, 12, 31, 23, 59, 59)
df = daft.from_pydict({"dec": [dec], "ts": [ts], "s": ["héllo"]})

print(df.select(partition_iceberg_bucket(df["dec"], 16), partition_hours(df["ts"])).to_pydict())
# {'dec_bucket': [13], 'ts_hours': [0]}
print(BucketTransform(16).transform(DecimalType(3, 2))(dec), HourTransform().transform(TimestampType())(ts))
# 5 -1
df.select(partition_iceberg_truncate(df["s"], 2)).collect()
# DaftCoreException: Compute error: The offset 2 is at an invalid utf-8 boundary.

Expected behavior

Match the spec: bucket 5, hour -1, and "hé" for the truncate.

Component(s)

Data Sources & Sinks

Additional context

test_partitioning_hours currently asserts the truncating behavior (-1 µs → hour 0). Happy to send a fix.

Activity

  1. added a commit that references this issue on Nov 4, 2026
    50bd9c1
  2. added a commit that references this issue on Nov 10, 2026
    865feff
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