/** * Create a new block from the current materialized block by keeping the same elements * only with respect to {@code visiblePositions}. */ default Block getPositions(int[] visiblePositions, int offset, int length) { return build().getPositions(visiblePositions, offset, length); }
private Page maskToDistinctOutputPositions(int distinctCount, int[] distinctPositions) { Page result = null; if (distinctCount > 0) { Block[] blocks = outputChannels.stream() .map(inputPage::getBlock) .map(block -> block.getPositions(distinctPositions, 0, distinctCount)) .toArray(Block[]::new); result = new Page(distinctCount, blocks); } return result; }
@Override public Block getPositions(int[] positions, int offset, int length) { assureLoaded(); return block.getPositions(positions, offset, length); }
public Page getPositions(int[] retainedPositions, int offset, int length) { requireNonNull(retainedPositions, "retainedPositions is null"); Block[] blocks = new Block[this.blocks.length]; Arrays.setAll(blocks, i -> this.blocks[i].getPositions(retainedPositions, offset, length)); return new Page(length, blocks); }
@Override public void load(LazyBlock lazyBlock) { if (block == null) { return; } lazyBlock.setBlock(block.getPositions(rowsToKeep.elements(), 0, rowsToKeep.size())); // clear reference to loader to free resources, since load was successful block = null; } }
private static void assertInvalidGetPositions(Block block, int[] positions, int offset, int length) { try { block.getPositions(positions, offset, length).getLong(0, 0); fail("Expected to fail"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().startsWith("position is not valid")); } catch (IndexOutOfBoundsException e) { assertTrue(e.getMessage().startsWith("Invalid offset")); } } }
private static Optional<Page> extractStatisticsRows(Page page) { int statisticsPositionCount = 0; for (int position = 0; position < page.getPositionCount(); position++) { if (isStatisticsPosition(page, position)) { statisticsPositionCount++; } } if (statisticsPositionCount == 0) { return Optional.empty(); } if (statisticsPositionCount == page.getPositionCount()) { return Optional.of(page); } int selectedPositionsIndex = 0; int[] selectedPositions = new int[statisticsPositionCount]; for (int position = 0; position < page.getPositionCount(); position++) { if (isStatisticsPosition(page, position)) { selectedPositions[selectedPositionsIndex] = position; selectedPositionsIndex++; } } Block[] blocks = new Block[page.getChannelCount()]; for (int channel = 0; channel < page.getChannelCount(); channel++) { blocks[channel] = page.getBlock(channel).getPositions(selectedPositions, 0, statisticsPositionCount); } return Optional.of(new Page(statisticsPositionCount, blocks)); }
@TypeParameter("T") @SqlType("array(array(T))") public static Block ngrams(@SqlType("array(T)") Block array, @SqlType(INTEGER) long n) { checkCondition(n > 0, INVALID_FUNCTION_ARGUMENT, "N must be positive"); // n should not be larger than the array length int elementsPerRecord = toIntExact(min(array.getPositionCount(), n)); int totalRecords = array.getPositionCount() - elementsPerRecord + 1; int[] ids = new int[totalRecords * elementsPerRecord]; int[] offset = new int[totalRecords + 1]; for (int recordIndex = 0; recordIndex < totalRecords; recordIndex++) { for (int elementIndex = 0; elementIndex < elementsPerRecord; elementIndex++) { ids[recordIndex * elementsPerRecord + elementIndex] = recordIndex + elementIndex; } offset[recordIndex + 1] = (recordIndex + 1) * elementsPerRecord; } return ArrayBlock.fromElementBlock(totalRecords, Optional.empty(), offset, array.getPositions(ids, 0, totalRecords * elementsPerRecord)); } }
dictionaryBlock = dictionaryBlock.getPositions(new int[] {0, 8, 1, 2, 4, 5, 7, 9}, 2, 4); assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] {expectedValues[1], expectedValues[2], expectedValues[4], expectedValues[5]}); assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId); dictionaryBlock = dictionaryBlock.getPositions(new int[] {0, 1, 3, 0, 0}, 0, 3); assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] {expectedValues[1], expectedValues[2], expectedValues[5]}); assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId); dictionaryBlock = dictionaryBlock.getPositions(new int[] {-1, -1, 0, 1, 2}, 2, 3); assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] {expectedValues[1], expectedValues[2], expectedValues[5]}); assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId); dictionaryBlock = dictionaryBlock.getPositions(new int[] {0, 2, 2}, 0, 3); assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] {expectedValues[1], expectedValues[5], expectedValues[5]}); assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId); dictionaryBlock = dictionaryBlock.getPositions(new int[] {1, 1, 1, 1, 1}, 0, 5); assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] {expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5]}); assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId); dictionaryBlock.getPositions(new int[] {position}, 0, 1); fail("Expected to fail"); dictionaryBlock.getPositions(new int[] {0}, offset, 1); fail("Expected to fail"); dictionaryBlock.getPositions(new int[] {0}, 0, length); fail("Expected to fail");
adaptedBlocks[i] = block.getPositions(rowsToKeep.elements(), 0, rowsToKeep.size());
Block probeBlock = probe.getPage().getBlock(probeOutputChannels[i]); if (!isSequentialProbeIndices || length == 0) { blocks[i] = probeBlock.getPositions(probeIndices, 0, probeIndices.length);
assertBlockEquals(BIGINT, block.getPositions(positions, 0, positions.length), BIGINT.createFixedSizeBlockBuilder(5).appendNull().writeLong(42).writeLong(42).writeLong(42).appendNull().build()); assertBlockEquals(BIGINT, block.getPositions(positions, 1, 4), BIGINT.createFixedSizeBlockBuilder(5).writeLong(42).writeLong(42).writeLong(42).appendNull().build()); assertBlockEquals(BIGINT, block.getPositions(positions, 2, 1), BIGINT.createFixedSizeBlockBuilder(5).writeLong(42).build()); assertBlockEquals(BIGINT, block.getPositions(positions, 0, 0), BIGINT.createFixedSizeBlockBuilder(5).build()); assertBlockEquals(BIGINT, block.getPositions(positions, 1, 0), BIGINT.createFixedSizeBlockBuilder(5).build()); block.getPositions(positions, 0, positions.length - 1).retainedBytesForEachPart((part, size) -> { if (part == positions) { isIdentical.set(true);
/** * Create a new block from the current materialized block by keeping the same elements * only with respect to {@code visiblePositions}. */ default Block getPositions(int[] visiblePositions, int offset, int length) { return build().getPositions(visiblePositions, offset, length); }
@Override public Block getPositions(int[] positions, int offset, int length) { assureLoaded(); return block.getPositions(positions, offset, length); }
public Page getPositions(int[] retainedPositions, int offset, int length) { requireNonNull(retainedPositions, "retainedPositions is null"); Block[] blocks = new Block[this.blocks.length]; Arrays.setAll(blocks, i -> this.blocks[i].getPositions(retainedPositions, offset, length)); return new Page(length, blocks); }