@Override public Block getRegion(int positionOffset, int length) { return block.getRegion(positionOffset, length); }
@Override public Block getRegion(int positionOffset, int length) { return block.getRegion(positionOffset, length); }
@Override public Block getRegion(int positionOffset, int length) { assureLoaded(); return block.getRegion(positionOffset, length); }
public Page getRegion(int positionOffset, int length) { if (positionOffset < 0 || length < 0 || positionOffset + length > positionCount) { throw new IndexOutOfBoundsException(format("Invalid position %s and length %s in page with %s positions", positionOffset, length, positionCount)); } int channelCount = getChannelCount(); Block[] slicedBlocks = new Block[channelCount]; for (int i = 0; i < channelCount; i++) { slicedBlocks[i] = blocks[i].getRegion(positionOffset, length); } return new Page(length, slicedBlocks); }
@Override public <T> T getObject(int position, Class<T> clazz) { if (clazz != Block.class) { throw new IllegalArgumentException("clazz must be Block.class"); } checkReadablePosition(position); int startValueOffset = getOffset(position); int endValueOffset = getOffset(position + 1); return clazz.cast(getRawElementBlock().getRegion(startValueOffset, endValueOffset - startValueOffset)); }
protected List<Block> splitBlock(Block block, int count) { double sizePerSplit = block.getPositionCount() * 1.0 / count; ImmutableList.Builder<Block> result = ImmutableList.builder(); for (int i = 0; i < count; i++) { int startPosition = toIntExact(Math.round(sizePerSplit * i)); int endPosition = toIntExact(Math.round(sizePerSplit * (i + 1))); result.add(block.getRegion(startPosition, endPosition - startPosition)); } return result.build(); }
public static RunLengthEncodedBlock createTestRleBlock(Block block, int position) { return new RunLengthEncodedBlock(block.getRegion(position, 1), 10); } }
protected List<Block> splitBlock(Block block, int count) { double sizePerSplit = block.getPositionCount() * 1.0 / count; ImmutableList.Builder<Block> result = ImmutableList.builder(); for (int i = 0; i < count; i++) { int startPosition = toIntExact(Math.round(sizePerSplit * i)); int endPosition = toIntExact(Math.round(sizePerSplit * (i + 1))); result.add(block.getRegion(startPosition, endPosition - startPosition)); } return result.build(); }
public static RunLengthEncodedBlock createTestRleBlock(Block block, int position) { return new RunLengthEncodedBlock(block.getRegion(position, 1), 10); } }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { SingleRowBlock singleRowBlock = (SingleRowBlock) block; int numFields = singleRowBlock.getNumFields(); int rowIndex = singleRowBlock.getRowIndex(); sliceOutput.appendInt(numFields); for (int i = 0; i < numFields; i++) { blockEncodingSerde.writeBlock(sliceOutput, singleRowBlock.getRawFieldBlock(i).getRegion(rowIndex, 1)); } }
@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); } }
@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); } }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { SingleMapBlock singleMapBlock = (SingleMapBlock) block; TypeSerde.writeType(sliceOutput, singleMapBlock.keyType); int offset = singleMapBlock.getOffset(); int positionCount = singleMapBlock.getPositionCount(); blockEncodingSerde.writeBlock(sliceOutput, singleMapBlock.getRawKeyBlock().getRegion(offset / 2, positionCount / 2)); blockEncodingSerde.writeBlock(sliceOutput, singleMapBlock.getRawValueBlock().getRegion(offset / 2, positionCount / 2)); int[] hashTable = singleMapBlock.getHashTable(); sliceOutput.appendInt(positionCount / 2 * HASH_MULTIPLIER); sliceOutput.writeBytes(wrappedIntArray(hashTable, offset / 2 * HASH_MULTIPLIER, positionCount / 2 * HASH_MULTIPLIER)); }
protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue) { long hash = 0; if (type.isComparable()) { hash = hashPosition(type, block, position); } assertPositionValue(block, position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, 1), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedStackValue, hash, expectedObjectValue); BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); type.appendTo(block, position, blockBuilder); assertPositionValue(blockBuilder.build(), 0, expectedStackValue, hash, expectedObjectValue); }
private static void verifyBlock(Block block, Slice[][][] expectedValues) { assertBlock(block, expectedValues); assertColumnarMap(block, expectedValues); assertDictionaryBlock(block, expectedValues); assertRunLengthEncodedBlock(block, expectedValues); int offset = 1; int length = expectedValues.length - 2; Block blockRegion = block.getRegion(offset, length); Slice[][][] expectedValuesRegion = Arrays.copyOfRange(expectedValues, offset, offset + length); assertBlock(blockRegion, expectedValuesRegion); assertColumnarMap(blockRegion, expectedValuesRegion); assertDictionaryBlock(blockRegion, expectedValuesRegion); assertRunLengthEncodedBlock(blockRegion, expectedValuesRegion); }
private static <T> void verifyBlock(Block block, T[] expectedValues) { assertBlock(block, expectedValues); assertColumnarArray(block, expectedValues); assertDictionaryBlock(block, expectedValues); assertRunLengthEncodedBlock(block, expectedValues); int offset = 1; int length = expectedValues.length - 2; Block blockRegion = block.getRegion(offset, length); T[] expectedValuesRegion = Arrays.copyOfRange(expectedValues, offset, offset + length); assertBlock(blockRegion, expectedValuesRegion); assertColumnarArray(blockRegion, expectedValuesRegion); assertDictionaryBlock(blockRegion, expectedValuesRegion); assertRunLengthEncodedBlock(blockRegion, expectedValuesRegion); }
private static <T> void verifyBlock(Block block, T[] expectedValues) { assertBlock(block, expectedValues); assertColumnarRow(block, expectedValues); assertDictionaryBlock(block, expectedValues); assertRunLengthEncodedBlock(block, expectedValues); int offset = 1; int length = expectedValues.length - 2; Block blockRegion = block.getRegion(offset, length); T[] expectedValuesRegion = Arrays.copyOfRange(expectedValues, offset, offset + length); assertBlock(blockRegion, expectedValuesRegion); assertColumnarRow(blockRegion, expectedValuesRegion); assertDictionaryBlock(blockRegion, expectedValuesRegion); assertRunLengthEncodedBlock(blockRegion, expectedValuesRegion); }
private static void verifyBlock(Block block, Slice[][][] expectedValues) { assertBlock(block, expectedValues); assertColumnarMap(block, expectedValues); assertDictionaryBlock(block, expectedValues); assertRunLengthEncodedBlock(block, expectedValues); int offset = 1; int length = expectedValues.length - 2; Block blockRegion = block.getRegion(offset, length); Slice[][][] expectedValuesRegion = Arrays.copyOfRange(expectedValues, offset, offset + length); assertBlock(blockRegion, expectedValuesRegion); assertColumnarMap(blockRegion, expectedValuesRegion); assertDictionaryBlock(blockRegion, expectedValuesRegion); assertRunLengthEncodedBlock(blockRegion, expectedValuesRegion); }
private static <T> void verifyBlock(Block block, T[] expectedValues) { assertBlock(block, expectedValues); assertColumnarArray(block, expectedValues); assertDictionaryBlock(block, expectedValues); assertRunLengthEncodedBlock(block, expectedValues); int offset = 1; int length = expectedValues.length - 2; Block blockRegion = block.getRegion(offset, length); T[] expectedValuesRegion = Arrays.copyOfRange(expectedValues, offset, offset + length); assertBlock(blockRegion, expectedValuesRegion); assertColumnarArray(blockRegion, expectedValuesRegion); assertDictionaryBlock(blockRegion, expectedValuesRegion); assertRunLengthEncodedBlock(blockRegion, expectedValuesRegion); }
private static void testProjectFastReturnIgnoreYield(Block block, DictionaryAwarePageProjection projection) { DriverYieldSignal yieldSignal = new DriverYieldSignal(); Work<Block> work = projection.project(null, yieldSignal, new Page(block), SelectedPositions.positionsRange(5, 10)); yieldSignal.setWithDelay(1, executor); yieldSignal.forceYieldForTesting(); // yield signal is ignored given the block has already been loaded assertTrue(work.process()); Block result = work.getResult(); yieldSignal.reset(); assertBlockEquals( BIGINT, result, block.getRegion(5, 10)); assertInstanceOf(result, DictionaryBlock.class); }