apache / apache/iceberg-python
Possible memory leak with to_arrow_batch_reader()
- 主要语言
- Python
- 星标
- 1.1k
- 派生
- 581
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 78
描述
### Apache Iceberg version
0.9.1 (latest release)
### Please describe the bug 🐞
## Summary
It seems that there is memory leak when running to_arrow_batch_reader(), it takes ~30GB memory to read an iceberg table with single 40MB parquet files
Example code:
```python
import boto3
from pyiceberg.table import StaticTable, Table
def iceberg_table_from_metadata_path(metadata_path: str) -> StaticTable:
session = boto3.Session(region_name="")
credentials = session.get_credentials()
credentials = credentials.get_frozen_credentials()
table = StaticTable.from_metadata(
metadata_path,
{
"client.secret-access-key": credentials.secret_key,
"client.access-key-id": credentials.access_key,
"client.session-token": credentials.token,
"client.region": "",
},
)
return table
def main():
metadata_path = ".metadata.json"
iceberg_table = iceberg_table_from_metadata_path(metadata_path)
scan_kwargs = {"row_filter": f"PARTITION='train'"}
batch_reader = iceberg_table.scan(**scan_kwargs).to_arrow_batch_reader()
for batch in batch_reader:
print(f"Inside batch reader")
plan_files = iceberg_table.scan(**scan_kwargs).plan_files()
for file in plan_files:
print(file.file.file_path)
print("Hello from pyiceberg-test!")
if __name__ == "__main__":
main()
```
Running using memray
```
uv run memray run main.py
```
Charts
Dependencies
```
"boto3>=1.40.21",
"memray>=1.18.0",
"pyarrow>=21.0.0",
"pyiceberg==0.10.0rc1",
"s3fs>=0.4.2"
```
### Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [x] 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
贡献指南
这个仓库没有索引到贡献指南
调研方向
首先使用 memray run main.py 重现 main.py 中的示例,重点关注 to_arrow_batch_reader() 入口点,并比较批次迭代期间的内存使用情况与后续 plan_files() 调用期间的内存使用情况。跟踪 scan 和 Arrow reader 路径,以确定内存是否仍被保留;完成标准是示例在没有无限增长的情况下读取表,并且该行为由适当的回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-engineering, databases
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100