dongjoon-hyun commented on a change in pull request #996:
URL: https://github.com/apache/orc/pull/996#discussion_r780503748



##########
File path: java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java
##########
@@ -182,10 +182,13 @@ public static long estimateRgEndOffset(boolean 
isCompressed,
                                          long streamLength) {
     // figure out the worst case last location
     // if adjacent groups have the same compressed block offset then stretch 
the slop
-    // by factor of 2 to safely accommodate the next compression block.
-    // One for the current compression block and another for the next 
compression block.
+    // by a factor to safely accommodate the next compression block.
+    // 512 is the MAX_SCOPE defined in RunLengthIntegerWriterV2.
+    // 8 is the maximum size of bytes for each value (see 
RunLengthIntegerWriterV2.zzBits100p).
+    // We need to calculate the maximum number of blocks by bufferSize 
accordingly.
+    int stretchFactor = bufferSize > 0 ? 2 + (512 * 8 - 1) / bufferSize : 2;
     long slop = isCompressed
-                    ? 2 * (OutStream.HEADER_SIZE + bufferSize)
+                    ? stretchFactor * (OutStream.HEADER_SIZE + bufferSize)
                     : WORST_UNCOMPRESSED_SLOP;
     return isLast ? streamLength : Math.min(streamLength, nextGroupOffset + 
slop);

Review comment:
       According to the change on the old test case, is there a chance of 
performance regression by causing more data traffics when we read ORC files on 
S3?
   ```scala
   - final int SLOP = 2 * (OutStream.HEADER_SIZE + options.getBufferSize());
   + final int SLOP = 5 * (OutStream.HEADER_SIZE + options.getBufferSize());
   ...
   assertEquals(START + 1000, result.get(1).getOffset());
   assertEquals(20000 + SLOP, result.get(1).getLength());
   assertEquals(START + 41000, result.get(2).getOffset());
   assertEquals(10000 + SLOP, result.get(2).getLength());
   ```




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to