kevinjqliu commented on code in PR #590: URL: https://github.com/apache/iceberg-python/pull/590#discussion_r1564830649
########## pyiceberg/io/pyarrow.py: ########## @@ -1769,27 +1769,33 @@ def data_file_statistics_from_parquet_metadata( def write_file(io: FileIO, table_metadata: TableMetadata, tasks: Iterator[WriteTask]) -> Iterator[DataFile]: - schema = table_metadata.schema() - arrow_file_schema = schema.as_arrow() parquet_writer_kwargs = _get_parquet_writer_kwargs(table_metadata.properties) - row_group_size = PropertyUtil.property_as_int( properties=table_metadata.properties, property_name=TableProperties.PARQUET_ROW_GROUP_SIZE_BYTES, default=TableProperties.PARQUET_ROW_GROUP_SIZE_BYTES_DEFAULT, ) def write_parquet(task: WriteTask) -> DataFile: + table_schema = task.schema + arrow_table = pa.Table.from_batches(task.record_batches) + # if schema needs to be transformed, use the transformed schema and adjust the arrow table accordingly + # otherwise use the original schema + if (sanitized_schema := sanitize_column_names(table_schema)) != table_schema: + file_schema = sanitized_schema + arrow_table = to_requested_schema(requested_schema=file_schema, file_schema=table_schema, table=arrow_table) + else: + file_schema = table_schema Review Comment: another option could be to push this logic up to the caller of `write_file` or maybe even in `WriteTask` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org