@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) block; // write the run length sliceOutput.writeInt(rleBlock.getPositionCount()); // write the value blockEncodingSerde.writeBlock(sliceOutput, rleBlock.getValue()); }
private static ColumnarArray toColumnarArray(RunLengthEncodedBlock rleBlock) { ColumnarArray columnarArray = toColumnarArray(rleBlock.getValue()); // build new offsets block int[] offsets = new int[rleBlock.getPositionCount() + 1]; int valueLength = columnarArray.getLength(0); for (int i = 0; i < offsets.length; i++) { offsets[i] = i * valueLength; } // create indexes for a dictionary block of the elements int[] dictionaryIds = new int[rleBlock.getPositionCount() * valueLength]; int nextDictionaryIndex = 0; for (int position = 0; position < rleBlock.getPositionCount(); position++) { for (int entryIndex = 0; entryIndex < valueLength; entryIndex++) { dictionaryIds[nextDictionaryIndex] = entryIndex; nextDictionaryIndex++; } } return new ColumnarArray( rleBlock, 0, offsets, new DictionaryBlock(dictionaryIds.length, columnarArray.getElementsBlock(), dictionaryIds)); }
private static ColumnarMap toColumnarMap(RunLengthEncodedBlock rleBlock) { ColumnarMap columnarMap = toColumnarMap(rleBlock.getValue()); // build new offsets block int[] offsets = new int[rleBlock.getPositionCount() + 1]; int entryCount = columnarMap.getEntryCount(0); for (int i = 0; i < offsets.length; i++) { offsets[i] = i * entryCount; } // create indexes for a dictionary block of the elements int[] dictionaryIds = new int[rleBlock.getPositionCount() * entryCount]; int nextDictionaryIndex = 0; for (int position = 0; position < rleBlock.getPositionCount(); position++) { for (int entryIndex = 0; entryIndex < entryCount; entryIndex++) { dictionaryIds[nextDictionaryIndex] = entryIndex; nextDictionaryIndex++; } } return new ColumnarMap( rleBlock, 0, offsets, new DictionaryBlock(dictionaryIds.length, columnarMap.getKeysBlock(), dictionaryIds), new DictionaryBlock(dictionaryIds.length, columnarMap.getValuesBlock(), dictionaryIds)); }
private static ColumnarRow toColumnarRow(RunLengthEncodedBlock rleBlock) { Block rleValue = rleBlock.getValue(); ColumnarRow columnarRow = toColumnarRow(rleValue); Block[] fields = new Block[columnarRow.getFieldCount()]; for (int i = 0; i < columnarRow.getFieldCount(); i++) { Block nullSuppressedField = columnarRow.getField(i); if (rleValue.isNull(0)) { // the rle value is a null row so, all null-suppressed fields should empty if (nullSuppressedField.getPositionCount() != 0) { throw new IllegalArgumentException("Invalid row block"); } fields[i] = nullSuppressedField; } else { fields[i] = new RunLengthEncodedBlock(nullSuppressedField, rleBlock.getPositionCount()); } } return new ColumnarRow(rleBlock, fields); }