Skip to content

Commit

Permalink
GH-2935: Avoid double close of ParquetFileWriter (#2951)
Browse files Browse the repository at this point in the history
* GH-2935: Avoid double close of ParquetFileWriter

* fix comment

---------

Co-authored-by: youming.whl <[email protected]>
  • Loading branch information
hellishfire and youming.whl authored Jul 22, 2024
1 parent 20651b8 commit 824b7d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public static enum Mode {

// set when end is called
private ParquetMetadata footer = null;
private boolean closed;

private final CRC32 crc;
private final ReusingByteBufferAllocator crcAllocator;
Expand Down Expand Up @@ -1658,11 +1659,16 @@ public void end(Map<String, String> extraMetaData) throws IOException {

@Override
public void close() throws IOException {
if (closed) {
return;
}
try (PositionOutputStream temp = out) {
temp.flush();
if (crcAllocator != null) {
crcAllocator.close();
}
} finally {
closed = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ public void testWriteRead() throws Exception {
w.endColumn();
w.endBlock();
w.end(new HashMap<String, String>());
// Although writer is already closed in previous end(),
// explicitly close it again to verify double close behavior.
w.close();

ParquetMetadata readFooter = ParquetFileReader.readFooter(configuration, path);
assertEquals("footer: " + readFooter, 2, readFooter.getBlocks().size());
Expand Down

0 comments on commit 824b7d0

Please sign in to comment.