private Object read()

in api/src/main/java/org/apache/iceberg/variants/SerializedPrimitive.java [55:118]


  private Object read() {
    switch (type) {
      case NULL:
        return null;
      case BOOLEAN_TRUE:
        return true;
      case BOOLEAN_FALSE:
        return false;
      case INT8:
        return VariantUtil.readLittleEndianInt8(value, PRIMITIVE_OFFSET);
      case INT16:
        return VariantUtil.readLittleEndianInt16(value, PRIMITIVE_OFFSET);
      case INT32:
      case DATE:
        return VariantUtil.readLittleEndianInt32(value, PRIMITIVE_OFFSET);
      case INT64:
      case TIMESTAMPTZ:
      case TIMESTAMPNTZ:
      case TIME:
      case TIMESTAMPTZ_NANOS:
      case TIMESTAMPNTZ_NANOS:
        return VariantUtil.readLittleEndianInt64(value, PRIMITIVE_OFFSET);
      case FLOAT:
        return VariantUtil.readFloat(value, PRIMITIVE_OFFSET);
      case DOUBLE:
        return VariantUtil.readDouble(value, PRIMITIVE_OFFSET);
      case DECIMAL4:
        {
          int scale = VariantUtil.readByte(value, PRIMITIVE_OFFSET);
          int unscaled = VariantUtil.readLittleEndianInt32(value, PRIMITIVE_OFFSET + 1);
          return new BigDecimal(BigInteger.valueOf(unscaled), scale);
        }
      case DECIMAL8:
        {
          int scale = VariantUtil.readByte(value, PRIMITIVE_OFFSET);
          long unscaled = VariantUtil.readLittleEndianInt64(value, PRIMITIVE_OFFSET + 1);
          return new BigDecimal(BigInteger.valueOf(unscaled), scale);
        }
      case DECIMAL16:
        {
          int scale = VariantUtil.readByte(value, PRIMITIVE_OFFSET);
          byte[] unscaled = new byte[16];
          for (int i = 0; i < 16; i += 1) {
            unscaled[i] = (byte) VariantUtil.readByte(value, PRIMITIVE_OFFSET + 16 - i);
          }
          return new BigDecimal(new BigInteger(unscaled), scale);
        }
      case BINARY:
        {
          int size = VariantUtil.readLittleEndianInt32(value, PRIMITIVE_OFFSET);
          return VariantUtil.slice(value, PRIMITIVE_OFFSET + 4, size);
        }
      case STRING:
        {
          int size = VariantUtil.readLittleEndianInt32(value, PRIMITIVE_OFFSET);
          return VariantUtil.readString(value, PRIMITIVE_OFFSET + 4, size);
        }
      case UUID:
        return UUIDUtil.convert(
            VariantUtil.slice(value, PRIMITIVE_OFFSET, 16).order(ByteOrder.BIG_ENDIAN));
    }

    throw new UnsupportedOperationException("Unsupported primitive type: " + type);
  }