{"record":{"id":"67371bd1548cfc60","repo":"apache/shardingsphere","slug":"42000-67371b","errorCode":"42000","errorMessage":"You have an error in your SQL syntax: %s","messagePattern":"You have an error in your SQL syntax: (.+?)","errorType":"exception","errorClass":"SQLParsingException","httpStatus":null,"severity":"error","filePath":"parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/parser/SQLParserExecutor.java","lineNumber":51,"sourceCode":"/**\n * SQL parser executor.\n */\n@RequiredArgsConstructor\npublic final class SQLParserExecutor {\n    \n    private final DatabaseType databaseType;\n    \n    /**\n     * Parse SQL.\n     *\n     * @param sql SQL to be parsed\n     * @return parse AST node\n     * @throws SQLParsingException SQL parsing exception\n     */\n    public ParseASTNode parse(final String sql) {\n        ParseASTNode result = twoPhaseParse(sql);\n        if (result.getRootNode() instanceof ErrorNode) {\n            throw new SQLParsingException(sql);\n        }\n        return result;\n    }\n    \n    private ParseASTNode twoPhaseParse(final String sql) {\n        DialectSQLParserFacade sqlParserFacade = DatabaseTypedSPILoader.getService(DialectSQLParserFacade.class, databaseType);\n        SQLParser sqlParser = SQLParserFactory.newInstance(sql, sqlParserFacade.getLexerClass(), sqlParserFacade.getParserClass());\n        try {\n            ((Parser) sqlParser).getInterpreter().setPredictionMode(PredictionMode.SLL);\n            return (ParseASTNode) sqlParser.parse();\n        } catch (final ParseCancellationException ex) {\n            ((Parser) sqlParser).reset();\n            ((Parser) sqlParser).getInterpreter().setPredictionMode(PredictionMode.LL);\n            ((Parser) sqlParser).removeErrorListeners();\n            ((Parser) sqlParser).addErrorListener(SQLParserErrorListener.getInstance());\n            try {\n                return (ParseASTNode) sqlParser.parse();\n            } catch (final ParseCancellationException exception) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/parser/SQLParserExecutor.java#L33-L69","documentation":"Thrown by SQLParserExecutor.parse when twoPhaseParse completes but the resulting ParseASTNode's root is an ANTLR ErrorNode. This covers the case where even the LL phase with the strict listener attached did not cancel, yet the tree is structurally invalid (error recovery produced an ErrorNode root). The raw SQL string is embedded in the message; SQLState 42000.","triggerScenarios":"Dialect SQL that both SLL and LL parsing survive syntactically at the token level but that attaches an ErrorNode at the root: incomplete statements ending mid-clause, mismatched constructs ANTLR recovers from, or grammar rules that embed error nodes for partial matches.","commonSituations":"Truncated SQL from network reads or log replay; statements cut at NUL bytes or newlines; partially-templated SQL where a placeholder was never substituted; grammar edge cases in less-used dialects.","solutions":["Log the full SQL string from the exception and inspect it for truncation or unsubstituted placeholders","Validate SQL length/integrity at the source (no cut-off, correct encoding)","Reproduce with the exact string in a unit test against the dialect parser to confirm the grammar gap","Upgrade ShardingSphere if the dialect grammar fix exists upstream"],"exampleFix":"// before\nString sql = readChunk(inputStream); // may cut mid-statement -> ErrorNode root\n\n// after\nString sql = readFully(inputStream); // read complete statement before parsing","handlingStrategy":"validation","validationCode":"// Ensure the SQL string is complete before parsing (e.g. statement ends cleanly)\nif (sql == null || sql.length() < 6 || sql.indexOf('\\0') >= 0) throw new IllegalArgumentException(\"Corrupt/truncated SQL\");","typeGuard":null,"tryCatchPattern":"try { executor.parse(sql); } catch (SQLParsingException e) { logSqlForDiagnosis(sql); return fallbackReject(sql); }","preventionTips":["Read complete statements (respect delimiters/encoding) before handing SQL to the parser","Log full SQL on parse failure to catch truncation","Guard against NUL bytes and encoding mismatches in SQL sources"],"tags":["sql-parser","antlr","errornode","two-phase","syntax"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}