private Object getLiteralValue()

in paimon-presto-0.236/src/main/java/org/apache/paimon/presto/PrestoFilterConverter.java [189:262]


    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 TimeType) {
            return (int) ((long) prestoNativeValue / 1_000);
        }

        if (type instanceof TimestampType) {
            return Timestamp.fromLocalDateTime(
                    Instant.ofEpochMilli((Long) prestoNativeValue)
                            .atZone(ZoneId.systemDefault())
                            .toLocalDateTime());
        }

        if (type instanceof TimestampWithTimeZoneType) {
            if (prestoNativeValue instanceof Long) {
                return prestoNativeValue;
            }
            return Timestamp.fromEpochMillis(
                    ((SqlTimestampWithTimeZone) prestoNativeValue).getMillisUtc());
        }

        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) {
            // Refer to trino.
            DecimalType decimalType = (DecimalType) type;
            BigDecimal bigDecimal;
            if (prestoNativeValue instanceof Long) {
                bigDecimal =
                        BigDecimal.valueOf((long) prestoNativeValue)
                                .movePointLeft(decimalType.getScale());
            } else {
                bigDecimal =
                        new BigDecimal(
                                Decimals.decodeUnscaledValue((Slice) prestoNativeValue),
                                decimalType.getScale());
            }
            return Decimal.fromBigDecimal(
                    bigDecimal, decimalType.getPrecision(), decimalType.getScale());
        }

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