in api/src/main/java/org/apache/iceberg/types/Conversions.java [130:183]
private static Object internalFromByteBuffer(Type type, ByteBuffer buffer) {
if (buffer == null) {
return null;
}
ByteBuffer tmp = buffer.duplicate();
if (type == Types.UUIDType.get() || type instanceof Types.DecimalType) {
tmp.order(ByteOrder.BIG_ENDIAN);
} else {
tmp.order(ByteOrder.LITTLE_ENDIAN);
}
switch (type.typeId()) {
case BOOLEAN:
return tmp.get() != 0x00;
case INTEGER:
case DATE:
return tmp.getInt();
case LONG:
case TIME:
case TIMESTAMP:
case TIMESTAMP_NANO:
if (tmp.remaining() < 8) {
// type was later promoted to long
return (long) tmp.getInt();
}
return tmp.getLong();
case FLOAT:
return tmp.getFloat();
case DOUBLE:
if (tmp.remaining() < 8) {
// type was later promoted to long
return (double) tmp.getFloat();
}
return tmp.getDouble();
case STRING:
try {
return DECODER.get().decode(tmp);
} catch (CharacterCodingException e) {
throw new RuntimeIOException(e, "Failed to decode value as UTF-8: %s", buffer);
}
case UUID:
return UUIDUtil.convert(tmp);
case FIXED:
case BINARY:
return tmp;
case DECIMAL:
Types.DecimalType decimal = (Types.DecimalType) type;
byte[] unscaledBytes = new byte[buffer.remaining()];
tmp.get(unscaledBytes);
return new BigDecimal(new BigInteger(unscaledBytes), decimal.scale());
default:
throw new UnsupportedOperationException("Cannot deserialize type: " + type);
}
}