presto-jdbc/src/main/java/io/prestosql/jdbc/ObjectCasts.java/ObjectCasts/castToBigDecimal
class ObjectCasts:    public static BigDecimal castToBigDecimal(Object x, int targetSqlType)
            throws SQLException
    {
        if (x instanceof Boolean) {
            return BigDecimal.valueOf(((Boolean) x) ? 1 : 0);
        }
        if (x instanceof BigInteger) {
            return new BigDecimal((BigInteger) x);
        }
        if (x instanceof BigDecimal) {
            return (BigDecimal) x;
        }
        try {
            if ((x instanceof Byte) || (x instanceof Short) || (x instanceof Integer) || (x instanceof Long)) {
                return BigDecimal.valueOf(((Number) x).longValue());
            }
            if ((x instanceof Float) || (x instanceof Double)) {
                return BigDecimal.valueOf(((Number) x).doubleValue());
            }
            if (x instanceof String) {
                return new BigDecimal((String) x);
            }
        }
        catch (RuntimeException e) {
            throw invalidConversion(x, targetSqlType, e);
        }
        throw invalidConversion(x, targetSqlType);
    }