private static int[] getNewIds(int positionCount, DictionaryBlock dictionaryBlock, int[] remapIndex) { int[] newIds = new int[positionCount]; for (int i = 0; i < positionCount; i++) { int newId = remapIndex[dictionaryBlock.getId(i)]; if (newId == -1) { throw new IllegalStateException("reference to a non-existent key"); } newIds[i] = newId; } return newIds; }
@Override public short getShort(int position, int offset) { return dictionary.getShort(getId(position), offset); }
@Override public boolean equals(int position, int offset, Block otherBlock, int otherPosition, int otherOffset, int length) { return dictionary.equals(getId(position), offset, otherBlock, otherPosition, otherOffset, length); }
@Override public boolean isNull(int position) { return dictionary.isNull(getId(position)); }
@Override public int getSliceLength(int position) { return dictionary.getSliceLength(getId(position)); }
@Override public byte getByte(int position, int offset) { return dictionary.getByte(getId(position), offset); }
@Override public long hash(int position, int offset, int length) { return dictionary.hash(getId(position), offset, length); }
@Override public Block getSingleValueBlock(int position) { return dictionary.getSingleValueBlock(getId(position)); }
@Override public long getLong(int position, int offset) { return dictionary.getLong(getId(position), offset); }
@Override public Slice getSlice(int position, int offset, int length) { return dictionary.getSlice(getId(position), offset, length); }
@Override public <T> T getObject(int position, Class<T> clazz) { return dictionary.getObject(getId(position), clazz); }
@Override public int compareTo(int leftPosition, int leftOffset, int leftLength, Block rightBlock, int rightPosition, int rightOffset, int rightLength) { return dictionary.compareTo(getId(leftPosition), leftOffset, leftLength, rightBlock, rightPosition, rightOffset, rightLength); }
@Override public int getInt(int position, int offset) { return dictionary.getInt(getId(position), offset); }
@Override public int bytesCompare(int position, int offset, int length, Slice otherSlice, int otherOffset, int otherLength) { return dictionary.bytesCompare(getId(position), offset, length, otherSlice, otherOffset, otherLength); }
@Override public long getEstimatedDataSizeForStats(int position) { return dictionary.getEstimatedDataSizeForStats(getId(position)); }
@Override public boolean bytesEqual(int position, int offset, Slice otherSlice, int otherOffset, int length) { return dictionary.bytesEqual(getId(position), offset, otherSlice, otherOffset, length); }
@Override public void writeBytesTo(int position, int offset, int length, BlockBuilder blockBuilder) { dictionary.writeBytesTo(getId(position), offset, length, blockBuilder); }
@Override public void writePositionTo(int position, BlockBuilder blockBuilder) { dictionary.writePositionTo(getId(position), blockBuilder); }
@Override public long getPositionsSizeInBytes(boolean[] positions) { checkValidPositions(positions, positionCount); boolean[] used = new boolean[dictionary.getPositionCount()]; for (int i = 0; i < positions.length; i++) { if (positions[i]) { used[getId(i)] = true; } } return dictionary.getPositionsSizeInBytes(used) + (Integer.BYTES * (long) countUsedPositions(positions)); }
private static void assertDictionaryIds(DictionaryBlock dictionaryBlock, int... expected) { assertEquals(dictionaryBlock.getPositionCount(), expected.length); for (int position = 0; position < dictionaryBlock.getPositionCount(); position++) { assertEquals(dictionaryBlock.getId(position), expected[position]); } } }