in src/main/java/org/apache/paimon/trino/TrinoFilterConverter.java [250:327]
private Object getLiteralValue(Type type, Object trinoNativeValue) {
requireNonNull(trinoNativeValue, "trinoNativeValue is null");
if (type instanceof BooleanType) {
return trinoNativeValue;
}
if (type instanceof TinyintType) {
return ((Long) trinoNativeValue).byteValue();
}
if (type instanceof SmallintType) {
return ((Long) trinoNativeValue).shortValue();
}
if (type instanceof IntegerType) {
return toIntExact((long) trinoNativeValue);
}
if (type instanceof BigintType) {
return trinoNativeValue;
}
if (type instanceof RealType) {
return intBitsToFloat(toIntExact((long) trinoNativeValue));
}
if (type instanceof DoubleType) {
return trinoNativeValue;
}
if (type instanceof DateType) {
return toIntExact(((Long) trinoNativeValue));
}
if (type.equals(TIME_MILLIS)) {
return (int) ((long) trinoNativeValue / PICOSECONDS_PER_MILLISECOND);
}
if (type.equals(TIMESTAMP_MILLIS)) {
return Timestamp.fromEpochMillis((long) trinoNativeValue / 1000);
}
if (type.equals(TIMESTAMP_TZ_MILLIS)) {
if (trinoNativeValue instanceof Long) {
return trinoNativeValue;
}
return Timestamp.fromEpochMillis(
((LongTimestampWithTimeZone) trinoNativeValue).getEpochMillis());
}
if (type instanceof VarcharType || type instanceof CharType) {
return BinaryString.fromBytes(((Slice) trinoNativeValue).getBytes());
}
if (type instanceof VarbinaryType) {
return ((Slice) trinoNativeValue).getBytes();
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
BigDecimal bigDecimal;
if (trinoNativeValue instanceof Long) {
bigDecimal =
BigDecimal.valueOf((long) trinoNativeValue)
.movePointLeft(decimalType.getScale());
} else {
bigDecimal =
new BigDecimal(
DecimalUtils.toBigInteger(trinoNativeValue),
decimalType.getScale());
}
return Decimal.fromBigDecimal(
bigDecimal, decimalType.getPrecision(), decimalType.getScale());
}
throw new UnsupportedOperationException("Unsupported type: " + type);
}