You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scan with an empty projection (selected_fields=()) returns 0 rows #4137
table.scan(selected_fields=()).to_arrow() returns an empty table instead of a table with the scan's row count and no columns. to_arrow_batch_reader() does the same, with or without a row_filter. A zero-column result is how callers ask for a row count without reading data: Ray's Dataset.count() pushes an empty projection into read_iceberg and got 0 (ray-project/ray#63913), which Ray worked around in ray-project/ray#65175 by reading one column and dropping it.
Two places drop the row count, both in pyiceberg/io/pyarrow.py:
_to_requested_schema builds each batch with pa.RecordBatch.from_struct_array(...). A struct array with no children has length 0, so every batch comes back with 0 rows.
ArrowScan.to_table combines batches with pa.concat_tables, which also returns 0 rows for tables without columns (pyarrow 25.0.1), so fixing the first place alone is not enough for to_arrow().
I have a fix: return batch.select([]) from _to_requested_schema when the requested schema is empty, and build the result with pa.Table.from_batches in to_table for an empty projection. Tests cover to_arrow(), the batch reader, a row filter, and a table with deleted rows. I can open a PR.
Activity