Skip to content

Commit

Permalink
Account for page header in ORC output buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Islam Ismailov authored and highker committed Feb 4, 2020
1 parent 8ac000d commit 10893a6
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class OrcOutputBuffer
extends SliceOutput
{
private static final int INSTANCE_SIZE = ClassLayout.parseClass(OrcOutputBuffer.class).instanceSize();
private static final int PAGE_HEADER_SIZE = 3; // ORC spec 3 byte header
private static final int INITIAL_BUFFER_SIZE = 256;
private static final int DIRECT_FLUSH_SIZE = 32 * 1024;
private static final int MINIMUM_OUTPUT_BUFFER_CHUNK_SIZE = 4 * 1024;
Expand Down Expand Up @@ -77,9 +78,9 @@ public class OrcOutputBuffer
public OrcOutputBuffer(CompressionKind compression, int maxBufferSize)
{
requireNonNull(compression, "compression is null");
checkArgument(maxBufferSize > 0, "maximum buffer size should be greater than 0");
checkArgument(maxBufferSize > PAGE_HEADER_SIZE, "maximum buffer size should be greater than page header size");

this.maxBufferSize = maxBufferSize;
this.maxBufferSize = compression == CompressionKind.NONE ? maxBufferSize : maxBufferSize - PAGE_HEADER_SIZE;

this.buffer = new byte[INITIAL_BUFFER_SIZE];
this.slice = wrappedBuffer(buffer);
Expand Down Expand Up @@ -386,6 +387,8 @@ public String toString()

private void ensureWritableBytes(int minWritableBytes)
{
checkArgument(minWritableBytes <= maxBufferSize, "Min writable bytes must not exceed max buffer size");

int neededBufferSize = bufferPosition + minWritableBytes;
if (neededBufferSize <= slice.length()) {
return;
Expand Down

0 comments on commit 10893a6

Please sign in to comment.