From 3443fab6ba93e20662b8d5e6848a9e70214107a5 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Tue, 28 May 2024 12:33:11 -0700 Subject: [PATCH] fix: Reuse previous CometDictionary Java arrays --- .../main/java/org/apache/comet/parquet/ColumnReader.java | 6 +++++- .../java/org/apache/comet/vector/CometDictionary.java | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/apache/comet/parquet/ColumnReader.java b/common/src/main/java/org/apache/comet/parquet/ColumnReader.java index 3d4cb3aa5..9e594804f 100644 --- a/common/src/main/java/org/apache/comet/parquet/ColumnReader.java +++ b/common/src/main/java/org/apache/comet/parquet/ColumnReader.java @@ -234,7 +234,11 @@ public CometDecodedVector loadVector() { Dictionary arrowDictionary = importer.getProvider().lookup(dictionaryEncoding.getId()); CometPlainVector dictionaryVector = new CometPlainVector(arrowDictionary.getVector(), useDecimal128, isUuid); - dictionary = new CometDictionary(dictionaryVector); + if (dictionary != null) { + dictionary.setDictionaryVector(dictionaryVector); + } else { + dictionary = new CometDictionary(dictionaryVector); + } currentVector = new CometDictionaryVector( diff --git a/common/src/main/java/org/apache/comet/vector/CometDictionary.java b/common/src/main/java/org/apache/comet/vector/CometDictionary.java index 9aa42bd68..b213b75d8 100644 --- a/common/src/main/java/org/apache/comet/vector/CometDictionary.java +++ b/common/src/main/java/org/apache/comet/vector/CometDictionary.java @@ -26,7 +26,7 @@ public class CometDictionary implements AutoCloseable { private static final int DECIMAL_BYTE_WIDTH = 16; - private final CometPlainVector values; + private CometPlainVector values; private final int numValues; /** Decoded dictionary values. Only one of the following is set. */ @@ -47,6 +47,13 @@ public CometDictionary(CometPlainVector values) { initialize(); } + public void setDictionaryVector(CometPlainVector values) { + this.values = values; + if (values.numValues() != numValues) { + throw new IllegalArgumentException("Mismatched dictionary size"); + } + } + public ValueVector getValueVector() { return values.getValueVector(); }