skyyyy955 opened a new issue, #11369:
URL: https://github.com/apache/paimon/issues/11369

   ### 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`.
   
   ```python
   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.
   
   ```json
   [{"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.
   
   ```text
   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](https://github.com/apache/paimon/blob/ff1a004379c22c671c5d98acbec1f8e912e210dc/paimon-python/pypaimon/read/table_read.py#L231-L288)
 ยท [Named projection 
example](https://paimon.apache.org/docs/master/pypaimon/pytorch/#named-nested-projections)
   
   ### 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?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to