You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@orc.apache.org by "dongjoon-hyun (via GitHub)" <gi...@apache.org> on 2023/03/09 20:46:31 UTC

[GitHub] [orc] dongjoon-hyun commented on a diff in pull request #1432: ORC-1393: Add `reset(DiskRangeList input, long length)` to `InStream` impl class

dongjoon-hyun commented on code in PR #1432:
URL: https://github.com/apache/orc/pull/1432#discussion_r1131575180


##########
java/core/src/test/org/apache/orc/impl/TestInStream.java:
##########
@@ -957,4 +957,47 @@ public void testMultiRangeCompressHeader() throws IOException {
       assertEquals((byte)i, inBuffer[i], "position " + i);
     }
   }
+
+  private static final byte[] uncompressed = input(
+          0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+  
+  @Test
+  public void testStreamResetWithIncreasedLength() throws IOException {
+    // Set up an initial buffer of PREVIOUS_LENGTH followed by our stream
+    // at START.
+    final long START = 1_000;
+    final int PREVIOUS_LENGTH = 30;
+    BufferChunkList list = new BufferChunkList();
+    byte[] previous = new byte[PREVIOUS_LENGTH];
+    Arrays.fill(previous, (byte) -1);
+    list.add(new BufferChunk(ByteBuffer.wrap(previous), START - PREVIOUS_LENGTH));
+    list.add(new BufferChunk(ByteBuffer.wrap(uncompressed), START));
+    // Creating a stream of 10 bytes, but with a length of 5
+    InStream inStream = InStream.create("test", list.get(), START, 5, new InStream.StreamOptions());
+    // Resetting the stream with the increased length
+    inStream.reset(list.get(), 10);
+    // Reading the stream and expecting to read 10 bytes
+    byte[] inBuffer = new byte[10];
+    assertEquals(10, inStream.read(inBuffer));
+  }
+
+  @Test
+  public void testStreamResetWithoutIncreasedLength() throws IOException {
+    // Set up an initial buffer of PREVIOUS_LENGTH followed by our stream
+    // at START.
+    final long START = 1_000;
+    final int PREVIOUS_LENGTH = 30;
+    BufferChunkList list = new BufferChunkList();
+    byte[] previous = new byte[PREVIOUS_LENGTH];
+    Arrays.fill(previous, (byte) -1);
+    list.add(new BufferChunk(ByteBuffer.wrap(previous), START - PREVIOUS_LENGTH));
+    list.add(new BufferChunk(ByteBuffer.wrap(uncompressed), START));
+    // Creating a stream of 10 bytes, but with a shorter length of 5
+    InStream inStream = InStream.create("test", list.get(), START, 5, new InStream.StreamOptions());
+    // Resetting the stream without updating its length
+    inStream.reset(list.get());

Review Comment:
   So, Hive also has this use case?



##########
java/core/src/test/org/apache/orc/impl/TestInStream.java:
##########
@@ -957,4 +957,47 @@ public void testMultiRangeCompressHeader() throws IOException {
       assertEquals((byte)i, inBuffer[i], "position " + i);
     }
   }
+
+  private static final byte[] uncompressed = input(
+          0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+  
+  @Test
+  public void testStreamResetWithIncreasedLength() throws IOException {
+    // Set up an initial buffer of PREVIOUS_LENGTH followed by our stream
+    // at START.
+    final long START = 1_000;
+    final int PREVIOUS_LENGTH = 30;
+    BufferChunkList list = new BufferChunkList();
+    byte[] previous = new byte[PREVIOUS_LENGTH];
+    Arrays.fill(previous, (byte) -1);
+    list.add(new BufferChunk(ByteBuffer.wrap(previous), START - PREVIOUS_LENGTH));
+    list.add(new BufferChunk(ByteBuffer.wrap(uncompressed), START));
+    // Creating a stream of 10 bytes, but with a length of 5
+    InStream inStream = InStream.create("test", list.get(), START, 5, new InStream.StreamOptions());
+    // Resetting the stream with the increased length
+    inStream.reset(list.get(), 10);
+    // Reading the stream and expecting to read 10 bytes
+    byte[] inBuffer = new byte[10];
+    assertEquals(10, inStream.read(inBuffer));
+  }
+
+  @Test
+  public void testStreamResetWithoutIncreasedLength() throws IOException {
+    // Set up an initial buffer of PREVIOUS_LENGTH followed by our stream
+    // at START.
+    final long START = 1_000;
+    final int PREVIOUS_LENGTH = 30;
+    BufferChunkList list = new BufferChunkList();
+    byte[] previous = new byte[PREVIOUS_LENGTH];
+    Arrays.fill(previous, (byte) -1);
+    list.add(new BufferChunk(ByteBuffer.wrap(previous), START - PREVIOUS_LENGTH));
+    list.add(new BufferChunk(ByteBuffer.wrap(uncompressed), START));
+    // Creating a stream of 10 bytes, but with a shorter length of 5
+    InStream inStream = InStream.create("test", list.get(), START, 5, new InStream.StreamOptions());
+    // Resetting the stream without updating its length
+    inStream.reset(list.get());

Review Comment:
   So, Hive also has this use case still, right?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org