io.airlift.slice.Slice.length()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(161)

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

Slice.length介绍

[英]Length of this slice.
[中]这片的长度。

代码示例

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

@VisibleForTesting
  int getBufferCapacity()
  {
    return slice.length();
  }
}

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

@Override
public String toString()
{
  StringBuilder builder = new StringBuilder("OutputStreamSliceOutputAdapter{");
  builder.append("outputStream=").append(compressedOutputStream);
  builder.append("bufferSize=").append(slice.length());
  builder.append('}');
  return builder.toString();
}

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

private static int hashBytes(int initialValue, Slice bytes)
{
  int result = initialValue;
  for (int i = 0; i < bytes.length(); i++) {
    result = result * 31 + bytes.getByte(i);
  }
  return result;
}

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

private void ensureWritableBytes(int minWritableBytes)
{
  checkArgument(minWritableBytes <= MAX_UNUSED_BUFFER_SIZE);
  if (bufferPosition + minWritableBytes > slice.length()) {
    closeChunk();
  }
}

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

public static int compareChars(Slice left, Slice right)
{
  if (left.length() < right.length()) {
    return compareCharsShorterToLonger(left, right);
  }
  else {
    return -compareCharsShorterToLonger(right, left);
  }
}

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

@Override
public void writeSlice(BlockBuilder blockBuilder, Slice value)
{
  writeSlice(blockBuilder, value, 0, value.length());
}

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

private void ensureWritableBytes(int minWritableBytes)
{
  checkArgument(minWritableBytes <= MAX_UNUSED_BUFFER_SIZE);
  if (bufferPosition + minWritableBytes > slice.length()) {
    closeChunk();
  }
}

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

private static int getSize(NullableValue nullableValue)
{
  if (nullableValue.isNull()) {
    return 0;
  }
  Object value = nullableValue.getValue();
  checkArgument(value instanceof Slice, "value is expected to be of Slice type");
  return ((Slice) value).length();
}

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

private Slice dropStringMinMaxIfNecessary(Slice minOrMax)
  {
    if (minOrMax == null || minOrMax.length() > stringStatisticsLimitInBytes) {
      return null;
    }

    // Do not hold the entire slice where the actual stats could be small
    if (minOrMax.isCompact()) {
      return minOrMax;
    }
    return Slices.copyOf(minOrMax);
  }
}

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

@Description("decode bigint value from a 32-bit 2's complement big endian varbinary")
@ScalarFunction("from_big_endian_32")
@SqlType(StandardTypes.INTEGER)
public static long fromBigEndian32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
  if (slice.length() != Integer.BYTES) {
    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "expected 4-byte input, but got instead: " + slice.length());
  }
  return Integer.reverseBytes(slice.getInt(0));
}

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

/**
 * Does the file start with the ORC magic bytes?
 */
private static boolean isValidHeaderMagic(OrcDataSource source)
    throws IOException
{
  byte[] headerMagic = new byte[MAGIC.length()];
  source.readFully(0, headerMagic);
  return MAGIC.equals(Slices.wrappedBuffer(headerMagic));
}

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

private static Slice decompressSnappy(Slice input, int uncompressedSize)
{
  byte[] buffer = new byte[uncompressedSize];
  decompress(new SnappyDecompressor(), input, 0, input.length(), buffer, 0);
  return wrappedBuffer(buffer);
}

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

@Test
public void testMinAverageValueBytes()
{
  assertMinAverageValueBytes(0L, ImmutableList.of());
  assertMinAverageValueBytes(BINARY_VALUE_BYTES_OVERHEAD, ImmutableList.of(EMPTY_SLICE));
  assertMinAverageValueBytes(FIRST_VALUE.length() + BINARY_VALUE_BYTES_OVERHEAD, ImmutableList.of(FIRST_VALUE));
  assertMinAverageValueBytes((FIRST_VALUE.length() + SECOND_VALUE.length()) / 2 + BINARY_VALUE_BYTES_OVERHEAD, ImmutableList.of(FIRST_VALUE, SECOND_VALUE));
}

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

@Test
public void testSum()
{
  StringStatisticsBuilder stringStatisticsBuilder = new StringStatisticsBuilder(Integer.MAX_VALUE);
  for (Slice value : ImmutableList.of(EMPTY_SLICE, LOW_BOTTOM_VALUE, LOW_TOP_VALUE)) {
    stringStatisticsBuilder.addValue(value);
  }
  assertStringStatistics(stringStatisticsBuilder.buildColumnStatistics(), 3, EMPTY_SLICE.length() + LOW_BOTTOM_VALUE.length() + LOW_TOP_VALUE.length());
}

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

@Test
public void testSum()
{
  BinaryStatisticsBuilder binaryStatisticsBuilder = new BinaryStatisticsBuilder();
  for (Slice value : ImmutableList.of(EMPTY_SLICE, FIRST_VALUE, SECOND_VALUE)) {
    binaryStatisticsBuilder.addValue(value);
  }
  assertBinaryStatistics(binaryStatisticsBuilder.buildColumnStatistics(), 3, EMPTY_SLICE.length() + FIRST_VALUE.length() + SECOND_VALUE.length());
}

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

@Description("length of the given binary")
@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long length(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
  return slice.length();
}

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

@Description("decode the 32-bit big-endian binary in IEEE 754 single-precision floating-point format")
@ScalarFunction("from_ieee754_32")
@SqlType(StandardTypes.REAL)
public static long fromIEEE754Binary32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
  checkCondition(slice.length() == Integer.BYTES, INVALID_FUNCTION_ARGUMENT, "Input floating-point value must be exactly 4 bytes long");
  return Integer.reverseBytes(slice.getInt(0));
}

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

private static Block createSingleValueBlock(Slice expectedValue)
{
  BlockBuilder blockBuilder = new VariableWidthBlockBuilder(null, 1, expectedValue.length());
  blockBuilder.writeBytes(expectedValue, 0, expectedValue.length()).closeEntry();
  return blockBuilder.build();
}

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

@Description("compute SpookyHashV2 32-bit hash")
@ScalarFunction
@SqlType(StandardTypes.VARBINARY)
public static Slice spookyHashV2_32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
  Slice hash = Slices.allocate(Integer.BYTES);
  hash.setInt(0, Integer.reverseBytes(SpookyHashV2.hash32(slice, 0, slice.length(), 0)));
  return hash;
}

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

@Description("compute SpookyHashV2 64-bit hash")
@ScalarFunction
@SqlType(StandardTypes.VARBINARY)
public static Slice spookyHashV2_64(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
  Slice hash = Slices.allocate(Long.BYTES);
  hash.setLong(0, Long.reverseBytes(SpookyHashV2.hash64(slice, 0, slice.length(), 0)));
  return hash;
}

相关文章