-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Using Zero-Copy API to read #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b6f096e
89784cc
1deb34a
930b93b
918efa7
4a99844
a428a29
4da7130
80a7351
6b7ea00
c1a1637
fb4cc9c
bfcb7d4
bd6b60b
8a3b36f
4cd926f
8f4c9b5
b139059
8e04e79
42276c1
00b7c7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
| import parquet.Log; | ||
| import parquet.bytes.BytesUtils; | ||
|
|
@@ -31,32 +32,37 @@ public class ByteBitPackingValuesReader extends ValuesReader { | |
| private final BytePacker packer; | ||
| private final int[] decoded = new int[VALUES_AT_A_TIME]; | ||
| private int decodedPosition = VALUES_AT_A_TIME - 1; | ||
| private byte[] encoded; | ||
| private ByteBuffer encoded; | ||
| private int encodedPos; | ||
| private int nextOffset; | ||
|
|
||
| public ByteBitPackingValuesReader(int bound, Packer packer) { | ||
| this.bitWidth = BytesUtils.getWidthFromMaxInt(bound); | ||
| this.packer = packer.newBytePacker(bitWidth); | ||
| } | ||
|
|
||
| @Override | ||
| public int readInteger() { | ||
| ++ decodedPosition; | ||
| if (decodedPosition == decoded.length) { | ||
| if (encodedPos + bitWidth > encoded.length) { | ||
| packer.unpack8Values(Arrays.copyOfRange(encoded, encodedPos, encodedPos + bitWidth), 0, decoded, 0); | ||
| encoded.position(encodedPos); | ||
| if (encodedPos + bitWidth > encoded.limit()) { | ||
| // unpack8Values needs at least bitWidth bytes to read from, | ||
| // We have to fill in 0 byte at the end of encoded bytes. | ||
| byte[] tempEncode = new byte[bitWidth]; | ||
| encoded.get(tempEncode, 0, encoded.limit() - encodedPos); | ||
| packer.unpack8Values(ByteBuffer.wrap(tempEncode), 0, decoded, 0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a comment in the code explaining the special case as the BB api makes the intent less clear. |
||
| } else { | ||
| packer.unpack8Values(encoded, encodedPos, decoded, 0); | ||
| } | ||
| } | ||
| encodedPos += bitWidth; | ||
| decodedPosition = 0; | ||
| } | ||
| return decoded[decodedPosition]; | ||
| } | ||
|
|
||
| @Override | ||
| public void initFromPage(int valueCount, byte[] page, int offset) | ||
| public void initFromPage(int valueCount, ByteBuffer page, int offset) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once this is all working we should provide an api compatibility layer in case other libraries are using those. |
||
| throws IOException { | ||
| int effectiveBitLength = valueCount * bitWidth; | ||
| int length = BytesUtils.paddedByteCountFromBits(effectiveBitLength); // ceil | ||
|
|
@@ -67,6 +73,11 @@ public void initFromPage(int valueCount, byte[] page, int offset) | |
| this.nextOffset = offset + length; | ||
| } | ||
|
|
||
| @Override | ||
| public void initFromPage(int valueCount, byte[] page, int offset) throws IOException{ | ||
| this.initFromPage(valueCount, ByteBuffer.wrap(page), offset); | ||
| } | ||
|
|
||
| @Override | ||
| public int getNextOffset() { | ||
| return nextOffset; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating a tmp byte array, can we call slice and use position and limit to create a sub view of the ByteBuffer directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temp byte array is used to fill 0 at the end of bytebuffer. I don't think using the previous byte memory could do it.