@Override public Block copyPositions(int[] positions, int offset, int length) { return block.copyPositions(positions, offset, length); }
@Override public Block copyPositions(int[] positions, int offset, int length) { assureLoaded(); return block.copyPositions(positions, offset, length); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); IntArrayList positionsToCopy = new IntArrayList(); Map<Integer, Integer> oldIndexToNewIndex = new HashMap<>(); int[] newIds = new int[length]; for (int i = 0; i < length; i++) { int position = positions[offset + i]; int oldIndex = getId(position); if (!oldIndexToNewIndex.containsKey(oldIndex)) { oldIndexToNewIndex.put(oldIndex, positionsToCopy.size()); positionsToCopy.add(oldIndex); } newIds[i] = oldIndexToNewIndex.get(oldIndex); } return new DictionaryBlock(dictionary.copyPositions(positionsToCopy.elements(), 0, positionsToCopy.size()), newIds); }
Block compactDictionary = dictionaryBlock.getDictionary().copyPositions(dictionaryPositionsToCopy, 0, numberOfIndexes); outputDictionaryBlocks.add(new DictionaryBlock(positionCount, compactDictionary, newIds, true, newDictionaryId));
protected <T> void assertBlockFilteredPositions(T[] expectedValues, Block block, Supplier<BlockBuilder> newBlockBuilder, int... positions) { Block filteredBlock = block.copyPositions(positions, 0, positions.length); T[] filteredExpectedValues = filter(expectedValues, positions); assertEquals(filteredBlock.getPositionCount(), positions.length); assertBlock(filteredBlock, newBlockBuilder, filteredExpectedValues); }
@Override public Work<Block> project(ConnectorSession session, DriverYieldSignal yieldSignal, Page page, SelectedPositions selectedPositions) { Block block = requireNonNull(page, "page is null").getBlock(0); requireNonNull(selectedPositions, "selectedPositions is null"); Block result; if (selectedPositions.isList()) { result = block.copyPositions(selectedPositions.getPositions(), selectedPositions.getOffset(), selectedPositions.size()); } else { result = block.getRegion(selectedPositions.getOffset(), selectedPositions.size()); } return new CompletedWork<>(result); } }
private static Block[] createKeyValueBlock(int positionCount, Block keys, Block values, int[] lengths) { if (!hasNull(keys)) { return new Block[] {keys, values}; } // // Map entries with a null key are skipped in the Hive ORC reader, so skip them here also // IntArrayList nonNullPositions = new IntArrayList(keys.getPositionCount()); int position = 0; for (int mapIndex = 0; mapIndex < positionCount; mapIndex++) { int length = lengths[mapIndex]; for (int entryIndex = 0; entryIndex < length; entryIndex++) { if (keys.isNull(position)) { // key is null, so remove this entry from the map lengths[mapIndex]--; } else { nonNullPositions.add(position); } position++; } } Block newKeys = keys.copyPositions(nonNullPositions.elements(), 0, nonNullPositions.size()); Block newValues = values.copyPositions(nonNullPositions.elements(), 0, nonNullPositions.size()); return new Block[] {newKeys, newValues}; }
Block compactDictionary = dictionary.copyPositions(dictionaryPositionsToCopy.elements(), 0, dictionaryPositionsToCopy.size()); return new DictionaryBlock(positionCount, compactDictionary, newIds, true);
for (int i = 0; i < page.getChannelCount(); i++) { Block block = page.getBlock(i); blocks[i] = block.copyPositions(positions, 0, usedPositionCount);
@Override public synchronized void accept(Page page) { // reset the assignment lists for (IntList partitionAssignment : partitionAssignments) { partitionAssignment.clear(); } // assign each row to a partition for (int position = 0; position < page.getPositionCount(); position++) { int partition = partitionGenerator.getPartition(page, position); partitionAssignments[partition].add(position); } // build a page for each partition Block[] outputBlocks = new Block[page.getChannelCount()]; for (int partition = 0; partition < buffers.size(); partition++) { IntArrayList positions = partitionAssignments[partition]; if (!positions.isEmpty()) { for (int i = 0; i < page.getChannelCount(); i++) { outputBlocks[i] = page.getBlock(i).copyPositions(positions.elements(), 0, positions.size()); } Page pageSplit = new Page(positions.size(), outputBlocks); memoryManager.updateMemoryUsage(pageSplit.getRetainedSizeInBytes()); buffers.get(partition).accept(new PageReference(pageSplit, 1, () -> memoryManager.updateMemoryUsage(-pageSplit.getRetainedSizeInBytes()))); } } }
Block newKeys = getRawKeyBlock().copyPositions(entriesPositions.elements(), 0, entriesPositions.size()); Block newValues = getRawValueBlock().copyPositions(entriesPositions.elements(), 0, entriesPositions.size()); return createMapBlockInternal(0, length, Optional.of(newMapIsNull), newOffsets, newKeys, newValues, newHashTable, keyType, keyBlockNativeEquals, keyNativeHashCode);
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); int[] newOffsets = new int[length + 1]; boolean[] newRowIsNull = new boolean[length]; IntArrayList fieldBlockPositions = new IntArrayList(length); for (int i = 0; i < length; i++) { int position = positions[offset + i]; if (isNull(position)) { newRowIsNull[i] = true; newOffsets[i + 1] = newOffsets[i]; } else { newOffsets[i + 1] = newOffsets[i] + 1; fieldBlockPositions.add(getFieldBlockOffset(position)); } } Block[] newBlocks = new Block[numFields]; for (int i = 0; i < numFields; i++) { newBlocks[i] = getRawFieldBlocks()[i].copyPositions(fieldBlockPositions.elements(), 0, fieldBlockPositions.size()); } return createRowBlockInternal(0, length, newRowIsNull, newOffsets, newBlocks); }
@Override public Block copyPositions(int[] positions, int offset, int length) { checkArrayRange(positions, offset, length); int[] newOffsets = new int[length + 1]; boolean[] newValueIsNull = new boolean[length]; IntArrayList valuesPositions = new IntArrayList(); int newPosition = 0; for (int i = offset; i < offset + length; ++i) { int position = positions[i]; if (isNull(position)) { newValueIsNull[newPosition] = true; newOffsets[newPosition + 1] = newOffsets[newPosition]; } else { int valuesStartOffset = getOffset(position); int valuesEndOffset = getOffset(position + 1); int valuesLength = valuesEndOffset - valuesStartOffset; newOffsets[newPosition + 1] = newOffsets[newPosition] + valuesLength; for (int elementIndex = valuesStartOffset; elementIndex < valuesEndOffset; elementIndex++) { valuesPositions.add(elementIndex); } } newPosition++; } Block newValues = getRawElementBlock().copyPositions(valuesPositions.elements(), 0, valuesPositions.size()); return createArrayBlockInternal(0, length, newValueIsNull, newOffsets, newValues); }
private static void testProjectList(Block block, Class<? extends Block> expectedResultType, DictionaryAwarePageProjection projection, boolean forceYield) { DriverYieldSignal yieldSignal = new DriverYieldSignal(); int[] positions = {0, 2, 4, 6, 8, 10}; Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsList(positions, 0, positions.length)); Block result; if (forceYield) { result = projectWithYield(work, yieldSignal); } else { assertTrue(work.process()); result = work.getResult(); } assertBlockEquals( BIGINT, result, block.copyPositions(positions, 0, positions.length)); assertInstanceOf(result, expectedResultType); }
protected <T> void assertBlockPosition(Block block, Supplier<BlockBuilder> newBlockBuilder, int position, T expectedValue, Class<?> expectedValueType) { assertPositionValue(block, position, expectedValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedValue); assertPositionValue(block.getRegion(position, 1), 0, expectedValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(copyBlockViaBlockSerde(block.getRegion(position, 1)), 0, expectedValue); assertPositionValue(copyBlockViaBlockSerde(block.getRegion(0, position + 1)), position, expectedValue); assertPositionValue(copyBlockViaBlockSerde(block.getRegion(position, block.getPositionCount() - position)), 0, expectedValue); assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(position, 1), newBlockBuilder), 0, expectedValue); assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(0, position + 1), newBlockBuilder), position, expectedValue); assertPositionValue(copyBlockViaWritePositionTo(block.getRegion(position, block.getPositionCount() - position), newBlockBuilder), 0, expectedValue); if (expectedValueType.isArray() || expectedValueType == List.class || expectedValueType == Map.class) { assertPositionValue(copyBlockViaWriteStructure(block.getRegion(position, 1), newBlockBuilder), 0, expectedValue); assertPositionValue(copyBlockViaWriteStructure(block.getRegion(0, position + 1), newBlockBuilder), position, expectedValue); assertPositionValue(copyBlockViaWriteStructure(block.getRegion(position, block.getPositionCount() - position), newBlockBuilder), 0, expectedValue); } assertPositionValue(block.copyRegion(position, 1), 0, expectedValue); assertPositionValue(block.copyRegion(0, position + 1), position, expectedValue); assertPositionValue(block.copyRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(block.copyPositions(new int[] {position}, 0, 1), 0, expectedValue); }
@Override public Block copyPositions(List<Integer> positions) { return block.copyPositions(positions); }
@Override public Block copyPositions(int[] positions, int offset, int length) { assureLoaded(); return block.copyPositions(positions, offset, length); }
protected <T> void assertBlockFilteredPositions(T[] expectedValues, Block block, List<Integer> positions) { Block filteredBlock = block.copyPositions(positions); T[] filteredExpectedValues = filter(expectedValues, positions); assertEquals(filteredBlock.getPositionCount(), positions.size()); assertBlock(filteredBlock, filteredExpectedValues); }
@Override protected <T> void assertBlockPosition(Block block, int position, T expectedValue) { assertPositionValue(block, position, expectedValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedValue); assertPositionValue(block.getRegion(position, 1), 0, expectedValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(block.copyRegion(position, 1), 0, expectedValue); assertPositionValue(block.copyRegion(0, position + 1), position, expectedValue); assertPositionValue(block.copyRegion(position, block.getPositionCount() - position), 0, expectedValue); int positionFloored = position / COLUMN_COUNT * COLUMN_COUNT; assertPositionValue(block.copyPositions(IntStream.range(positionFloored, positionFloored + COLUMN_COUNT).boxed().collect(Collectors.toList())), position % COLUMN_COUNT, expectedValue); } }
protected <T> void assertBlockPosition(Block block, int position, T expectedValue) { assertPositionValue(block, position, expectedValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedValue); assertPositionValue(block.getRegion(position, 1), 0, expectedValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(block.copyRegion(position, 1), 0, expectedValue); assertPositionValue(block.copyRegion(0, position + 1), position, expectedValue); assertPositionValue(block.copyRegion(position, block.getPositionCount() - position), 0, expectedValue); assertPositionValue(block.copyPositions(Ints.asList(position)), 0, expectedValue); }