com.facebook.presto.spi.block.Block.copyRegion()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中com.facebook.presto.spi.block.Block.copyRegion()方法的一些代码示例,展示了Block.copyRegion()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.copyRegion()方法的具体详情如下:
包路径:com.facebook.presto.spi.block.Block
类名称:Block
方法名:copyRegion

Block.copyRegion介绍

[英]Returns a block starting at the specified position and extends for the specified length. The specified region must be entirely contained within this block.

The region returned must be a compact representation of the original block, unless their internal representation will be exactly the same. This method is useful for operators that hold on to a range of values without holding on to the entire block.
[中]返回从指定位置开始并延伸指定长度的块。指定的区域必须完全包含在此块中。
返回的区域必须是原始块的紧凑表示形式,除非其内部表示形式完全相同。此方法对于保留一系列值而不保留整个块的运算符非常有用。

代码示例

代码示例来源:origin: prestodb/presto

@Override
public Block copyRegion(int positionOffset, int length)
{
  return block.copyRegion(positionOffset, length);
}

代码示例来源:origin: prestodb/presto

@Override
public Block copyRegion(int position, int length)
{
  assureLoaded();
  return block.copyRegion(position, length);
}

代码示例来源:origin: prestodb/presto

@Override
public Block copyRegion(int positionOffset, int length)
{
  checkValidRegion(positionCount, positionOffset, length);
  return new RunLengthEncodedBlock(value.copyRegion(0, 1), length);
}

代码示例来源:origin: prestodb/presto

@Override
public Block copyPositions(int[] positions, int offset, int length)
{
  checkArrayRange(positions, offset, length);
  for (int i = offset; i < offset + length; i++) {
    checkValidPosition(positions[i], positionCount);
  }
  return new RunLengthEncodedBlock(value.copyRegion(0, 1), length);
}

代码示例来源:origin: prestodb/presto

@Override
public Block getSingleValueBlock(int position)
{
  checkReadablePosition(position);
  int startValueOffset = getOffset(position);
  int endValueOffset = getOffset(position + 1);
  int valueLength = endValueOffset - startValueOffset;
  Block newKeys = getRawKeyBlock().copyRegion(startValueOffset, valueLength);
  Block newValues = getRawValueBlock().copyRegion(startValueOffset, valueLength);
  int[] newHashTable = Arrays.copyOfRange(getHashTables(), startValueOffset * HASH_MULTIPLIER, endValueOffset * HASH_MULTIPLIER);
  return createMapBlockInternal(
      0,
      1,
      Optional.of(new boolean[] {isNull(position)}),
      new int[] {0, valueLength},
      newKeys,
      newValues,
      newHashTable,
      keyType,
      keyBlockNativeEquals,
      keyNativeHashCode);
}

代码示例来源:origin: prestodb/presto

public void compact()
{
  if (getRetainedSizeInBytes() <= getSizeInBytes()) {
    return;
  }
  for (int i = 0; i < blocks.length; i++) {
    Block block = blocks[i];
    if (block instanceof DictionaryBlock) {
      continue;
    }
    // Compact the block
    blocks[i] = block.copyRegion(0, block.getPositionCount());
  }
  Map<DictionaryId, DictionaryBlockIndexes> dictionaryBlocks = getRelatedDictionaryBlocks();
  for (DictionaryBlockIndexes blockIndexes : dictionaryBlocks.values()) {
    List<DictionaryBlock> compactBlocks = compactRelatedBlocks(blockIndexes.getBlocks());
    List<Integer> indexes = blockIndexes.getIndexes();
    for (int i = 0; i < compactBlocks.size(); i++) {
      blocks[indexes.get(i)] = compactBlocks.get(i);
    }
  }
  updateRetainedSize();
}

代码示例来源:origin: prestodb/presto

protected static void assertCompact(Block block)
{
  assertSame(block.copyRegion(0, block.getPositionCount()), block);
}

代码示例来源:origin: prestodb/presto

