This is an automated email from the ASF dual-hosted git repository.

omalley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/master by this push:
     new 150415f  ORC-416: Avoid opening data reader when there is no stripe
150415f is described below

commit 150415fabcf47a5221cdadc53f429bd7c6c27fe8
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Wed Oct 10 02:36:07 2018 -0700

    ORC-416: Avoid opening data reader when there is no stripe
    
    Fixes #320
    
    Signed-off-by: Owen O'Malley <[email protected]>
---
 .../java/org/apache/orc/impl/RecordReaderImpl.java |  1 -
 .../org/apache/orc/impl/TestRecordReaderImpl.java  | 23 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java 
b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
index a8e0be1..731b46e 100644
--- a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
@@ -249,7 +249,6 @@ public class RecordReaderImpl implements RecordReader {
               .withZeroCopy(zeroCopy)
               .build());
     }
-    this.dataReader.open();
     firstRow = skippedRows;
     totalRowCount = rows;
     Boolean skipCorrupt = options.getSkipCorruptRecords();
diff --git a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java 
b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
index 1cf01de..66951ff 100644
--- a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
+++ b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -2096,4 +2097,26 @@ public class TestRecordReaderImpl {
     assertEquals(1, applier.getExceptionCount()[0]);
     assertEquals(0, applier.getExceptionCount()[1]);
   }
+
+  @Test
+  public void testSkipDataReaderOpen() throws Exception {
+    IOException ioe = new IOException("Don't open when there is no stripe");
+
+    DataReader mockedDataReader = mock(DataReader.class);
+    doThrow(ioe).when(mockedDataReader).open();
+    when(mockedDataReader.clone()).thenReturn(mockedDataReader);
+    doNothing().when(mockedDataReader).close();
+
+    Configuration conf = new Configuration();
+    Path path = new Path(workDir, "empty.orc");
+    FileSystem.get(conf).delete(path, true);
+    OrcFile.WriterOptions options = 
OrcFile.writerOptions(conf).setSchema(TypeDescription.createLong());
+    Writer writer = OrcFile.createWriter(path, options);
+    writer.close();
+
+    Reader reader = OrcFile.createReader(path, OrcFile.readerOptions(conf));
+    Reader.Options readerOptions = 
reader.options().dataReader(mockedDataReader);
+    RecordReader recordReader = reader.rows(readerOptions);
+    recordReader.close();
+  }
 }

Reply via email to