Skip to content

read_iceberg drops rows when a filter on a bucket, truncate or date-transform partition column is wrapped in NOT #7657

Open

Description

@RyanLin5967

Describe the bug

Currently, rewrite_predicate_for_partitioning (src/daft-scan/src/expr_rewriter.rs) rewrites every =, <, <=, > and >= comparison on a partition source column into a comparison on the partition value, wherever it sits in the predicate tree, including under NOT. For a lossy transform the rewritten comparison is only a superset of the matching partitions (d < '2024-03-10' becomes d_month <= 2024-03), and negating a superset gives a subset, so NOT (d < '2024-03-10') becomes d_month > 2024-03 and prunes the partition holding the matching rows. The same happens to NOT (i = 3) on bucket(i) (every other row in 3's bucket is dropped) and NOT (s = 'ab') on truncate(s, 1).

To Reproduce

import datetime as dt, tempfile
import daft, pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.schema import Schema
from pyiceberg.types import NestedField, DateType, LongType
from pyiceberg.partitioning import PartitionSpec, PartitionField
from pyiceberg.transforms import MonthTransform

wh = tempfile.mkdtemp()
cat = SqlCatalog("c", uri=f"sqlite:///{wh}/cat.db", warehouse=f"file://{wh}")
cat.create_namespace("db")
sch = Schema(NestedField(1, "id", LongType()), NestedField(2, "d", DateType()))
t = cat.create_table("db.t", schema=sch, partition_spec=PartitionSpec(PartitionField(2, 1000, MonthTransform(), "d_month")))
t.append(pa.table({"id": [1, 2], "d": [dt.date(2024, 3, 1), dt.date(2024, 3, 20)]}, schema=sch.as_arrow()))

df = daft.read_iceberg(t)
print(df.where(~(daft.col("d") < dt.date(2024, 3, 10))).to_pydict()["id"])
# []
print(df.where(daft.col("d") >= dt.date(2024, 3, 10)).to_pydict()["id"])
# [2]

Without the partition spec, both filters return [2].

Expected behavior

[2] for both filters. A comparison under NOT should not be rewritten onto a lossy partition transform (or the predicate should be put in negation normal form first, as Iceberg's own projections do).

Component(s)

Data Sources & Sinks

Additional context

daft 0.7.26, pyiceberg 0.12.0, pyiceberg-core 0.10.1, pyarrow 25.0.1, Python 3.12.13, macOS 26.6.2, arm64 (Darwin 25.6.0). rewrite_predicate_for_partitioning has no case for Expr::Not on main.

Activity

  1. added
    bug
    on Oct 30, 2026
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

    bugneeds triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions