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

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

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

Block.isNull介绍

[英]Is the specified position null?
[中]指定的位置是否为空?

代码示例

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

@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
  if (block.isNull(position)) {
    blockBuilder.appendNull();
  }
  else {
    block.writePositionTo(position, blockBuilder);
  }
}

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

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

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

@TypeParameter("E")
@SqlNullable
@SqlType("E")
public static Slice sliceElementAt(@TypeParameter("E") Type elementType, @SqlType("array(E)") Block array, @SqlType("bigint") long index)
{
  int position = checkedIndexToBlockPosition(array, index);
  if (position == -1) {
    return null;
  }
  if (array.isNull(position)) {
    return null;
  }
  return elementType.getSlice(array, position);
}

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

@SqlType(StandardTypes.BOOLEAN)
  public static boolean isDistinctFrom(
      @BlockPosition @SqlType(value = StandardTypes.DATE, nativeContainerType = long.class) Block left,
      @BlockIndex int leftPosition,
      @BlockPosition @SqlType(value = StandardTypes.DATE, nativeContainerType = long.class) Block right,
      @BlockIndex int rightPosition)
  {
    if (left.isNull(leftPosition) != right.isNull(rightPosition)) {
      return true;
    }
    if (left.isNull(leftPosition)) {
      return false;
    }
    return notEqual(DATE.getLong(left, leftPosition), DATE.getLong(right, rightPosition));
  }
}

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

@TypeParameter("T")
@SqlType(StandardTypes.BIGINT)
public static long arrayPosition(
    @TypeParameter("T") Type type,
    @OperatorDependency(operator = EQUAL, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle equalMethodHandle,
    @SqlType("array(T)") Block array,
    @SqlType("T") long element)
{
  int size = array.getPositionCount();
  for (int i = 0; i < size; i++) {
    if (!array.isNull(i)) {
      long arrayValue = type.getLong(array, i);
      try {
        Boolean result = (Boolean) equalMethodHandle.invokeExact(arrayValue, element);
        checkNotIndeterminate(result);
        if (result) {
          return i + 1; // result is 1-based (instead of 0)
        }
      }
      catch (Throwable t) {
        throw internalError(t);
      }
    }
  }
  return 0;
}

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

@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
  if (block.isNull(position)) {
    blockBuilder.appendNull();
  }
  else {
    block.writePositionTo(position, blockBuilder);
  }
}

代码示例来源: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.writeLong(blockBuilder, fromType.getLong(block, i));
    }
    return blockBuilder.build();
  }
}

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

@TypeParameter("E")
@SqlNullable
@SqlType("E")
public static Boolean booleanElementAt(@TypeParameter("E") Type elementType, @SqlType("array(E)") Block array, @SqlType("bigint") long index)
{
  int position = checkedIndexToBlockPosition(array, index);
  if (position == -1) {
    return null;
  }
  if (array.isNull(position)) {
    return null;
  }
  return elementType.getBoolean(array, position);
}

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

@SqlType(StandardTypes.BOOLEAN)
  public static boolean isDistinctFrom(
      @BlockPosition @SqlType(value = StandardTypes.BIGINT, nativeContainerType = long.class) Block left,
      @BlockIndex int leftPosition,
      @BlockPosition @SqlType(value = StandardTypes.BIGINT, nativeContainerType = long.class) Block right,
      @BlockIndex int rightPosition)
  {
    if (left.isNull(leftPosition) != right.isNull(rightPosition)) {
      return true;
    }
    if (left.isNull(leftPosition)) {
      return false;
    }
    return notEqual(BIGINT.getLong(left, leftPosition), BIGINT.getLong(right, rightPosition));
  }
}

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

@TypeParameter("T")
@SqlType(StandardTypes.BIGINT)
public static long arrayPosition(
    @TypeParameter("T") Type type,
    @OperatorDependency(operator = EQUAL, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle equalMethodHandle,
    @SqlType("array(T)") Block array,
    @SqlType("T") Slice element)
{
  int size = array.getPositionCount();
  for (int i = 0; i < size; i++) {
    if (!array.isNull(i)) {
      Slice arrayValue = type.getSlice(array, i);
      try {
        Boolean result = (Boolean) equalMethodHandle.invokeExact(arrayValue, element);
        checkNotIndeterminate(result);
        if (result) {
          return i + 1; // result is 1-based (instead of 0)
        }
      }
      catch (Throwable t) {
        throw internalError(t);
      }
    }
  }
  return 0;
}

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

@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
  if (block.isNull(position)) {
    blockBuilder.appendNull();
  }
  else {
    block.writePositionTo(position, blockBuilder);
  }
}

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

private static Double mapL2Norm(Block map)
  {
    double norm = 0.0;

    for (int i = 1; i < map.getPositionCount(); i += 2) {
      if (map.isNull(i)) {
        return null;
      }
      norm += DOUBLE.getDouble(map, i) * DOUBLE.getDouble(map, i);
    }

    return Math.sqrt(norm);
  }
}

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

private static Block copyBlockViaWritePositionTo(Block block, Supplier<BlockBuilder> newBlockBuilder)
{
  BlockBuilder blockBuilder = newBlockBuilder.get();
  for (int i = 0; i < block.getPositionCount(); i++) {
    if (block.isNull(i)) {
      blockBuilder.appendNull();
    }
    else {
      block.writePositionTo(i, blockBuilder);
    }
  }
  return blockBuilder.build();
}

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

@TypeParameter("E")
@SqlNullable
@SqlType("E")
public static Long longElementAt(@TypeParameter("E") Type elementType, @SqlType("array(E)") Block array, @SqlType("bigint") long index)
{
  int position = checkedIndexToBlockPosition(array, index);
  if (position == -1) {
    return null;
  }
  if (array.isNull(position)) {
    return null;
  }
  return elementType.getLong(array, position);
}

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

@SqlType(StandardTypes.BOOLEAN)
  public static boolean isDistinctFrom(
      @BlockPosition @SqlType(value = StandardTypes.TIME_WITH_TIME_ZONE, nativeContainerType = long.class) Block left,
      @BlockIndex int leftPosition,
      @BlockPosition @SqlType(value = StandardTypes.TIME_WITH_TIME_ZONE, nativeContainerType = long.class) Block right,
      @BlockIndex int rightPosition)
  {
    if (left.isNull(leftPosition) && right.isNull(rightPosition)) {
      return false;
    }
    if (left.isNull(leftPosition)) {
      return false;
    }
    return notEqual(TIME_WITH_TIME_ZONE.getLong(left, leftPosition), TIME_WITH_TIME_ZONE.getLong(right, rightPosition));
  }
}

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

@TypeParameter("T")
@SqlType(StandardTypes.BIGINT)
public static long arrayPosition(
    @TypeParameter("T") Type type,
    @OperatorDependency(operator = EQUAL, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T", "T"}) MethodHandle equalMethodHandle,
    @SqlType("array(T)") Block array,
    @SqlType("T") boolean element)
{
  int size = array.getPositionCount();
  for (int i = 0; i < size; i++) {
    if (!array.isNull(i)) {
      boolean arrayValue = type.getBoolean(array, i);
      try {
        Boolean result = (Boolean) equalMethodHandle.invokeExact(arrayValue, element);
        checkNotIndeterminate(result);
        if (result) {
          return i + 1; // result is 1-based (instead of 0)
        }
      }
      catch (Throwable t) {
        throw internalError(t);
      }
    }
  }
  return 0;
}

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

@Override
public void appendTo(Block block, int position, BlockBuilder blockBuilder)
{
  if (block.isNull(position)) {
    blockBuilder.appendNull();
  }
  else {
    block.writeBytesTo(position, 0, block.getSliceLength(position), blockBuilder);
    blockBuilder.closeEntry();
  }
}

相关文章