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

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

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

Block.getPositionCount介绍

[英]Returns the number of positions in this block.
[中]返回此块中的位置数。

代码示例

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

private static boolean hasNull(Block keys)
{
  for (int position = 0; position < keys.getPositionCount(); position++) {
    if (keys.isNull(position)) {
      return true;
    }
  }
  return false;
}

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

@TypeParameter("E")
  @SqlType(StandardTypes.BIGINT)
  public static long arrayCardinality(@SqlType("array(E)") Block block)
  {
    return block.getPositionCount();
  }
}

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

@TypeParameter("K")
  @TypeParameter("V")
  @SqlType("array(K)")
  public static Block getKeys(
      @TypeParameter("K") Type keyType,
      @SqlType("map(K,V)") Block block)
  {
    BlockBuilder blockBuilder = keyType.createBlockBuilder(null, block.getPositionCount() / 2);
    for (int i = 0; i < block.getPositionCount(); i += 2) {
      keyType.appendTo(block, i, blockBuilder);
    }
    return blockBuilder.build();
  }
}

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

public static Block getKeys(Type keyType, Block block)
  {
    BlockBuilder blockBuilder = keyType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() / 2);
    for (int i = 0; i < block.getPositionCount(); i += 2) {
      keyType.appendTo(block, i, blockBuilder);
    }
    return blockBuilder.build();
  }
}

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

@TypeParameter("T")
@SqlType(StandardTypes.BIGINT)
public static long hash(
    @OperatorDependency(operator = HASH_CODE, returnType = StandardTypes.BIGINT, argumentTypes = {"T"}) MethodHandle hashFunction,
    @TypeParameter("T") Type type,
    @SqlType("array(T)") Block block)
{
  try {
    long hash = 0;
    for (int i = 0; i < block.getPositionCount(); i++) {
      hash = CombineHashFunction.getHash(hash, block.isNull(i) ? NULL_HASH_CODE : (long) hashFunction.invoke(readNativeValue(type, block, i)));
    }
    return hash;
  }
  catch (Throwable t) {
    throw internalError(t);
  }
}

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

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, long value)
{
  BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
  for (int i = 0; i < block.getPositionCount(); i++) {
    elementType.appendTo(block, i, blockBuilder);
  }
  elementType.writeLong(blockBuilder, value);
  return blockBuilder.build();
}

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

@Override
  public Block apply(Block block)
  {
    BlockBuilder blockBuilder = toType.createBlockBuilder(null, block.getPositionCount());
    for (int i = 0; i < block.getPositionCount(); i++) {
      if (block.isNull(i)) {
        blockBuilder.appendNull();
        continue;
      }
      toType.writeLong(blockBuilder, fromType.getLong(block, i));
    }
    return blockBuilder.build();
  }
}

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

@Override
  public GroupByIdBlock getResult()
  {
    checkState(lastPosition == block.getPositionCount(), "process has not yet finished");
    checkState(!finished, "result has produced");
    finished = true;
    return new GroupByIdBlock(nextGroupId, blockBuilder.build());
  }
}

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

@SqlType("array(bigint)")
public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlType("array(bigint)") Block rightArray)
{
  int leftArrayCount = leftArray.getPositionCount();
  int rightArrayCount = rightArray.getPositionCount();
  LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
  BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(null, leftArrayCount + rightArrayCount);
  AtomicBoolean containsNull = new AtomicBoolean(false);
  appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
  appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
  return distinctElementBlockBuilder.build();
}

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

public Block serialize()
{
  Block keys = keyBlockBuilder.build();
  Block values = valueBlockBuilder.build();
  BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueType), new BlockBuilderStatus(), keys.getPositionCount() * 2);
  for (int i = 0; i < keys.getPositionCount(); i++) {
    keyType.appendTo(keys, i, blockBuilder);
    valueType.appendTo(values, i, blockBuilder);
  }
  return blockBuilder.build();
}

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

public static Block createMap(MapType mapType, Block keyBlock, Block valueBlock)
  {
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(mapType.getTypeParameters(), new BlockBuilderStatus(), keyBlock.getPositionCount() * 2);

    checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
    for (int i = 0; i < keyBlock.getPositionCount(); i++) {
      if (keyBlock.isNull(i)) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
      }
      mapType.getKeyType().appendTo(keyBlock, i, blockBuilder);
      mapType.getValueType().appendTo(valueBlock, i, blockBuilder);
    }

    return blockBuilder.build();
  }
}

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

