apache/shardingsphere · error · SQLParsingException
42000
42000
Error message
You have an error in your SQL syntax: %s
What it means
Thrown by KernelDistSQLStatementParserEngine.getSQLStatement when the kernel DistSQL parser (KernelDistSQLLexer/Parser) produces a ParseASTNode whose root is an ErrorNode. This engine handles kernel-level DistSQL (e.g. SHOW/DISTINCT VARIABLE, SET statements) in a single-phase parse, so any grammar-level failure that ANTLR recovers from surfaces here rather than as a cancellation.
Source
Thrown at parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementParserEngine.java:45
/**
* SQL statement parser engine for kernel DistSQL.
*/
public final class KernelDistSQLStatementParserEngine {
/**
* Parse SQL.
*
* @param sql SQL to be parsed
* @return SQL statement
*/
public SQLStatement parse(final String sql) {
ASTNode astNode = SQLParserFactory.newInstance(sql, KernelDistSQLLexer.class, KernelDistSQLParser.class).parse();
return getSQLStatement(sql, (ParseASTNode) astNode);
}
private SQLStatement getSQLStatement(final String sql, final ParseASTNode parseASTNode) {
if (parseASTNode.getRootNode() instanceof ErrorNode) {
throw new SQLParsingException(sql);
}
return (SQLStatement) (new KernelDistSQLStatementVisitor()).visit(parseASTNode.getRootNode());
}
}
View on GitHub (pinned to e952770a21)
Solutions
- Match the statement exactly to kernel DistSQL grammar (SHOW DIST_VARIABLE / SET DIST_VARIABLE etc. for your version)
- Fix quoting and value formats in SET statements
- Route feature-specific statements to DistSQLParserEngine instead of the kernel engine
- Consult KernelDistSQL.g4 grammar for the supported statement forms
Example fix
// before
engine.parse("SET DIST_VARIABLES = a=1"); // wrong keyword form
// after
engine.parse("SET DIST VARIABLE a=1"); Defensive patterns
Strategy: try-catch
Try / catch
try {
SQLStatement stmt = kernelEngine.parse(distSql);
} catch (SQLParsingException e) {
// reject and show user the offending statement
} Prevention
- Use exact kernel DistSQL forms (SHOW DIST_VARIABLE, SET DIST VARIABLE) for your version
- Keep variable-management scripts in one place and lint their keywords
- Don't route feature DistSQL to the kernel engine
When it happens
Trigger: Calling KernelDistSQLStatementParserEngine.parse with malformed kernel DistSQL: 'SHOW VARIABLE' misspellings, invalid SET VARIABLE value syntax, unexpected trailing tokens, or a statement belonging to a feature facade routed to the kernel engine by mistake.
Common situations: Typing kernel DistSQL by hand in the proxy CLI; script-driven variable management with wrong value quoting; version drift where kernel grammar rules were renamed; routing logic sending feature DistSQL to the kernel engine.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/f9e095e92b77afe5.
Report an issue: GitHub.