{"record":{"id":"5e90aaa128abd4a5","repo":"prestodb/presto","slug":"invalid-cast-argument-5e90aa","errorCode":"INVALID_CAST_ARGUMENT","errorMessage":"Cannot cast '%s' to BIGINT","messagePattern":"Cannot cast '(.+?)' to BIGINT","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/DecimalCasts.java","lineNumber":232,"sourceCode":"\n    @UsedByGeneratedCode\n    public static long shortDecimalToBigint(long decimal, long precision, long scale, long tenToScale)\n    {\n        // this rounds the decimal value to the nearest integral value\n        if (decimal >= 0) {\n            return (decimal + tenToScale / 2) / tenToScale;\n        }\n        return -((-decimal + tenToScale / 2) / tenToScale);\n    }\n\n    @UsedByGeneratedCode\n    public static long longDecimalToBigint(Slice decimal, long precision, long scale, BigInteger tenToScale)\n    {\n        try {\n            return unscaledDecimalToUnscaledLong(rescale(decimal, intScale(-scale)));\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, format(\"Cannot cast '%s' to BIGINT\", Decimals.toString(decimal, intScale(scale))));\n        }\n    }\n\n    @UsedByGeneratedCode\n    public static long bigintToShortDecimal(long value, long precision, long scale, long tenToScale)\n    {\n        try {\n            long decimal = multiplyExact(value, tenToScale);\n            if (overflows(decimal, intScale(precision))) {\n                throw new PrestoException(INVALID_CAST_ARGUMENT, format(\"Cannot cast BIGINT '%s' to DECIMAL(%s, %s)\", value, precision, scale));\n            }\n            return decimal;\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(INVALID_CAST_ARGUMENT, format(\"Cannot cast BIGINT '%s' to DECIMAL(%s, %s)\", value, precision, scale));\n        }\n    }\n","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/DecimalCasts.java#L214-L250","documentation":"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.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/type/DecimalCasts.java:232 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}