in paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoFilterConverter.java [184:244]
private Object getLiteralValue(Type type, Object prestoNativeValue) {
Objects.requireNonNull(prestoNativeValue, "prestoNativeValue is null");
if (type instanceof BooleanType) {
return prestoNativeValue;
}
if (type instanceof IntegerType) {
return Math.toIntExact((long) prestoNativeValue);
}
if (type instanceof BigintType) {
return prestoNativeValue;
}
if (type instanceof RealType) {
return Float.intBitsToFloat(Math.toIntExact((long) prestoNativeValue));
}
if (type instanceof DoubleType) {
return prestoNativeValue;
}
if (type instanceof DateType) {
return Math.toIntExact(((Long) prestoNativeValue));
}
if (type instanceof TimestampType || type instanceof TimeType) {
return TimeUnit.MILLISECONDS.toMicros((Long) prestoNativeValue);
}
if (type instanceof VarcharType || type instanceof CharType) {
return BinaryString.fromBytes(((Slice) prestoNativeValue).getBytes());
}
if (type instanceof VarbinaryType) {
return ((Slice) prestoNativeValue).getBytes();
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
Object value =
Objects.requireNonNull(
prestoNativeValue, "The prestoNativeValue must be non-null");
if (Decimals.isShortDecimal(decimalType)) {
Preconditions.checkArgument(
value instanceof Long,
"A short decimal should be represented by a Long value but was %s",
value.getClass().getName());
return BigDecimal.valueOf((long) value).movePointLeft(decimalType.getScale());
}
Preconditions.checkArgument(
value instanceof Slice,
"A long decimal should be represented by a Slice value but was %s",
value.getClass().getName());
return new BigDecimal(
Decimals.decodeUnscaledValue((Slice) value), decimalType.getScale());
}
throw new UnsupportedOperationException("Unsupported type: " + type);
}