|
19 | 19 | package org.apache.parquet.column.values.rle; |
20 | 20 |
|
21 | 21 | import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertArrayEquals; |
22 | 23 |
|
23 | 24 | import java.io.ByteArrayInputStream; |
24 | 25 | import java.util.ArrayList; |
| 26 | +import java.util.Arrays; |
25 | 27 | import java.util.List; |
26 | 28 | import org.apache.parquet.bytes.BytesUtils; |
27 | 29 | import org.apache.parquet.bytes.DirectByteBufferAllocator; |
@@ -298,6 +300,49 @@ public void testGroupBoundary() throws Exception { |
298 | 300 | assertEquals(stream.available(), 0); |
299 | 301 | } |
300 | 302 |
|
| 303 | + @Test |
| 304 | + public void testTruncatedPackedRunAfterFullPackedRunDoesNotReuseStaleBytes() throws Exception { |
| 305 | + int bitWidth = 3; |
| 306 | + BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth); |
| 307 | + |
| 308 | + int[] firstRunValues = new int[8]; |
| 309 | + Arrays.fill(firstRunValues, 7); |
| 310 | + byte[] firstRunPacked = new byte[bitWidth]; |
| 311 | + packer.pack8Values(firstRunValues, 0, firstRunPacked, 0); |
| 312 | + |
| 313 | + int[] secondRunValues = {1, 2, 3, 4, 5, 6, 7, 0}; |
| 314 | + byte[] secondRunPacked = new byte[bitWidth]; |
| 315 | + packer.pack8Values(secondRunValues, 0, secondRunPacked, 0); |
| 316 | + |
| 317 | + byte[] encoded = { |
| 318 | + (byte) ((1 << 1) | 1), |
| 319 | + firstRunPacked[0], |
| 320 | + firstRunPacked[1], |
| 321 | + firstRunPacked[2], |
| 322 | + (byte) ((1 << 1) | 1), |
| 323 | + secondRunPacked[0] |
| 324 | + }; |
| 325 | + |
| 326 | + RunLengthBitPackingHybridDecoder decoder = |
| 327 | + new RunLengthBitPackingHybridDecoder(bitWidth, new ByteArrayInputStream(encoded)); |
| 328 | + |
| 329 | + for (int ignored = 0; ignored < 8; ignored++) { |
| 330 | + assertEquals(7, decoder.readInt()); |
| 331 | + } |
| 332 | + |
| 333 | + int[] actualSecondRun = new int[8]; |
| 334 | + for (int i = 0; i < 8; i++) { |
| 335 | + actualSecondRun[i] = decoder.readInt(); |
| 336 | + } |
| 337 | + |
| 338 | + byte[] expectedSecondPacked = new byte[bitWidth]; |
| 339 | + expectedSecondPacked[0] = secondRunPacked[0]; |
| 340 | + int[] expectedSecondRun = new int[8]; |
| 341 | + packer.unpack8Values(expectedSecondPacked, 0, expectedSecondRun, 0); |
| 342 | + |
| 343 | + assertArrayEquals(expectedSecondRun, actualSecondRun); |
| 344 | + } |
| 345 | + |
301 | 346 | private static List<Integer> unpack(int bitWidth, int numValues, ByteArrayInputStream is) throws Exception { |
302 | 347 |
|
303 | 348 | BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth); |
|
0 commit comments