Skip to content

Commit

Permalink
Unwrap a dictionary block in a run length encoded block
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Sep 18, 2022
1 parent 9a04fca commit 08342e5
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,28 @@ public RunLengthEncodedBlock(Block value, int positionCount)
if (value.getPositionCount() != 1) {
throw new IllegalArgumentException(format("Expected value to contain a single position but has %s positions", value.getPositionCount()));
}
if (positionCount < 0) {
throw new IllegalArgumentException("positionCount is negative");
}

if (value instanceof RunLengthEncodedBlock) {
this.value = ((RunLengthEncodedBlock) value).getValue();
// do not nest an RLE or Dictionary in an RLE
if (value instanceof RunLengthEncodedBlock block) {
this.value = block.getValue();
}
else if (value instanceof DictionaryBlock block) {
Block dictionary = block.getDictionary();
int id = block.getId(0);
if (dictionary.getPositionCount() == 1 && id == 0) {
this.value = dictionary;
}
else {
this.value = dictionary.getRegion(id, 1);
}
}
else {
this.value = value;
}

if (positionCount < 0) {
throw new IllegalArgumentException("positionCount is negative");
}

this.positionCount = positionCount;
}

Expand Down

0 comments on commit 08342e5

Please sign in to comment.