orc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject orc git commit: ORC-83. Protect users from Reader.rows(Options) modifying the Options object.
Date Tue, 12 Jul 2016 22:29:18 GMT
Repository: orc
Updated Branches:
  refs/heads/master e476f6a55 -> 714b6cc34


ORC-83. Protect users from Reader.rows(Options) modifying the Options
object.

Fixes #48

Signed-off-by: Owen O'Malley <omalley@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/orc/repo
Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/714b6cc3
Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/714b6cc3
Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/714b6cc3

Branch: refs/heads/master
Commit: 714b6cc340c5aa0c45be7b31baaec74cb879e237
Parents: e476f6a
Author: Owen O'Malley <omalley@apache.org>
Authored: Tue Jul 12 14:43:45 2016 -0700
Committer: Owen O'Malley <omalley@apache.org>
Committed: Tue Jul 12 15:28:55 2016 -0700

----------------------------------------------------------------------
 .../src/java/org/apache/orc/impl/ReaderImpl.java |  1 +
 .../test/org/apache/orc/impl/TestReaderImpl.java | 19 +++++++++++++++++++
 .../apache/orc/impl/TestRecordReaderImpl.java    | 10 +++++++---
 3 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/orc/blob/714b6cc3/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
----------------------------------------------------------------------
diff --git a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
index a18f922..34f743b 100644
--- a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
@@ -580,6 +580,7 @@ public class ReaderImpl implements Reader {
     boolean[] include = options.getInclude();
     // if included columns is null, then include all columns
     if (include == null) {
+      options = options.clone();
       include = new boolean[types.size()];
       Arrays.fill(include, true);
       options.include(include);

http://git-wip-us.apache.org/repos/asf/orc/blob/714b6cc3/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java
----------------------------------------------------------------------
diff --git a/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java b/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java
index 23d0dab..4dd8d3e 100644
--- a/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java
+++ b/java/core/src/test/org/apache/orc/impl/TestReaderImpl.java
@@ -20,6 +20,8 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
+
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FSDataInputStream;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.PositionedReadable;
@@ -27,11 +29,16 @@ import org.apache.hadoop.fs.Seekable;
 import org.apache.orc.FileFormatException;
 import org.apache.hadoop.io.Text;
 import org.apache.orc.OrcFile;
+import org.apache.orc.Reader;
+import org.apache.orc.RecordReader;
+import org.apache.orc.tools.TestJsonFileDump;
 import org.junit.Test;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.rules.ExpectedException;
 
+import static org.junit.Assert.assertEquals;
+
 public class TestReaderImpl {
 
   @Rule
@@ -73,6 +80,18 @@ public class TestReaderImpl {
     ReaderImpl.ensureOrcFooter(in, path, psLen, buffer);
   }
 
+  @Test
+  public void testOptionSafety() throws IOException {
+    Reader.Options options = new Reader.Options();
+    String expected = options.toString();
+    Configuration conf = new Configuration();
+    Path path = new Path(TestJsonFileDump.getFileFromClasspath
+        ("orc-file-11-format.orc"));
+    Reader reader = OrcFile.createReader(path, OrcFile.readerOptions(conf));
+    RecordReader rows = reader.rows(options);
+    assertEquals(expected, options.toString());
+  }
+
   private void prepareTestCase(byte[] bytes) {
     buffer = ByteBuffer.wrap(bytes);
     psLen = buffer.get(bytes.length - 1) & 0xff;

http://git-wip-us.apache.org/repos/asf/orc/blob/714b6cc3/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
----------------------------------------------------------------------
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 cdd62ac..01a5200 100644
--- a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
+++ b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
@@ -1651,15 +1651,19 @@ public class TestRecordReaderImpl {
   @Test
   public void testClose() throws Exception {
     DataReader mockedDataReader = mock(DataReader.class);
+    DataReader cloned = mock(DataReader.class);
+    when(mockedDataReader.clone()).thenReturn(cloned);
     closeMockedRecordReader(mockedDataReader);
 
-    verify(mockedDataReader, atLeastOnce()).close();
+    verify(cloned, atLeastOnce()).close();
   }
 
   @Test
   public void testCloseWithException() throws Exception {
     DataReader mockedDataReader = mock(DataReader.class);
-    doThrow(IOException.class).when(mockedDataReader).close();
+    DataReader cloned = mock(DataReader.class);
+    when(mockedDataReader.clone()).thenReturn(cloned);
+    doThrow(IOException.class).when(cloned).close();
 
     try {
       closeMockedRecordReader(mockedDataReader);
@@ -1668,7 +1672,7 @@ public class TestRecordReaderImpl {
 
     }
 
-    verify(mockedDataReader, atLeastOnce()).close();
+    verify(cloned, atLeastOnce()).close();
   }
 
   Path workDir = new Path(System.getProperty("test.tmp.dir",


Mime
View raw message