private static void assertBlockEquals(Type type, Block actual, Block expected) {
   for (int position = 0; position < actual.getPositionCount(); position++) {
     assertEquals(
         type.getObjectValue(SESSION, actual, position),
         type.getObjectValue(SESSION, expected, position));
   }
 }
Ejemplo n.º 2
0
  @Override
  public void writeBlock(SliceOutput sliceOutput, Block block) {
    int positionCount = block.getPositionCount();
    sliceOutput.appendInt(positionCount);

    encodeNullsAsBits(sliceOutput, block);

    for (int position = 0; position < positionCount; position++) {
      if (!block.isNull(position)) {
        sliceOutput.writeLong(block.getLong(position, 0));
      }
    }
  }
Ejemplo n.º 3
0
  public RunLengthEncodedBlock(Block value, int positionCount) {
    requireNonNull(value, "value is null");
    if (value.getPositionCount() != 1) {
      throw new IllegalArgumentException(
          format(
              "Expected value to contain a single position but has %s positions",
              value.getPositionCount()));
    }

    // value can not be a RunLengthEncodedBlock because this could cause stack overflow in some of
    // the methods
    if (value instanceof RunLengthEncodedBlock) {
      throw new IllegalArgumentException(
          format("Value can not be an instance of a %s", getClass().getName()));
    }

    if (positionCount < 0) {
      throw new IllegalArgumentException("positionCount is negative");
    }

    this.value = value;
    this.positionCount = positionCount;
  }
Ejemplo n.º 4
0
  @Override
  public int getEstimatedSize(Block block) {
    int positionCount = block.getPositionCount();

    // positionCount integer bytes
    int size = Integer.BYTES;

    // one byte null bits per eight elements and possibly last null bits
    size += positionCount / Byte.SIZE + 1;

    // non-null data values
    for (int position = 0; position < positionCount; position++) {
      if (!block.isNull(position)) {
        size += Long.BYTES;
      }
    }

    return size;
  }