apache / apache/parquet-java

Out of Memory when reading large parquet file

未关闭
#2,201 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Component: Parquet Priority: Major Type: bug
主要语言
Java
星标
3.1k
派生
1.6k
平均合并
3 天 12 小时
30 天内合并 PR
33

描述

Hi,

We are successfully reading parquet files block by block, and are running into a JVM out of memory issue in a certain edge case. Consider the following scenario:

Parquet file has one column and one block and is 10 GB

Our JVM is 5 GB

Is there any way to read such a file? Below is our implementation/stack trace
```java

Caused by: java.lang.OutOfMemoryError: Java heap space
at org.apache.parquet.hadoop.ParquetFileReader$ConsecutiveChunkList.readAll(ParquetFileReader.java:778)
at org.apache.parquet.hadoop.ParquetFileReader.readNextRowGroup(ParquetFileReader.java:511)

try {
ParquetMetadata readFooter = ParquetFileReader.readFooter(hfsConfig, path,
ParquetMetadataConverter.NO_FILTER);
MessageType schema = readFooter.getFileMetaData().getSchema();
long a = readFooter.getBlocks().stream().
reduce(0L, (left, right) -> left >
right.getTotalByteSize() ? left : right.getTotalByteSize(),
(leftl, rightl) -> leftl > rightl ? leftl : rightl);

for (BlockMetaData block : readFooter.getBlocks()) {
try {
fileReader = new ParquetFileReader(hfsConfig,
readFooter.getFileMetaData(), path, Collections
.singletonList(block), schema.getColumns());
PageReadStore pages;

while (null != (pages = fileReader.readNextRowGroup())) {
//exception gets thrown here on blocks larger than jvm memory
final long rows = pages.getRowCount();
final MessageColumnIO columnIO = new
ColumnIOFactory().getColumnIO(schema);
final RecordReader recordReader =
columnIO.getRecordReader(pages, new GroupRecordConverter(schema));

for (int i = 0; i < rows; i++) {
final Group group = recordReader.read();
int fieldCount = group.getType().getFieldCount();

for (int field = 0; field < fieldCount; field++) {
int valueCount = group.getFieldRepetitionCount(field);
Type fieldType = group.getType().getType(field);
String fieldName = fieldType.getName();

for (int index = 0; index < valueCount; index++) {
// Process data
}
}
}
}
} catch (IOException e) {
...
} finally {
...
}
}
```

**Reporter**: [Ryan Sachs](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=sachsry)

**Note**: *This issue was originally created as [PARQUET-1359](https://issues.apache.org/jira/browse/PARQUET-1359). Please see the [migration documentation](https://issues.apache.org/jira/browse/PARQUET-2502) for further details.*

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先,在 5 GB JVM 中复现读取单列、10 GB Parquet 的情况,并沿着 ParquetFileReader.readNextRowGroup 跟踪到 ConsecutiveChunkList.readAll,即 stack trace 中显示的位置。确定 reader 是否应当处理大于堆的 row group,并将完成定义为一种有文档记录或经过测试的行为,可以避免所报告的内存不足故障。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
data-engineering
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。