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

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

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

Block.getPositions介绍

[英]Create a new block from the current block by keeping the same elements only with respect to positions that starts at offset and has length of length. May return a view over the data in this block or may return a copy
[中]从当前块创建新块,方法是仅保留从偏移开始且长度为的位置的相同元素。可以返回此块中数据的视图,也可以返回副本

代码示例

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

/**
 * 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);
}

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

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;
}

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

@Override
public Block getPositions(int[] positions, int offset, int length)
{
  assureLoaded();
  return block.getPositions(positions, offset, length);
}

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

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);
}

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

@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;
  }
}

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

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"));
    }
  }
}

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

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));
}

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

@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));
  }
}

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

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");

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

adaptedBlocks[i] = block.getPositions(rowsToKeep.elements(), 0, rowsToKeep.size());

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

Block probeBlock = probe.getPage().getBlock(probeOutputChannels[i]);
if (!isSequentialProbeIndices || length == 0) {
  blocks[i] = probeBlock.getPositions(probeIndices, 0, probeIndices.length);

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

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);

代码示例来源:origin: com.facebook.presto/presto-spi

/**
 * 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);
}

代码示例来源:origin: com.facebook.presto/presto-spi

@Override
public Block getPositions(int[] positions, int offset, int length)
{
  assureLoaded();
  return block.getPositions(positions, offset, length);
}

代码示例来源:origin: com.facebook.presto/presto-spi

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);
}

相关文章