[Bug] PyPaimon named ROW projection rejects filters on a colliding top-level column
Search before asking
- [x] I searched existing issues and found no report for this case.
Paimon version
master at ff1a004379c22c671c5d98acbec1f8e912e210dc (2.2-SNAPSHOT).
Compute Engine
PyPaimon on Windows with Python 3.10.11, PyArrow 19.0.1, the Python backend, and a local Parquet table.
Minimal reproduce step
Run this script against the checkout above. It writes three rows, filters on the top-level details_city column, and reads details.city as picked_city.
from pathlib import Path
from tempfile import TemporaryDirectory
import pyarrow as pa
from pypaimon import CatalogFactory, Schema
expression = "details_city = 'east'"
fields = pa.schema([
("id", pa.int64()),
("details_city", pa.string()),
("details", pa.struct([("city", pa.string()), ("origin", pa.string())])),
])
rows = pa.Table.from_pylist([
{"id": 1, "details_city": "east", "details": {"city": "Rome", "origin": "A"}},
{"id": 2, "details_city": "west", "details": {"city": "east", "origin": "B"}},
{"id": 3, "details_city": "east", "details": None},
], schema=fields)
options = {
"file.format": "parquet",
"bucket": "-1",
"write-only": "true",
"scan.native-plan.enabled": "false",
"read.native.enabled": "false",
"write.native.enabled": "false",
"commit.native.enabled": "false",
}
with TemporaryDirectory(prefix="named-filter-") as temp:
root = Path(temp)
catalog_config = {"warehouse": (root / "warehouse").as_uri()}
catalog = CatalogFactory.create(catalog_config)
catalog.create_database("audit", False)
catalog.create_table(
"audit.users", Schema.from_pyarrow_schema(fields, options=options), False
)
table = catalog.get_table("audit.users")
batch = table.new_batch_write_builder()
writer, commit = batch.new_write(), batch.new_commit()
try:
writer.write_arrow(rows)
commit.commit(writer.prepare_commit())
finally:
writer.close()
commit.close()
def fetch(projection=None, where=expression, project_first=False):
builder = table.new_read_builder()
if not project_first:
builder.with_filter(where)
if projection is not None:
builder.with_projection(projection)
if project_first:
builder.with_filter(where)
result = builder.new_read().to_arrow(builder.new_scan().plan().splits())
return sorted(result.to_pylist(), key=lambda row: row["id"])
assert [row["id"] for row in fetch()] == [1, 3]
print("Full Python API:", [row["id"] for row in fetch()])
assert fetch(["id"]) == [{"id": 1}, {"id": 3}]
print("Flat Python projection:", fetch(["id"]))
selected = {"id": "id", "picked_city": "details.city"}
control = fetch(selected, where="id <= 3")
assert control == [
{"id": 1, "picked_city": "Rome"},
{"id": 2, "picked_city": "east"},
{"id": 3, "picked_city": None},
], control
print("Named Python projection, unrelated filter:", control)
for name, projection, reverse in (
("List nested projection", ["id", "details.city"], False),
("Named nested projection, filter first", selected, False),
("Named nested projection, projection first", selected, True),
("Named nested projection, filter returned", dict(selected, physical_city="details_city"), False),
):
try:
result = fetch(projection, project_first=reverse)
print(name + ":", result, flush=True)
except Exception as error:
print(name + ":", type(error).__name__, str(error), flush=True)
What doesn't meet your expectations?
The named projection should return these two rows.
[{"id": 1, "picked_city": "Rome"}, {"id": 3, "picked_city": null}]
new_read() raises the same error whether I set the filter or the projection first.
ValueError: Predicate field 'details_city' with path ['details_city'] is not in the reader projection
Full reads and list projections return IDs [1, 3] with the same filter. Adding the top-level filter column to the named output also returns IDs [1, 3].
Anything else?
The reader gives details.city the internal name details_city. List projections include filter-only columns when assigning those names. Named projections skip that step, so the physical details_city filter cannot bind. Reader binding · Named projection example
Are you willing to submit a PR?
- [x] I'm willing to submit a PR!
I'd like to fix the binding for named projections and add a Parquet regression test. Could you assign this issue to me?
Hi @skyyyy955,i have opened PR #11500 to address this issue.
The fix updates TableRead._reader_adapter() so named projections retain physical filter-only columns required for predicate binding, without exposing those columns in the final output.
I've also added a Parquet regression test covering both filter-before-projection and projection-before-filter scenarios.
Validation completed:
named_projection_iterator_test.py: 36 passed, 16 skipped.projection_predicate_index_test.pyandtest_read_builder_nested_projection.py: 36 passed, 17 subtests passed.
Thanks for reporting this issue!