protected static void assertNotCompact(Block block)
{
  assertNotSame(block.copyRegion(0, block.getPositionCount()), block);
}

代码示例来源:origin: prestodb/presto

protected static void testCopyRegionCompactness(Block block)
{
  assertCompact(block.copyRegion(0, block.getPositionCount()));
  if (block.getPositionCount() > 0) {
    assertCompact(block.copyRegion(0, block.getPositionCount() - 1));
    assertCompact(block.copyRegion(1, block.getPositionCount() - 1));
  }
}

代码示例来源:origin: prestodb/presto

@Override
public Block getSingleValueBlock(int position)
{
  checkReadablePosition(position);
  int startValueOffset = getOffset(position);
  int valueLength = getOffset(position + 1) - startValueOffset;
  Block newValues = getRawElementBlock().copyRegion(startValueOffset, valueLength);
  return createArrayBlockInternal(
      0,
      1,
      new boolean[] {isNull(position)},
      new int[] {0, valueLength},
      newValues);
}

代码示例来源:origin: prestodb/presto

@Override
public Block getSingleValueBlock(int position)
{
  checkReadablePosition(position);
  int startFieldBlockOffset = getFieldBlockOffset(position);
  int endFieldBlockOffset = getFieldBlockOffset(position + 1);
  int fieldBlockLength = endFieldBlockOffset - startFieldBlockOffset;
  Block[] newBlocks = new Block[numFields];
  for (int i = 0; i < numFields; i++) {
    newBlocks[i] = getRawFieldBlocks()[i].copyRegion(startFieldBlockOffset, fieldBlockLength);
  }
  boolean[] newRowIsNull = new boolean[] {isNull(position)};
  int[] newOffsets = new int[] {0, fieldBlockLength};
  return createRowBlockInternal(0, 1, newRowIsNull, newOffsets, newBlocks);
}

代码示例来源:origin: prestodb/presto

public void compact()
{
  if (eagerCompact) {
    return;
  }
  for (int channel = 0; channel < types.size(); channel++) {
    ObjectArrayList<Block> blocks = channels[channel];
    for (int i = nextBlockToCompact; i < blocks.size(); i++) {
      Block block = blocks.get(i);
      // Copy the block to compact its size
      Block compactedBlock = block.copyRegion(0, block.getPositionCount());
      blocks.set(i, compactedBlock);
      pagesMemorySize -= block.getRetainedSizeInBytes();
      pagesMemorySize += compactedBlock.getRetainedSizeInBytes();
    }
  }
  nextBlockToCompact = channels[0].size();
  estimatedSize = calculateEstimatedSize();
}

代码示例来源:origin: prestodb/presto

@Test
public void testCopyRegion()
{
  Slice[] expectedValues = createExpectedValues(100);
  Block block = createBlockBuilderWithValues(expectedValues).build();
  Block actual = block.copyRegion(10, 10);
  Block expected = createBlockBuilderWithValues(copyOfRange(expectedValues, 10, 20)).build();
  assertEquals(actual.getPositionCount(), expected.getPositionCount());
  assertEquals(actual.getSizeInBytes(), expected.getSizeInBytes());
}

代码示例来源:origin: prestodb/presto

@Override
public Block copyRegion(int position, int length)
{
  int positionCount = getPositionCount();
  checkValidRegion(positionCount, position, length);
  int startValueOffset = getOffset(position);
  int endValueOffset = getOffset(position + length);
  Block newKeys = getRawKeyBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset);
  Block newValues = getRawValueBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset);
  int[] newOffsets = compactOffsets(getOffsets(), position + getOffsetBase(), length);
  boolean[] mapIsNull = getMapIsNull();
  boolean[] newMapIsNull = mapIsNull == null ? null : compactArray(mapIsNull, position + getOffsetBase(), length);
  int[] newHashTable = compactArray(getHashTables(), startValueOffset * HASH_MULTIPLIER, (endValueOffset - startValueOffset) * HASH_MULTIPLIER);
  if (newKeys == getRawKeyBlock() && newValues == getRawValueBlock() && newOffsets == getOffsets() && newMapIsNull == mapIsNull && newHashTable == getHashTables()) {
    return this;
  }
  return createMapBlockInternal(
      0,
      length,
      Optional.ofNullable(newMapIsNull),
      newOffsets,
      newKeys,
      newValues,
      newHashTable,
      keyType,
      keyBlockNativeEquals,
      keyNativeHashCode);
}

