Repository navigation
Closed as not planned
Labels
Description
Apache Iceberg version
main (development)
Please describe the bug 🐞
In the development version, I noticed that the to_arrow_batch_reader method casts all string types to large_string, whereas the to_arrow method returns the schema as defined in the parquet file. At first glance, it looks like a bug, likely a regression from #1669
Here is a script you can use to reproduce the issue:
import pyarrow as pa
from pyiceberg.catalog import load_catalog
from uuid import uuid4
from pyiceberg.schema import Schema
from pyiceberg.types import NestedField, StringType, DoubleType
catalog = load_catalog("default")
df = pa.Table.from_pylist(
[
{"city": "Amsterdam", "lat": 52.371807, "long": 4.896029},
{"city": "San Francisco", "lat": 37.773972, "long": -122.431297},
{"city": "Drachten", "lat": 53.11254, "long": 6.0989},
{"city": "Paris", "lat": 48.864716, "long": 2.349014},
],
)
schema = Schema(
NestedField(1, "city", StringType(), required=False),
NestedField(2, "lat", DoubleType(), required=False),
NestedField(3, "long", DoubleType(), required=False),
)
tbl = catalog.create_table(f"default.cities-{uuid4()}", schema=schema)
tbl.overwrite(df)
schema_to_arrow = tbl.scan().to_arrow().schema
schema_to_arrow_batch_reader = tbl.scan().to_arrow_batch_reader().schema
print("schema_to_arrow == schema_to_arrow_batch_reader", schema_to_arrow == schema_to_arrow_batch_reader)
print("\nschema_to_arrow")
print(schema_to_arrow)
print("\nschema_to_arrow_batch_reader")
print(schema_to_arrow_batch_reader)output:
schema_to_arrow == schema_to_arrow_batch_reader False
schema_to_arrow:
city: string
lat: double
long: double
schema_to_arrow_batch_reader:
city: large_string
-- field metadata --
PARQUET:field_id: '1'
lat: double
-- field metadata --
PARQUET:field_id: '2'
long: double
-- field metadata --
PARQUET:field_id: '3'
Notice that in to_arrow schema says city: string, while in to_arrow_batch_reader it's city: large_string
Willingness to contribute
- I can contribute a fix for this bug independently
- I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- I cannot contribute a fix for this bug at this time
Activity
Fokko commentedon Aug 4, 2025
Some context, as this is a bit of a loose-end:
to_arrow()we pull all the data in memory right away, so we know that all the types of the column.to_arrow_batch_reader()we read the files one by one, and we might hit a Parquet file that useslarge_stringrather thanstring. We cannot push it into thestringsince it would cause a buffer overflow. Therefore we're taking the safe path and we upcast it into alarge_stringupfront.Out of curiousity, what is your expected outcome here?
enkidulan commentedon Aug 6, 2025
Thanks for getting back to me.
As for the expectation, I'd expect
to_arrow_batch_readerto return the type defined in the table schema. Why would any of the parquet files in the table not be compatible with the table schema?However, there is another aspect to this. After upgrading to the upstream version,
table.scan().to_arrow()call started to fail on existing tables with the following traceback:We are doing recoding using
to_arrow_batch_readerfunction and then writing results withtable.appendback to the table. Fromtable.appendpoint of view, the type thatto_arrow_batch_readerreturns is backward compatible; however, pyarrow fails on trying to read it, as it gets two parquet files with incompatible schemas (from its point of view). To be fair, we specify both pyiceberd and pyarrow schemas explicitly, but I didn't expecttable.appendto succeed if the table schema is not compatible with other parquet files. So this is the point of conduction for me: to_arrow_batch_readerand to_arrowwere returning different types than specified in the table schema.Here is the code you can reproduce this issue with:
enkidulan commentedon Aug 6, 2025
I'm happy to provide more context on the issue or contribute to the solution, whatever it may be (if updating docs to manage users' expectations is the solution, I'm happy to create a PR)
github-actions commentedon Feb 4, 2026
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
github-actions commentedon Feb 18, 2026
This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'