本文整理了Java中com.facebook.presto.spi.block.Block.copyPositions()
方法的一些代码示例,展示了Block.copyPositions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.copyPositions()
方法的具体详情如下:
包路径:com.facebook.presto.spi.block.Block
类名称:Block
方法名:copyPositions
[英]Returns a block containing the specified positions. Positions to copy are stored in a subarray within positions array that starts at offset and has length of length. All specified positions must be valid for this block.
The returned block must be a compact representation of the original block.
[中]返回包含指定位置的块。要复制的位置存储在位置数组中的子数组中,该数组从偏移开始,长度为。所有指定的位置必须对此块有效。
返回的块必须是原始块的紧凑表示形式。
代码示例来源:origin: prestodb/presto
@Override
public Block copyPositions(int[] positions, int offset, int length)
{
return block.copyPositions(positions, offset, length);
}
代码示例来源:origin: prestodb/presto
@Override
public Block copyPositions(int[] positions, int offset, int length)
{
assureLoaded();
return block.copyPositions(positions, offset, length);
}
代码示例来源:origin: prestodb/presto
@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);
}
代码示例来源:origin: prestodb/presto
Block compactDictionary = dictionaryBlock.getDictionary().copyPositions(dictionaryPositionsToCopy, 0, numberOfIndexes);
outputDictionaryBlocks.add(new DictionaryBlock(positionCount, compactDictionary, newIds, true, newDictionaryId));
代码示例来源:origin: prestodb/presto
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);
}
代码示例来源:origin: prestodb/presto
@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);
}
}
代码示例来源:origin: prestodb/presto
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};
}
代码示例来源:origin: prestodb/presto
Block compactDictionary = dictionary.copyPositions(dictionaryPositionsToCopy.elements(), 0, dictionaryPositionsToCopy.size());
return new DictionaryBlock(positionCount, compactDictionary, newIds, true);
代码示例来源:origin: prestodb/presto
for (int i = 0; i < page.getChannelCount(); i++) {
Block block = page.getBlock(i);
blocks[i] = block.copyPositions(positions, 0, usedPositionCount);
代码示例来源:origin: prestodb/presto
@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())));
}
}
}
代码示例来源:origin: prestodb/presto
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);
代码示例来源:origin: prestodb/presto
@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);
}
代码示例来源:origin: prestodb/presto
@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);
}
代码示例来源:origin: prestodb/presto
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);
}
代码示例来源:origin: prestodb/presto
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);
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
@Override
public Block copyPositions(List<Integer> positions)
{
return block.copyPositions(positions);
}
代码示例来源:origin: com.facebook.presto/presto-spi
@Override
public Block copyPositions(int[] positions, int offset, int length)
{
assureLoaded();
return block.copyPositions(positions, offset, length);
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
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);
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
@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);
}
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-main
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);
}
内容来源于网络,如有侵权,请联系作者删除!