public static ColumnarMap toColumnarMap(Block block) { requireNonNull(block, "block is null"); if (block instanceof DictionaryBlock) { return toColumnarMap((DictionaryBlock) block); } if (block instanceof RunLengthEncodedBlock) { return toColumnarMap((RunLengthEncodedBlock) block); } if (!(block instanceof AbstractMapBlock)) { throw new IllegalArgumentException("Invalid map block: " + block.getClass().getName()); } AbstractMapBlock mapBlock = (AbstractMapBlock) block; int offsetBase = mapBlock.getOffsetBase(); int[] offsets = mapBlock.getOffsets(); // get the keys and values for visible region int firstEntryPosition = mapBlock.getOffset(0); int totalEntryCount = mapBlock.getOffset(block.getPositionCount()) - firstEntryPosition; Block keysBlock = mapBlock.getRawKeyBlock().getRegion(firstEntryPosition, totalEntryCount); Block valuesBlock = mapBlock.getRawValueBlock().getRegion(firstEntryPosition, totalEntryCount); return new ColumnarMap(block, offsetBase, offsets, keysBlock, valuesBlock); }
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 ColumnarMap toColumnarMap(DictionaryBlock dictionaryBlock) { ColumnarMap columnarMap = toColumnarMap(dictionaryBlock.getDictionary()); // build new offsets int[] offsets = new int[dictionaryBlock.getPositionCount() + 1]; for (int position = 0; position < dictionaryBlock.getPositionCount(); position++) { int dictionaryId = dictionaryBlock.getId(position); offsets[position + 1] = offsets[position] + columnarMap.getEntryCount(dictionaryId); } // reindex dictionary int[] dictionaryIds = new int[offsets[dictionaryBlock.getPositionCount()]]; int nextDictionaryIndex = 0; for (int position = 0; position < dictionaryBlock.getPositionCount(); position++) { int dictionaryId = dictionaryBlock.getId(position); int entryCount = columnarMap.getEntryCount(dictionaryId); // adjust to the element block start offset int startOffset = columnarMap.getOffset(dictionaryId) - columnarMap.getOffset(0); for (int entryIndex = 0; entryIndex < entryCount; entryIndex++) { dictionaryIds[nextDictionaryIndex] = startOffset + entryIndex; nextDictionaryIndex++; } } return new ColumnarMap( dictionaryBlock, 0, offsets, new DictionaryBlock(dictionaryIds.length, columnarMap.getKeysBlock(), dictionaryIds), new DictionaryBlock(dictionaryIds.length, columnarMap.getValuesBlock(), dictionaryIds)); }