代码示例来源:origin: prestodb/presto

public void addPage(Page page)
{
  // ignore empty pages
  if (page.getPositionCount() == 0) {
    return;
  }
  positionCount += page.getPositionCount();
  int pageIndex = (channels.length > 0) ? channels[0].size() : 0;
  for (int i = 0; i < channels.length; i++) {
    Block block = page.getBlock(i);
    if (eagerCompact) {
      block = block.copyRegion(0, block.getPositionCount());
    }
    channels[i].add(block);
    pagesMemorySize += block.getRetainedSizeInBytes();
  }
  for (int position = 0; position < page.getPositionCount(); position++) {
    long sliceAddress = encodeSyntheticAddress(pageIndex, position);
    valueAddresses.add(sliceAddress);
  }
  estimatedSize = calculateEstimatedSize();
}

代码示例来源:origin: prestodb/presto

@Override
public Block copyRegion(int position, int length)
{
  int positionCount = getPositionCount();
  checkValidRegion(positionCount, position, length);
  int startValueOffset = getOffset(position);
  int endValueOffset = getOffset(position + length);
  Block newValues = getRawElementBlock().copyRegion(startValueOffset, endValueOffset - startValueOffset);
  int[] newOffsets = compactOffsets(getOffsets(), position + getOffsetBase(), length);
  boolean[] valueIsNull = getValueIsNull();
  boolean[] newValueIsNull = valueIsNull == null ? null : compactArray(valueIsNull, position + getOffsetBase(), length);
  if (newValues == getRawElementBlock() && newOffsets == getOffsets() && newValueIsNull == valueIsNull) {
    return this;
  }
  return createArrayBlockInternal(0, length, newValueIsNull, newOffsets, newValues);
}

代码示例来源:origin: prestodb/presto

@Override
public Block copyRegion(int position, int length)
{
  int positionCount = getPositionCount();
  checkValidRegion(positionCount, position, length);
  int startFieldBlockOffset = getFieldBlockOffset(position);
  int endFieldBlockOffset = getFieldBlockOffset(position + length);
  int fieldBlockLength = endFieldBlockOffset - startFieldBlockOffset;
  Block[] newBlocks = new Block[numFields];
  for (int i = 0; i < numFields; i++) {
    newBlocks[i] = getRawFieldBlocks()[i].copyRegion(startFieldBlockOffset, fieldBlockLength);
  }
  int[] newOffsets = compactOffsets(getFieldBlockOffsets(), position + getOffsetBase(), length);
  boolean[] rowIsNull = getRowIsNull();
  boolean[] newRowIsNull = rowIsNull == null ? null : compactArray(rowIsNull, position + getOffsetBase(), length);
  if (arraySame(newBlocks, getRawFieldBlocks()) && newOffsets == getFieldBlockOffsets() && newRowIsNull == rowIsNull) {
    return this;
  }
  return createRowBlockInternal(0, length, newRowIsNull, newOffsets, newBlocks);
}

代码示例来源: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-hive

private static Slice blockToSlice(Block block)
{
  // This function is strictly for testing use only
  SliceOutput sliceOutput = new DynamicSliceOutput(1000);
  BlockSerdeUtil.writeBlock(sliceOutput, block.copyRegion(0, block.getPositionCount()));
  return sliceOutput.slice();
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-hive

private static Slice blockToSlice(Block block)
{
  // This function is strictly for testing use only
  SliceOutput sliceOutput = new DynamicSliceOutput(1000);
  BlockSerdeUtil.writeBlock(sliceOutput, block.copyRegion(0, block.getPositionCount()));
  return sliceOutput.slice();
}

相关文章