hsnusonic commented on a change in pull request #996:
URL: https://github.com/apache/orc/pull/996#discussion_r781699986



##########
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;

Review comment:
       We are actually doing a round-up operation for `(512 * 8) / bufferSize`. 
We can interpret the formula as `1 (for uncompressed bytes in buffer) + 
Math.ceil(512 * 8 / (float) bufferSize)`. The second part can be expanded to `1 
+ (512 * 8 - 1) / bufferSize`. I just thought that we can avoid floating point 
calculation here.




-- 
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