|
19 | 19 | package org.apache.parquet.hadoop;
|
20 | 20 |
|
21 | 21 | import java.io.IOException;
|
| 22 | +import java.nio.ByteBuffer; |
22 | 23 | import java.util.ArrayDeque;
|
23 | 24 | import java.util.HashMap;
|
24 | 25 | import java.util.Iterator;
|
@@ -166,10 +167,33 @@ public DataPage readPage() {
|
166 | 167 | public DataPage visit(DataPageV1 dataPageV1) {
|
167 | 168 | try {
|
168 | 169 | BytesInput bytes = dataPageV1.getBytes();
|
| 170 | + ByteBuffer byteBuffer = bytes.toByteBuffer(); |
| 171 | + long compressedSize = bytes.size(); |
| 172 | + |
169 | 173 | if (null != blockDecryptor) {
|
170 |
| - bytes = BytesInput.from(blockDecryptor.decrypt(bytes.toByteArray(), dataPageAAD)); |
| 174 | + byte[] decrypted = blockDecryptor.decrypt(bytes.toByteArray(), dataPageAAD); |
| 175 | + compressedSize = decrypted.length; |
| 176 | + byteBuffer = ByteBuffer.allocateDirect((int) compressedSize); |
| 177 | + byteBuffer.put(decrypted); |
| 178 | + byteBuffer.flip(); |
| 179 | + } |
| 180 | + |
| 181 | + if (!byteBuffer.isDirect()) { |
| 182 | + ByteBuffer directByteBuffer = ByteBuffer.allocateDirect((int) compressedSize);; |
| 183 | + directByteBuffer.put(byteBuffer); |
| 184 | + directByteBuffer.flip(); |
| 185 | + byteBuffer = directByteBuffer; |
| 186 | + } |
| 187 | + |
| 188 | + // The input/output bytebuffers must be direct for (bytebuffer-based, native) decompressor |
| 189 | + ByteBuffer decompressedBuffer = ByteBuffer.allocateDirect(dataPageV1.getUncompressedSize()); |
| 190 | + decompressor.decompress(byteBuffer, (int) compressedSize, decompressedBuffer, dataPageV1.getUncompressedSize()); |
| 191 | + |
| 192 | + // HACKY: sometimes we need to do `flip` because the position of output bytebuffer is not reset. |
| 193 | + if (decompressedBuffer.position() != 0) { |
| 194 | + decompressedBuffer.flip(); |
171 | 195 | }
|
172 |
| - BytesInput decompressed = decompressor.decompress(bytes, dataPageV1.getUncompressedSize()); |
| 196 | + BytesInput decompressed = BytesInput.from(decompressedBuffer); |
173 | 197 |
|
174 | 198 | final DataPageV1 decompressedPage;
|
175 | 199 | if (offsetIndex == null) {
|
|
0 commit comments