public static void checkOverflow(BigInteger value) { if (overflows(value)) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("Value is out of range: %s", value.toString())); } }
@UsedByGeneratedCode public static long varcharToShortDecimal(Slice value, long precision, long scale, long tenToScale) { BigDecimal result; String stringValue = value.toString(UTF_8); try { result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP); } catch (NumberFormatException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale)); } if (overflows(result, precision)) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale)); } return result.unscaledValue().longValue(); }
@UsedByGeneratedCode public static Slice varcharToLongDecimal(Slice value, long precision, long scale, BigInteger tenToScale) { BigDecimal result; String stringValue = value.toString(UTF_8); try { result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP); } catch (NumberFormatException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale)); } if (overflows(result, precision)) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale)); } return encodeUnscaledValue(result.unscaledValue()); }
@UsedByGeneratedCode public static long smallintToShortDecimal(long value, long precision, long scale, long tenToScale) { try { long decimal = multiplyExact(value, tenToScale); if (overflows(decimal, intScale(precision))) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast SMALLINT '%s' to DECIMAL(%s, %s)", value, precision, scale)); } return decimal; } catch (ArithmeticException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast SMALLINT '%s' to DECIMAL(%s, %s)", value, precision, scale)); } }
@UsedByGeneratedCode public static long bigintToShortDecimal(long value, long precision, long scale, long tenToScale) { try { long decimal = multiplyExact(value, tenToScale); if (overflows(decimal, intScale(precision))) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast BIGINT '%s' to DECIMAL(%s, %s)", value, precision, scale)); } return decimal; } catch (ArithmeticException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast BIGINT '%s' to DECIMAL(%s, %s)", value, precision, scale)); } }
@UsedByGeneratedCode public static long integerToShortDecimal(long value, long precision, long scale, long tenToScale) { try { long decimal = multiplyExact(value, tenToScale); if (overflows(decimal, intScale(precision))) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast INTEGER '%s' to DECIMAL(%s, %s)", value, precision, scale)); } return decimal; } catch (ArithmeticException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast INTEGER '%s' to DECIMAL(%s, %s)", value, precision, scale)); } }
@UsedByGeneratedCode public static long tinyintToShortDecimal(long value, long precision, long scale, long tenToScale) { try { long decimal = multiplyExact(value, tenToScale); if (overflows(decimal, intScale(precision))) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast TINYINT '%s' to DECIMAL(%s, %s)", value, precision, scale)); } return decimal; } catch (ArithmeticException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast TINYINT '%s' to DECIMAL(%s, %s)", value, precision, scale)); } }
if (overflows(returnValue, (int) resultPrecision)) { throw throwCastException(value, sourcePrecision, sourceScale, resultPrecision, resultScale);
public static void checkOverflow(BigInteger value) { if (overflows(value)) { throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, format("Value is out of range: %s", value.toString())); } }