Пример #1
0
  private static boolean valueEquals(
      Type type, Slice leftSlice, int leftOffset, Slice rightSlice, int rightOffset) {
    // check if null flags are the same
    boolean leftIsNull = leftSlice.getByte(leftOffset) != 0;
    boolean rightIsNull = rightSlice.getByte(rightOffset) != 0;
    if (leftIsNull != rightIsNull) {
      return false;
    }

    // if values are both null, they are equal
    if (leftIsNull) {
      return true;
    }

    if (type == Type.FIXED_INT_64 || type == Type.DOUBLE) {
      long leftValue = leftSlice.getLong(leftOffset + SIZE_OF_BYTE);
      long rightValue = rightSlice.getLong(rightOffset + SIZE_OF_BYTE);
      return leftValue == rightValue;
    } else if (type == Type.BOOLEAN) {
      boolean leftValue = leftSlice.getByte(leftOffset + SIZE_OF_BYTE) != 0;
      boolean rightValue = rightSlice.getByte(rightOffset + SIZE_OF_BYTE) != 0;
      return leftValue == rightValue;
    } else if (type == Type.VARIABLE_BINARY) {
      int leftLength = getVariableBinaryLength(leftSlice, leftOffset);
      int rightLength = getVariableBinaryLength(rightSlice, rightOffset);
      return leftSlice.equals(
          leftOffset + SIZE_OF_BYTE + SIZE_OF_INT,
          leftLength,
          rightSlice,
          rightOffset + SIZE_OF_BYTE + SIZE_OF_INT,
          rightLength);
    } else {
      throw new IllegalArgumentException("Unsupported type " + type);
    }
  }
Пример #2
0
  private static int valueHashCode(Type type, Slice slice, int offset) {
    boolean isNull = slice.getByte(offset) != 0;
    if (isNull) {
      return 0;
    }

    if (type == Type.FIXED_INT_64) {
      return Longs.hashCode(slice.getLong(offset + SIZE_OF_BYTE));
    } else if (type == Type.DOUBLE) {
      long longValue = Double.doubleToLongBits(slice.getDouble(offset + SIZE_OF_BYTE));
      return Longs.hashCode(longValue);
    } else if (type == Type.BOOLEAN) {
      return slice.getByte(offset + SIZE_OF_BYTE) != 0 ? 1 : 0;
    } else if (type == Type.VARIABLE_BINARY) {
      int sliceLength = getVariableBinaryLength(slice, offset);
      return slice.hashCode(offset + SIZE_OF_BYTE + SIZE_OF_INT, sliceLength);
    } else {
      throw new IllegalArgumentException("Unsupported type " + type);
    }
  }
Пример #3
0
    public void appendTo(int position, BlockBuilder builder) {
      checkArgument(position >= 0 && position < positionOffsets.size());

      int offset = positionOffsets.getInt(position);

      if (slice.getByte(offset) != 0) {
        builder.appendNull();
      } else if (type == Type.FIXED_INT_64) {
        builder.append(slice.getLong(offset + SIZE_OF_BYTE));
      } else if (type == Type.DOUBLE) {
        builder.append(slice.getDouble(offset + SIZE_OF_BYTE));
      } else if (type == Type.BOOLEAN) {
        builder.append(slice.getByte(offset + SIZE_OF_BYTE) != 0);
      } else if (type == Type.VARIABLE_BINARY) {
        int sliceLength = getVariableBinaryLength(slice, offset);
        builder.append(slice.slice(offset + SIZE_OF_BYTE + SIZE_OF_INT, sliceLength));
      } else {
        throw new IllegalArgumentException("Unsupported type " + type);
      }
    }