apache/shardingsphere · error · SQLParsingException

42000

42000

Error message

Expected integer ID, got: %s

What it means

Thrown by DorisDALStatementVisitor.parseIntegerToken when a SHOW DATABASES/SHOW TABLES-style statement in Doris carries a NUMBER_ token whose text is not all digits (e.g. a negative sign, decimal point, or a token like '1e3'). The visitor needs a long statement ID/limit, so any non-pure-digit text is rejected with 'Expected integer ID, got: <text>' plus the token text and line.

Source

Thrown at parser/sql/engine/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/engine/doris/visitor/statement/type/DorisDALStatementVisitor.java:781

        MySQLShowDatabasesStatement result = new MySQLShowDatabasesStatement(getDatabaseType(), filter, catalogName);
        result.addParameterMarkers(getParameterMarkerSegments());
        return result;
    }
    
    @Override
    public ASTNode visitShowDatabase(final ShowDatabaseContext ctx) {
        return new DorisShowDatabaseStatement(getDatabaseType(), parseIntegerToken(ctx.NUMBER_()));
    }
    
    @Override
    public ASTNode visitShowTable(final ShowTableContext ctx) {
        return new DorisShowTableStatement(getDatabaseType(), parseIntegerToken(ctx.NUMBER_()));
    }
    
    private long parseIntegerToken(final TerminalNode token) {
        String text = token.getText();
        if (!text.chars().allMatch(Character::isDigit)) {
            throw new SQLParsingException(String.format("Expected integer ID, got: %s", text), text, token.getSymbol().getLine());
        }
        return Long.parseLong(text);
    }
    
    @Override
    public ASTNode visitShowEvents(final ShowEventsContext ctx) {
        MySQLShowEventsStatement result = new MySQLShowEventsStatement(getDatabaseType(),
                null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()), null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()));
        result.addParameterMarkers(getParameterMarkerSegments());
        return result;
    }
    
    @Override
    public ASTNode visitShowTables(final ShowTablesContext ctx) {
        MySQLShowTablesStatement result = new MySQLShowTablesStatement(getDatabaseType(), null == ctx.fromDatabase() ? null : (FromDatabaseSegment) visit(ctx.fromDatabase()),
                null == ctx.showFilter() ? null : (ShowFilterSegment) visit(ctx.showFilter()), null != ctx.FULL());
        result.addParameterMarkers(getParameterMarkerSegments());
        return result;

View on GitHub (pinned to e952770a21)

Solutions

  1. Use a plain non-negative integer literal in the statement (no sign, decimal point, or exponent)
  2. If the value comes from user input, validate it is an unsigned decimal integer string before building the SQL
  3. Quote/bind the value through your own formatting so only digits reach the statement

Example fix

// before
String sql = "SHOW DATABASES -1"; // sign not allowed

// after
String sql = "SHOW DATABASES 1";
Defensive patterns

Strategy: validation

Validate before calling

// Validate unsigned integer before building Doris SHOW statement
static String buildShowDb(long id) {
    if (id < 0) throw new IllegalArgumentException("id must be non-negative");
    return "SHOW DATABASES " + id;
}

Try / catch

try { visitorEngine.parse(sql); } catch (SQLParsingException e) { return reject("SHOW ID must be an unsigned integer"); }

Prevention

When it happens

Trigger: Doris 'SHOW DATABASES <n>' / 'SHOW TABLE <n>' grammar where the NUMBER_ token matched something like '-1', '+5', '3.14', or a scientific-notation literal; parseIntegerToken's Character::isDigit check fails on the sign or dot, throwing before Long.parseLong.

Common situations: Statements ported from MySQL with a database ID literal; users writing 'SHOW DATABASES 1.0' or passing computed numeric strings; grammar changes where NUMBER_ starts matching previously-lexed tokens.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/7b14f747a7b9b690. Report an issue: GitHub.