Skip to content

Commit e6930f9

Browse files
pyckleAndrew Pikler
authored andcommitted
move getDictionary to DictionaryPage
1 parent a220df6 commit e6930f9

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnReaderBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.parquet.column.page.DataPage;
3838
import org.apache.parquet.column.page.DataPageV1;
3939
import org.apache.parquet.column.page.DataPageV2;
40+
import org.apache.parquet.column.page.DictionaryPage;
4041
import org.apache.parquet.column.page.PageReader;
4142
import org.apache.parquet.column.values.RequiresPreviousReader;
4243
import org.apache.parquet.column.values.ValuesReader;
@@ -451,7 +452,8 @@ void writeValue() {
451452
this.converter = Objects.requireNonNull(converter, "converter cannot be null");
452453
this.writerVersion = writerVersion;
453454
this.maxDefinitionLevel = path.getMaxDefinitionLevel();
454-
this.dictionary = pageReader.getDictionary(path);
455+
DictionaryPage dictionaryPage = pageReader.readDictionaryPage();
456+
this.dictionary = dictionaryPage == null ? null : dictionaryPage.getDictionary(path);
455457
if (dictionary != null && converter.hasDictionarySupport()) {
456458
converter.setDictionary(dictionary);
457459
}

parquet-column/src/main/java/org/apache/parquet/column/page/DictionaryPage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
import java.io.IOException;
2222
import java.util.Objects;
2323
import org.apache.parquet.bytes.BytesInput;
24+
import org.apache.parquet.column.ColumnDescriptor;
25+
import org.apache.parquet.column.Dictionary;
2426
import org.apache.parquet.column.Encoding;
27+
import org.apache.parquet.io.ParquetDecodingException;
2528

2629
/**
2730
* Data for a dictionary page
@@ -74,6 +77,17 @@ public DictionaryPage copy() throws IOException {
7477
return new DictionaryPage(BytesInput.copy(bytes), getUncompressedSize(), dictionarySize, encoding);
7578
}
7679

80+
/**
81+
* @return the decoded dictionary
82+
*/
83+
public Dictionary getDictionary(ColumnDescriptor path) {
84+
try {
85+
return getEncoding().initDictionary(path, this);
86+
} catch (IOException e) {
87+
throw new ParquetDecodingException("could not decode the dictionary for " + path, e);
88+
}
89+
}
90+
7791
@Override
7892
public String toString() {
7993
return "Page [bytes.size=" + bytes.size() + ", entryCount=" + dictionarySize + ", uncompressedSize="

parquet-column/src/main/java/org/apache/parquet/column/page/PageReader.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
*/
1919
package org.apache.parquet.column.page;
2020

21-
import java.io.IOException;
22-
import org.apache.parquet.column.ColumnDescriptor;
23-
import org.apache.parquet.column.Dictionary;
24-
import org.apache.parquet.io.ParquetDecodingException;
25-
2621
/**
2722
* Reader for a sequence a page from a given column chunk
2823
*/
@@ -33,22 +28,6 @@ public interface PageReader {
3328
*/
3429
DictionaryPage readDictionaryPage();
3530

36-
/**
37-
* @return the dictionary in this page or null if none
38-
*/
39-
default Dictionary getDictionary(ColumnDescriptor path) {
40-
Dictionary dictionary = null;
41-
DictionaryPage dictionaryPage = readDictionaryPage();
42-
if (dictionaryPage != null) {
43-
try {
44-
dictionary = dictionaryPage.getEncoding().initDictionary(path, dictionaryPage);
45-
} catch (IOException e) {
46-
throw new ParquetDecodingException("could not decode the dictionary for " + path, e);
47-
}
48-
}
49-
return dictionary;
50-
}
51-
5231
/**
5332
* @return the total number of values in the column chunk
5433
*/

0 commit comments

Comments
 (0)