Skip to content

Commit

Permalink
PARQUET-2472: Close in finally block in ParquetFileWriter#end (#1350)
Browse files Browse the repository at this point in the history
It's currently possible that ParquetFileWriter#end fails when
writing out the footer, and we don't clean up resources.
This change addresses this by explicitly closing the output stream
in the finally block.
  • Loading branch information
amogh-jahagirdar authored May 17, 2024
1 parent 77fa24e commit f12229a
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1643,14 +1643,17 @@ private static void copy(SeekableInputStream from, PositionOutputStream to, long
* @throws IOException if there is an error while writing
*/
public void end(Map<String, String> extraMetaData) throws IOException {
state = state.end();
serializeColumnIndexes(columnIndexes, blocks, out, fileEncryptor);
serializeOffsetIndexes(offsetIndexes, blocks, out, fileEncryptor);
serializeBloomFilters(bloomFilters, blocks, out, fileEncryptor);
LOG.debug("{}: end", out.getPos());
this.footer = new ParquetMetadata(new FileMetaData(schema, extraMetaData, Version.FULL_VERSION), blocks);
serializeFooter(footer, out, fileEncryptor, metadataConverter);
close();
try {
state = state.end();
serializeColumnIndexes(columnIndexes, blocks, out, fileEncryptor);
serializeOffsetIndexes(offsetIndexes, blocks, out, fileEncryptor);
serializeBloomFilters(bloomFilters, blocks, out, fileEncryptor);
LOG.debug("{}: end", out.getPos());
this.footer = new ParquetMetadata(new FileMetaData(schema, extraMetaData, Version.FULL_VERSION), blocks);
serializeFooter(footer, out, fileEncryptor, metadataConverter);
} finally {
close();
}
}

@Override
Expand Down

0 comments on commit f12229a

Please sign in to comment.