@Override
  public void deserialize(Block block, int index, ArrayAggregationState state)
  {
    Block stateBlock = (Block) arrayType.getObject(block, index);
    int positionCount = stateBlock.getPositionCount();
    BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
    for (int i = 0; i < positionCount; i++) {
      stateBlock.writePositionTo(i, blockBuilder);
      blockBuilder.closeEntry();
    }
    state.setBlockBuilder(blockBuilder);
  }
}

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

public static Block getValues(Type valueType, Block block)
  {
    BlockBuilder blockBuilder = valueType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() / 2);
    for (int i = 0; i < block.getPositionCount(); i += 2) {
      valueType.appendTo(block, i + 1, blockBuilder);
    }
    return blockBuilder.build();
  }
}

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

@TypeParameter("T")
@SqlType(StandardTypes.BOOLEAN)
public static boolean greaterThan(
    @OperatorDependency(operator = GREATER_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle greaterThanFunction,
    @TypeParameter("T") Type type,
    @SqlType("array(T)") Block leftArray,
    @SqlType("array(T)") Block rightArray)
{
  int len = Math.min(leftArray.getPositionCount(), rightArray.getPositionCount());
  int index = 0;
  while (index < len) {
    checkElementNotNull(leftArray.isNull(index), ARRAY_NULL_ELEMENT_MSG);
    checkElementNotNull(rightArray.isNull(index), ARRAY_NULL_ELEMENT_MSG);
    Object leftElement = readNativeValue(type, leftArray, index);
    Object rightElement = readNativeValue(type, rightArray, index);
    try {
      if ((boolean) greaterThanFunction.invoke(leftElement, rightElement)) {
        return true;
      }
      if ((boolean) greaterThanFunction.invoke(rightElement, leftElement)) {
        return false;
      }
    }
    catch (Throwable t) {
      throw internalError(t);
    }
    index++;
  }
  return leftArray.getPositionCount() > rightArray.getPositionCount();
}

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

@TypeParameter("K")
  @TypeParameter("V")
  @SqlType("array(V)")
  public static Block getValues(
      @TypeParameter("V") Type valueType,
      @SqlType("map(K,V)") Block block)
  {
    BlockBuilder blockBuilder = valueType.createBlockBuilder(null, block.getPositionCount() / 2);
    for (int i = 0; i < block.getPositionCount(); i += 2) {
      valueType.appendTo(block, i + 1, blockBuilder);
    }
    return blockBuilder.build();
  }
}

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

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Slice value)
{
  BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
  for (int i = 0; i < block.getPositionCount(); i++) {
    elementType.appendTo(block, i, blockBuilder);
  }
  elementType.writeSlice(blockBuilder, value);
  return blockBuilder.build();
}

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

@Override
public void addBlock(Type type, Block block)
{
  for (int position = 0; position < block.getPositionCount(); position++) {
    if (!block.isNull(position)) {
      rowCount++;
    }
  }
}

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

@Override
  public Block apply(Block block)
  {
    BlockBuilder blockBuilder = toType.createBlockBuilder(null, block.getPositionCount());
    for (int i = 0; i < block.getPositionCount(); i++) {
      if (block.isNull(i)) {
        blockBuilder.appendNull();
        continue;
      }
      toType.writeSlice(blockBuilder, utf8Slice(String.valueOf(fromType.getLong(block, i))));
    }
    return blockBuilder.build();
  }
}

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

@Override
  protected Object getGreaterValue(Object value)
  {
    Block block = (Block) value;
    BlockBuilder blockBuilder = SMALLINT.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
      SMALLINT.appendTo(block, i, blockBuilder);
    }
    SMALLINT.writeLong(blockBuilder, 1L);

    return blockBuilder.build();
  }
}

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

@ScalarFunction("values_at_quantiles")
@Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the qdigest is qn.")
@SqlType("array(real)")
public static Block valuesAtQuantilesReal(@SqlType("qdigest(real)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock)
{
  QuantileDigest digest = new QuantileDigest(input);
  BlockBuilder output = REAL.createBlockBuilder(null, percentilesArrayBlock.getPositionCount());
  for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) {
    REAL.writeLong(output, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i)))));
  }
  return output.build();
}

相关文章