From 8f39e4cdde83eb2c16facc276514ad2f2453259f Mon Sep 17 00:00:00 2001 From: lukasz-stec Date: Mon, 12 Jun 2023 09:34:26 +0200 Subject: [PATCH] Support RLE DictionaryBlock.dictionary in UnnestingPositionsAppender DictionaryBlock.dictionary will not be RLE in normal circumstances, but since there is no precondition in the constructor, we cannot rely on this to be always the case --- .../io/trino/operator/output/RleAwarePositionsAppender.java | 2 +- .../io/trino/operator/output/UnnestingPositionsAppender.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/operator/output/RleAwarePositionsAppender.java b/core/trino-main/src/main/java/io/trino/operator/output/RleAwarePositionsAppender.java index 41b08f0397a6..dbffe7983146 100644 --- a/core/trino-main/src/main/java/io/trino/operator/output/RleAwarePositionsAppender.java +++ b/core/trino-main/src/main/java/io/trino/operator/output/RleAwarePositionsAppender.java @@ -54,7 +54,7 @@ public void append(IntArrayList positions, Block source) { // RleAwarePositionsAppender should be used with UnnestingPositionsAppender that makes sure // append is called only with flat block - checkArgument(!(source instanceof RunLengthEncodedBlock), "Append should be called with flat block but got %s", source); + checkArgument(!(source instanceof RunLengthEncodedBlock), "Append should be called with non-RLE block but got %s", source); switchToFlat(); delegate.append(positions, source); } diff --git a/core/trino-main/src/main/java/io/trino/operator/output/UnnestingPositionsAppender.java b/core/trino-main/src/main/java/io/trino/operator/output/UnnestingPositionsAppender.java index c56f02b4c754..cedc3ece1cfd 100644 --- a/core/trino-main/src/main/java/io/trino/operator/output/UnnestingPositionsAppender.java +++ b/core/trino-main/src/main/java/io/trino/operator/output/UnnestingPositionsAppender.java @@ -117,6 +117,11 @@ public long getSizeInBytes() private void appendDictionary(IntArrayList positions, DictionaryBlock source) { Block dictionary = source.getDictionary(); + if (dictionary instanceof RunLengthEncodedBlock rleDictionary) { + appendRle(rleDictionary.getValue(), positions.size()); + return; + } + IntArrayList dictionaryPositions = getDictionaryPositions(positions, source); if (dictionaryBlockBuilder.canAppend(dictionary)) { dictionaryBlockBuilder.append(dictionaryPositions, dictionary);