prestodb/presto · error · ParsingException

Type calculation is too large (stack overflow while parsing)

Error message

Type calculation is too large (stack overflow while parsing)

What it means

Catch of StackOverflowError in calculateLiteralValue: the recursive type-calculation grammar parser blew the call stack while parsing the calculation expression (typically a pathologically long or deeply nested expression). It is rethrown as a ParsingException telling the user the type calculation is too large.

Source

Thrown at presto-parser/src/main/java/com/facebook/presto/type/TypeCalculation.java:71

        {
            throw new ParsingException(message, e, line, charPositionInLine);
        }
    };

    private TypeCalculation() {}

    public static Long calculateLiteralValue(
            String calculation,
            Map<String, Long> inputs)
    {
        try {
            ParserRuleContext tree = parseTypeCalculation(calculation);
            CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs);
            BigInteger result = visitor.visit(tree);
            return result.longValueExact();
        }
        catch (StackOverflowError e) {
            throw new ParsingException("Type calculation is too large (stack overflow while parsing)");
        }
    }

    private static ParserRuleContext parseTypeCalculation(String calculation)
    {
        TypeCalculationLexer lexer = new TypeCalculationLexer(new CaseInsensitiveStream(new ANTLRInputStream(calculation)));
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        TypeCalculationParser parser = new TypeCalculationParser(tokenStream);

        lexer.removeErrorListeners();
        lexer.addErrorListener(ERROR_LISTENER);

        parser.removeErrorListeners();
        parser.addErrorListener(ERROR_LISTENER);

        ParserRuleContext tree;
        try {
            // first, try parsing with potentially faster SLL mode

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Simplify or shorten the type calculation expression in the type signature
  2. Reduce nesting/number of operators in the calculated type definition
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at presto-parser/src/main/java/com/facebook/presto/type/TypeCalculation.java:71 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/d8f281315217d7f9. Report an issue: GitHub.