prestodb/presto · error · PrestoException
INVALID_CAST_ARGUMENT
INVALID_CAST_ARGUMENT
Error message
Cannot cast '%s' to BIGINT
What it means
Cast error from longDecimalToBigint: converting the unscaled decimal to a long overflows (unscaledDecimalToUnscaledLong threw), i.e. the decimal's integral magnitude exceeds BIGINT range even after rounding. The %s shows the original decimal text; the faulty input is the decimal value being cast to BIGINT.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalCasts.java:232
@UsedByGeneratedCode
public static long shortDecimalToBigint(long decimal, long precision, long scale, long tenToScale)
{
// this rounds the decimal value to the nearest integral value
if (decimal >= 0) {
return (decimal + tenToScale / 2) / tenToScale;
}
return -((-decimal + tenToScale / 2) / tenToScale);
}
@UsedByGeneratedCode
public static long longDecimalToBigint(Slice decimal, long precision, long scale, BigInteger tenToScale)
{
try {
return unscaledDecimalToUnscaledLong(rescale(decimal, intScale(-scale)));
}
catch (ArithmeticException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to BIGINT", Decimals.toString(decimal, intScale(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));
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Cast to DOUBLE with truncation tolerance instead if precision loss is acceptable
- Filter out out-of-range values before casting: WHERE d BETWEEN -9223372036854775808 AND 9223372036854775807
- Reduce the decimal's scale/precision upstream so it fits BIGINT
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalCasts.java:232 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/5e90aaa128abd4a5.
Report an issue: GitHub.