|
19 | 19 | import com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int32ValuesDecoder;
|
20 | 20 | import com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int64TimeAndTimestampMicrosValuesDecoder;
|
21 | 21 | import com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.Int64ValuesDecoder;
|
| 22 | +import com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.ShortDecimalValuesDecoder; |
22 | 23 | import com.facebook.presto.parquet.batchreader.decoders.ValuesDecoder.TimestampValuesDecoder;
|
23 | 24 | import com.facebook.presto.parquet.batchreader.decoders.plain.BinaryPlainValuesDecoder;
|
24 | 25 | import com.facebook.presto.parquet.batchreader.decoders.plain.BooleanPlainValuesDecoder;
|
25 | 26 | import com.facebook.presto.parquet.batchreader.decoders.plain.Int32PlainValuesDecoder;
|
| 27 | +import com.facebook.presto.parquet.batchreader.decoders.plain.Int32ShortDecimalPlainValuesDecoder; |
26 | 28 | import com.facebook.presto.parquet.batchreader.decoders.plain.Int64PlainValuesDecoder;
|
| 29 | +import com.facebook.presto.parquet.batchreader.decoders.plain.Int64ShortDecimalPlainValuesDecoder; |
27 | 30 | import com.facebook.presto.parquet.batchreader.decoders.plain.Int64TimeAndTimestampMicrosPlainValuesDecoder;
|
28 | 31 | import com.facebook.presto.parquet.batchreader.decoders.plain.TimestampPlainValuesDecoder;
|
29 | 32 | import com.facebook.presto.parquet.batchreader.decoders.rle.BinaryRLEDictionaryValuesDecoder;
|
30 | 33 | import com.facebook.presto.parquet.batchreader.decoders.rle.BooleanRLEValuesDecoder;
|
31 | 34 | import com.facebook.presto.parquet.batchreader.decoders.rle.Int32RLEDictionaryValuesDecoder;
|
| 35 | +import com.facebook.presto.parquet.batchreader.decoders.rle.Int32ShortDecimalRLEDictionaryValuesDecoder; |
32 | 36 | import com.facebook.presto.parquet.batchreader.decoders.rle.Int64RLEDictionaryValuesDecoder;
|
33 | 37 | import com.facebook.presto.parquet.batchreader.decoders.rle.Int64TimeAndTimestampMicrosRLEDictionaryValuesDecoder;
|
34 | 38 | import com.facebook.presto.parquet.batchreader.decoders.rle.TimestampRLEDictionaryValuesDecoder;
|
@@ -118,6 +122,26 @@ private static BooleanValuesDecoder booleanRLE(byte[] pageBytes)
|
118 | 122 | return new BooleanRLEValuesDecoder(ByteBuffer.wrap(pageBytes));
|
119 | 123 | }
|
120 | 124 |
|
| 125 | + private static ShortDecimalValuesDecoder int32ShortDecimalPlain(byte[] pageBytes) |
| 126 | + { |
| 127 | + return new Int32ShortDecimalPlainValuesDecoder(pageBytes, 0, pageBytes.length); |
| 128 | + } |
| 129 | + |
| 130 | + private static ShortDecimalValuesDecoder int64ShortDecimalPlain(byte[] pageBytes) |
| 131 | + { |
| 132 | + return new Int64ShortDecimalPlainValuesDecoder(pageBytes, 0, pageBytes.length); |
| 133 | + } |
| 134 | + |
| 135 | + private static ShortDecimalValuesDecoder int32ShortDecimalRLE(byte[] pageBytes, int dictionarySize, IntegerDictionary dictionary) |
| 136 | + { |
| 137 | + return new Int32ShortDecimalRLEDictionaryValuesDecoder(getWidthFromMaxInt(dictionarySize), new ByteArrayInputStream(pageBytes), dictionary); |
| 138 | + } |
| 139 | + |
| 140 | + private static ShortDecimalValuesDecoder int64ShortDecimalRLE(byte[] pageBytes, int dictionarySize, LongDictionary dictionary) |
| 141 | + { |
| 142 | + return new Int64RLEDictionaryValuesDecoder(getWidthFromMaxInt(dictionarySize), new ByteArrayInputStream(pageBytes), dictionary); |
| 143 | + } |
| 144 | + |
121 | 145 | private static void int32BatchReadWithSkipHelper(int batchSize, int skipSize, int valueCount, Int32ValuesDecoder decoder, List<Object> expectedValues)
|
122 | 146 | throws IOException
|
123 | 147 | {
|
@@ -213,6 +237,52 @@ private static void int64BatchReadWithSkipHelper(int batchSize, int skipSize, in
|
213 | 237 | }
|
214 | 238 | }
|
215 | 239 |
|
| 240 | + private static void int32ShortDecimalBatchReadWithSkipHelper(int batchSize, int skipSize, int valueCount, ShortDecimalValuesDecoder decoder, List<Object> expectedValues) |
| 241 | + throws IOException |
| 242 | + { |
| 243 | + long[] actualValues = new long[valueCount]; |
| 244 | + int inputOffset = 0; |
| 245 | + int outputOffset = 0; |
| 246 | + while (inputOffset < valueCount) { |
| 247 | + int readBatchSize = min(batchSize, valueCount - inputOffset); |
| 248 | + decoder.readNext(actualValues, outputOffset, readBatchSize); |
| 249 | + |
| 250 | + for (int i = 0; i < readBatchSize; i++) { |
| 251 | + assertEquals(actualValues[outputOffset + i], (int) expectedValues.get(inputOffset + i)); |
| 252 | + } |
| 253 | + |
| 254 | + inputOffset += readBatchSize; |
| 255 | + outputOffset += readBatchSize; |
| 256 | + |
| 257 | + int skipBatchSize = min(skipSize, valueCount - inputOffset); |
| 258 | + decoder.skip(skipBatchSize); |
| 259 | + inputOffset += skipBatchSize; |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + private static void int64ShortDecimalBatchReadWithSkipHelper(int batchSize, int skipSize, int valueCount, ShortDecimalValuesDecoder decoder, List<Object> expectedValues) |
| 264 | + throws IOException |
| 265 | + { |
| 266 | + long[] actualValues = new long[valueCount]; |
| 267 | + int inputOffset = 0; |
| 268 | + int outputOffset = 0; |
| 269 | + while (inputOffset < valueCount) { |
| 270 | + int readBatchSize = min(batchSize, valueCount - inputOffset); |
| 271 | + decoder.readNext(actualValues, outputOffset, readBatchSize); |
| 272 | + |
| 273 | + for (int i = 0; i < readBatchSize; i++) { |
| 274 | + assertEquals(actualValues[outputOffset + i], expectedValues.get(inputOffset + i)); |
| 275 | + } |
| 276 | + |
| 277 | + inputOffset += readBatchSize; |
| 278 | + outputOffset += readBatchSize; |
| 279 | + |
| 280 | + int skipBatchSize = min(skipSize, valueCount - inputOffset); |
| 281 | + decoder.skip(skipBatchSize); |
| 282 | + inputOffset += skipBatchSize; |
| 283 | + } |
| 284 | + } |
| 285 | + |
216 | 286 | private static void timestampBatchReadWithSkipHelper(int batchSize, int skipSize, int valueCount, TimestampValuesDecoder decoder, List<Object> expectedValues)
|
217 | 287 | throws IOException
|
218 | 288 | {
|
@@ -515,4 +585,100 @@ public void testBooleanRLE()
|
515 | 585 | booleanBatchReadWithSkipHelper(89, 29, valueCount, booleanRLE(dataPage), expectedValues);
|
516 | 586 | booleanBatchReadWithSkipHelper(1024, 1024, valueCount, booleanRLE(dataPage), expectedValues);
|
517 | 587 | }
|
| 588 | + |
| 589 | + @Test |
| 590 | + public void testInt32ShortDecimalPlain() |
| 591 | + throws IOException |
| 592 | + { |
| 593 | + int valueCount = 2048; |
| 594 | + List<Object> expectedValues = new ArrayList<>(); |
| 595 | + |
| 596 | + byte[] pageBytes = generatePlainValuesPage(valueCount, 32, new Random(83), expectedValues); |
| 597 | + int32ShortDecimalBatchReadWithSkipHelper(valueCount, 0, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); // read all values in one batch |
| 598 | + int32ShortDecimalBatchReadWithSkipHelper(29, 0, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); |
| 599 | + int32ShortDecimalBatchReadWithSkipHelper(89, 0, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); |
| 600 | + int32ShortDecimalBatchReadWithSkipHelper(1024, 0, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); |
| 601 | + |
| 602 | + int32ShortDecimalBatchReadWithSkipHelper(256, 29, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); |
| 603 | + int32ShortDecimalBatchReadWithSkipHelper(89, 29, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); |
| 604 | + int32ShortDecimalBatchReadWithSkipHelper(1024, 1024, valueCount, int32ShortDecimalPlain(pageBytes), expectedValues); |
| 605 | + } |
| 606 | + |
| 607 | + @Test |
| 608 | + public void testInt64ShortDecimalPlain() |
| 609 | + throws IOException |
| 610 | + { |
| 611 | + int valueCount = 2048; |
| 612 | + List<Object> expectedValues = new ArrayList<>(); |
| 613 | + |
| 614 | + byte[] pageBytes = generatePlainValuesPage(valueCount, 64, new Random(83), expectedValues); |
| 615 | + int64ShortDecimalBatchReadWithSkipHelper(valueCount, 0, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); // read all values in one batch |
| 616 | + int64ShortDecimalBatchReadWithSkipHelper(29, 0, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); |
| 617 | + int64ShortDecimalBatchReadWithSkipHelper(89, 0, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); |
| 618 | + int64ShortDecimalBatchReadWithSkipHelper(1024, 0, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); |
| 619 | + |
| 620 | + int64ShortDecimalBatchReadWithSkipHelper(256, 29, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); |
| 621 | + int64ShortDecimalBatchReadWithSkipHelper(89, 29, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); |
| 622 | + int64ShortDecimalBatchReadWithSkipHelper(1024, 1024, valueCount, int64ShortDecimalPlain(pageBytes), expectedValues); |
| 623 | + } |
| 624 | + |
| 625 | + @Test |
| 626 | + public void testInt32ShortDecimalRLE() |
| 627 | + throws IOException |
| 628 | + { |
| 629 | + Random random = new Random(83); |
| 630 | + int valueCount = 2048; |
| 631 | + int dictionarySize = 29; |
| 632 | + List<Object> dictionary = new ArrayList<>(); |
| 633 | + List<Integer> dictionaryIds = new ArrayList<>(); |
| 634 | + |
| 635 | + byte[] dictionaryPage = generatePlainValuesPage(dictionarySize, 32, random, dictionary); |
| 636 | + byte[] dataPage = generateDictionaryIdPage2048(dictionarySize - 1, random, dictionaryIds); |
| 637 | + |
| 638 | + List<Object> expectedValues = new ArrayList<>(); |
| 639 | + for (Integer dictionaryId : dictionaryIds) { |
| 640 | + expectedValues.add(dictionary.get(dictionaryId)); |
| 641 | + } |
| 642 | + |
| 643 | + IntegerDictionary integerDictionary = new IntegerDictionary(new DictionaryPage(Slices.wrappedBuffer(dictionaryPage), dictionarySize, PLAIN_DICTIONARY)); |
| 644 | + |
| 645 | + int32ShortDecimalBatchReadWithSkipHelper(valueCount, 0, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); // read all values in one batch |
| 646 | + int32ShortDecimalBatchReadWithSkipHelper(29, 0, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); |
| 647 | + int32ShortDecimalBatchReadWithSkipHelper(89, 0, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); |
| 648 | + int32ShortDecimalBatchReadWithSkipHelper(1024, 0, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); |
| 649 | + |
| 650 | + int32ShortDecimalBatchReadWithSkipHelper(256, 29, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); |
| 651 | + int32ShortDecimalBatchReadWithSkipHelper(89, 29, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); |
| 652 | + int32ShortDecimalBatchReadWithSkipHelper(1024, 1024, valueCount, int32ShortDecimalRLE(dataPage, dictionarySize, integerDictionary), expectedValues); |
| 653 | + } |
| 654 | + |
| 655 | + @Test |
| 656 | + public void testInt64ShortDecimalRLE() |
| 657 | + throws IOException |
| 658 | + { |
| 659 | + Random random = new Random(83); |
| 660 | + int valueCount = 2048; |
| 661 | + int dictionarySize = 29; |
| 662 | + List<Object> dictionary = new ArrayList<>(); |
| 663 | + List<Integer> dictionaryIds = new ArrayList<>(); |
| 664 | + |
| 665 | + byte[] dictionaryPage = generatePlainValuesPage(dictionarySize, 64, random, dictionary); |
| 666 | + byte[] dataPage = generateDictionaryIdPage2048(dictionarySize - 1, random, dictionaryIds); |
| 667 | + |
| 668 | + List<Object> expectedValues = new ArrayList<>(); |
| 669 | + for (Integer dictionaryId : dictionaryIds) { |
| 670 | + expectedValues.add(dictionary.get(dictionaryId)); |
| 671 | + } |
| 672 | + |
| 673 | + LongDictionary longDictionary = new LongDictionary(new DictionaryPage(Slices.wrappedBuffer(dictionaryPage), dictionarySize, PLAIN_DICTIONARY)); |
| 674 | + |
| 675 | + int64ShortDecimalBatchReadWithSkipHelper(valueCount, 0, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); // read all values in one batch |
| 676 | + int64ShortDecimalBatchReadWithSkipHelper(29, 0, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); |
| 677 | + int64ShortDecimalBatchReadWithSkipHelper(89, 0, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); |
| 678 | + int64ShortDecimalBatchReadWithSkipHelper(1024, 0, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); |
| 679 | + |
| 680 | + int64ShortDecimalBatchReadWithSkipHelper(256, 29, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); |
| 681 | + int64ShortDecimalBatchReadWithSkipHelper(89, 29, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); |
| 682 | + int64ShortDecimalBatchReadWithSkipHelper(1024, 1024, valueCount, int64ShortDecimalRLE(dataPage, dictionarySize, longDictionary), expectedValues); |
| 683 | + } |
518 | 684 | }
|
0 commit comments