in paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlFilterConverter.java [194:259]
private Object getLiteralValue(Type type, Object prestosqlNativeValue) {
requireNonNull(prestosqlNativeValue, "prestosqlNativeValue is null");
if (type instanceof BooleanType) {
return prestosqlNativeValue;
}
if (type instanceof IntegerType) {
return toIntExact((long) prestosqlNativeValue);
}
if (type instanceof BigintType) {
return prestosqlNativeValue;
}
if (type instanceof RealType) {
return intBitsToFloat(toIntExact((long) prestosqlNativeValue));
}
if (type instanceof DoubleType) {
return prestosqlNativeValue;
}
if (type instanceof DateType) {
return toIntExact(((Long) prestosqlNativeValue));
}
if (type instanceof TimeType) {
return toIntExact(((Long) prestosqlNativeValue));
}
if (type instanceof TimestampType) {
return Timestamp.fromEpochMillis((long) prestosqlNativeValue);
}
if (type instanceof TimestampWithTimeZoneType) {
return Timestamp.fromEpochMillis(unpackMillisUtc((Long) prestosqlNativeValue));
}
if (type instanceof VarcharType || type instanceof CharType) {
return BinaryString.fromBytes(((Slice) prestosqlNativeValue).getBytes());
}
if (type instanceof VarbinaryType) {
return ((Slice) prestosqlNativeValue).getBytes();
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
BigDecimal bigDecimal;
if (prestosqlNativeValue instanceof Long) {
bigDecimal =
BigDecimal.valueOf((long) prestosqlNativeValue)
.movePointLeft(decimalType.getScale());
} else {
bigDecimal =
new BigDecimal(
DecimalUtils.toBigInteger(prestosqlNativeValue),
decimalType.getScale());
}
return Decimal.fromBigDecimal(
bigDecimal, decimalType.getPrecision(), decimalType.getScale());
}
throw new UnsupportedOperationException("Unsupported type: " + type);
}