Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-978: Fix NPE in TestFlinkOrcReaderWriter #891

Merged
merged 2 commits into from Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions java/core/src/java/org/apache/orc/impl/WriterImpl.java
Expand Up @@ -140,6 +140,7 @@ public class WriterImpl implements WriterInternal, MemoryManager.Callback {
// information
private boolean needKeyFlush;
private final boolean useProlepticGregorian;
private boolean isClose = false;

public WriterImpl(FileSystem fs,
Path path,
Expand Down Expand Up @@ -725,15 +726,21 @@ public void addRowBatch(VectorizedRowBatch batch) throws IOException {

@Override
public void close() throws IOException {
if (callback != null) {
callback.preFooterWrite(callbackContext);
if (!isClose) {
try {
if (callback != null) {
callback.preFooterWrite(callbackContext);
}
// remove us from the memory manager so that we don't get any callbacks
memoryManager.removeWriter(path);
// actually close the file
flushStripe();
lastFlushOffset = writeFooter();
physicalWriter.close();
} finally {
isClose = true;
}
}
// remove us from the memory manager so that we don't get any callbacks
memoryManager.removeWriter(path);
// actually close the file
flushStripe();
lastFlushOffset = writeFooter();
physicalWriter.close();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions java/core/src/test/org/apache/orc/impl/TestWriterImpl.java
Expand Up @@ -118,4 +118,12 @@ public void testStripes() throws Exception {
Reader r = OrcFile.createReader(testFilePath, OrcFile.readerOptions(conf));
assertEquals(r.getStripes(), w.getStripes());
}

@Test
public void testCloseIsIdempotent() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding a test case for this.

conf.set(OrcConf.OVERWRITE_OUTPUT_FILE.getAttribute(), "true");
Writer w = OrcFile.createWriter(testFilePath, OrcFile.writerOptions(conf).setSchema(schema));
w.close();
w.close();
}
}