|
24 | 24 | import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.DOUBLE; |
25 | 25 | import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.FLOAT; |
26 | 26 | import static org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName.INT32; |
27 | | -import static org.junit.Assert.assertEquals; |
| 27 | +import static org.junit.Assert.*; |
28 | 28 |
|
29 | 29 | import java.io.IOException; |
30 | 30 | import java.nio.ByteBuffer; |
|
44 | 44 | import org.apache.parquet.column.values.dictionary.DictionaryValuesWriter.PlainFloatDictionaryValuesWriter; |
45 | 45 | import org.apache.parquet.column.values.dictionary.DictionaryValuesWriter.PlainIntegerDictionaryValuesWriter; |
46 | 46 | import org.apache.parquet.column.values.dictionary.DictionaryValuesWriter.PlainLongDictionaryValuesWriter; |
| 47 | +import org.apache.parquet.column.values.dictionary.PlainValuesDictionary.PlainBooleanDictionary; |
47 | 48 | import org.apache.parquet.column.values.fallback.FallbackValuesWriter; |
48 | 49 | import org.apache.parquet.column.values.plain.BinaryPlainValuesReader; |
49 | 50 | import org.apache.parquet.column.values.plain.PlainValuesReader; |
@@ -678,6 +679,72 @@ public void testZeroValues() throws IOException { |
678 | 679 | } |
679 | 680 | } |
680 | 681 |
|
| 682 | + @Test |
| 683 | + public void testBooleanDictionary() throws IOException { |
| 684 | + // Create a dictionary page with boolean values (false, true) |
| 685 | + // Bit-packed: bit 0 = false (0), bit 1 = true (1) => byte = 0b00000010 = 0x02 |
| 686 | + BytesInput bytes = BytesInput.from(new byte[] {0x02}); |
| 687 | + DictionaryPage dictionaryPage = new DictionaryPage(bytes, 2, PLAIN); |
| 688 | + |
| 689 | + PlainBooleanDictionary dictionary = new PlainBooleanDictionary(dictionaryPage); |
| 690 | + |
| 691 | + // Verify dictionary decoding |
| 692 | + assertFalse(dictionary.decodeToBoolean(0)); |
| 693 | + assertTrue(dictionary.decodeToBoolean(1)); |
| 694 | + assertEquals(1, dictionary.getMaxId()); |
| 695 | + } |
| 696 | + |
| 697 | + @Test |
| 698 | + public void testBooleanDictionarySingleValue() throws IOException { |
| 699 | + // Test dictionary with only true value |
| 700 | + // Bit-packed: bit 0 = true (1) => byte = 0b00000001 = 0x01 |
| 701 | + BytesInput bytesTrue = BytesInput.from(new byte[] {0x01}); |
| 702 | + DictionaryPage dictionaryPageTrue = new DictionaryPage(bytesTrue, 1, PLAIN); |
| 703 | + |
| 704 | + PlainBooleanDictionary dictionaryTrue = new PlainBooleanDictionary(dictionaryPageTrue); |
| 705 | + |
| 706 | + assertTrue(dictionaryTrue.decodeToBoolean(0)); |
| 707 | + assertEquals(0, dictionaryTrue.getMaxId()); |
| 708 | + |
| 709 | + // Test dictionary with only false value |
| 710 | + // Bit-packed: bit 0 = false (0) => byte = 0b00000000 = 0x00 |
| 711 | + BytesInput bytesFalse = BytesInput.from(new byte[] {0x00}); |
| 712 | + DictionaryPage dictionaryPageFalse = new DictionaryPage(bytesFalse, 1, PLAIN); |
| 713 | + |
| 714 | + PlainBooleanDictionary dictionaryFalse = new PlainBooleanDictionary(dictionaryPageFalse); |
| 715 | + |
| 716 | + assertFalse(dictionaryFalse.decodeToBoolean(0)); |
| 717 | + assertEquals(0, dictionaryFalse.getMaxId()); |
| 718 | + } |
| 719 | + |
| 720 | + @Test |
| 721 | + public void testBooleanDictionaryToString() throws IOException { |
| 722 | + // Bit-packed: bit 0 = false (0), bit 1 = true (1) => byte = 0b00000010 = 0x02 |
| 723 | + BytesInput bytes = BytesInput.from(new byte[] {0x02}); |
| 724 | + DictionaryPage dictionaryPage = new DictionaryPage(bytes, 2, PLAIN); |
| 725 | + |
| 726 | + PlainBooleanDictionary dictionary = new PlainBooleanDictionary(dictionaryPage); |
| 727 | + |
| 728 | + String str = dictionary.toString(); |
| 729 | + Assert.assertTrue(str.contains("PlainIntegerDictionary")); |
| 730 | + Assert.assertTrue(str.contains("0 => false")); |
| 731 | + Assert.assertTrue(str.contains("1 => true")); |
| 732 | + } |
| 733 | + |
| 734 | + @Test |
| 735 | + public void testBooleanDictionaryWithDictionaryEncoding() throws IOException { |
| 736 | + // Test with PLAIN_DICTIONARY encoding (both PLAIN and PLAIN_DICTIONARY should work) |
| 737 | + // Bit-packed: bit 0 = true (1), bit 1 = false (0) => byte = 0b00000001 = 0x01 |
| 738 | + BytesInput bytes = BytesInput.from(new byte[] {0x01}); |
| 739 | + DictionaryPage dictionaryPage = new DictionaryPage(bytes, 2, PLAIN_DICTIONARY); |
| 740 | + |
| 741 | + PlainBooleanDictionary dictionary = new PlainBooleanDictionary(dictionaryPage); |
| 742 | + |
| 743 | + assertEquals(true, dictionary.decodeToBoolean(0)); |
| 744 | + assertEquals(false, dictionary.decodeToBoolean(1)); |
| 745 | + assertEquals(1, dictionary.getMaxId()); |
| 746 | + } |
| 747 | + |
681 | 748 | private DictionaryValuesReader initDicReader(ValuesWriter cw, PrimitiveTypeName type) throws IOException { |
682 | 749 | final DictionaryPage dictionaryPage = cw.toDictPageAndClose().copy(); |
683 | 750 | final ColumnDescriptor descriptor = new ColumnDescriptor(new String[] {"foo"}, type, 0, 0); |
|
0 commit comments