Skip to content

Paimon connector does not use row predicates for file pruning #7702

Open

Description

@JustinBinber

Describe the bug

The Paimon connector guide describes file-level skipping for filters passed to df.where(). On an ordinary, unpartitioned append-only Parquet table, Daft still creates a scan task for a file that PyPaimon can eliminate using its file statistics. The returned rows are correct in this reproduction.

To reproduce

  • OS: Windows 10 22H2 (x64)
  • Python: 3.11.7
  • Daft: 0.7.26, native runner
  • PyPaimon: 1.3.1
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch

import daft
import pyarrow as pa
import pypaimon
from daft.io.paimon.paimon_scan import PaimonDataSource

tasks = []
original_get_tasks = PaimonDataSource.get_tasks

async def record_tasks(self, pushdowns):
    async for task in original_get_tasks(self, pushdowns):
        tasks.append(task)
        yield task

with TemporaryDirectory() as directory:
    path = Path(directory)
    warehouse = "file://" + path.as_posix() if path.drive else str(path)
    catalog = pypaimon.CatalogFactory.create({"warehouse": warehouse})
    catalog.create_database("repro", ignore_if_exists=True)
    schema = pypaimon.Schema.from_pyarrow_schema(pa.schema([("id", pa.int64())]))
    catalog.create_table("repro.records", schema, ignore_if_exists=True)
    table = catalog.get_table("repro.records")

    builder = table.new_batch_write_builder()
    writer = builder.new_write()
    committer = builder.new_commit()
    try:
        writer.write_arrow(pa.table({"id": [4, 5]}))
        committer.commit(writer.prepare_commit())
    finally:
        writer.close()
        committer.close()

    read_builder = table.new_read_builder()
    predicate = read_builder.new_predicate_builder().greater_than("id", 99)
    splits = read_builder.with_filter(predicate).new_scan().plan().splits()
    print("Splits planned by PyPaimon with id > 99:", len(splits))
    with patch.object(PaimonDataSource, "get_tasks", record_tasks):
        result = daft.read_paimon(table).where(daft.col("id") > 99).to_pydict()
    print("Daft tasks:", len(tasks))
    print("Daft result:", result)
    assert len(splits) == 0
    assert result == {"id": []}
    assert len(tasks) == 0

Observed:

Splits planned by PyPaimon with id > 99: 0
Daft tasks: 1
Daft result: {'id': []}

I get the same result with DAFT_DEV_ENABLE_STRICT_FILTER_PUSHDOWN=true.

Expected behavior

When PyPaimon can rule out the only data file using the pushed predicate, Daft should produce zero scan tasks and return the same empty result.

Component(s)

Data Sources & Sinks

Additional context

The same wiring is present on main at eabd8474d7fd42fee90dde8370a244ac564ccf0c. PaimonDataSource.get_tasks() only passes a predicate to the read builder when push_filters() has set _paimon_predicate. However, the Rust wrapper used by Python DataSource returns None from as_pushdown_filter(). The read builder therefore never sees the non-partition predicate in this example.

A possible connector-local fix is to derive pruning predicates from pushdowns.filters when planning tasks, similar to the Iceberg source, and keep the original Daft row filter. The conversion needs to preserve comparison direction before it is used for pruning. I also verified that the current visitor translates lit(3) < col("id") into id < 3, which causes PyPaimon to reject the file containing [4, 5] when that converted predicate is passed directly to its planner.

I can work on a regression test and fix if maintainers agree on the scope.

Activity

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