provectus/kafka-ui · error · ValidationException
Error parsing ksql query:
Error message
Error parsing ksql query:
What it means
KsqlGrammar.parseStatements catches any exception raised while driving the ANTLR parser over the ksql text (beyond listener-reported syntax errors) and rethrows it as ValidationException('Error parsing ksql query: ' + message). It is the fallback path for parser failures.
Solutions
- Read the wrapped cause message after 'Error parsing ksql query: ' to identify the parser failure
- Simplify the query into smaller statements and parse them individually
- Validate the query with the ksqlDB CLI/parser to isolate the failing construct
- Report/upgrade if the bundled grammar lags behind your ksqlDB server version
Example fix
// before
KsqlGrammar.parseStatements(complexQuery); // single opaque failure
// after
for (String stmt : complexQuery.split(";")) {
KsqlGrammar.parseStatements(stmt + ";"); // isolates failing statement
} Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check: reject obviously malformed multi-statement input
if (query == null || query.isBlank()) throw new IllegalArgumentException("ksql query is empty"); Try / catch
try {
var parser = KsqlGrammar.parsed(query);
} catch (ValidationException e) {
if (e.getMessage().startsWith("Error parsing ksql query:")) {
log.error("ksql parse failed: {}", e.getMessage());
} else { throw e; }
} Prevention
- Keep queries modest in size/complexity; split large scripts into statements
- Ensure UTF-8 clean input without invisible characters
- Test against the same kafka-ui/ANTLR grammar version in CI
- Keep kafka-ui updated to track ksqlDB syntax changes
When it happens
Trigger: parseStatements (exposed via KsqlGrammar.parsed) throwing a non-ANTLR exception during parsing — e.g. internal parser errors, PredictionMode.LL failures, stream/IO problems in the case-insensitive CharStream wrapper.
Common situations: Extremely large or exotic queries stressing the parser; grammar edge cases not handled by the copied Confluent implementation; corrupted input encoding.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Invalid syntax:
- Invalid format for webclient.maxInMemoryBufferSize
- seekTo should be set if seekType is
- Wrong seekTo argument format. See API docs for details
- Unexpected script result
AI-assisted analysis of provectus/kafka-ui@83b5a60cc0 (2026-09-08).
Data as JSON: /api/errors/eb0aaf9f619138e3.
Report an issue: GitHub.
Appendix: source
Thrown at kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/ksql/KsqlGrammar.java:61
private static ksql.KsqlGrammarParser.StatementsContext parseStatements(final String sql) {
var lexer = new KsqlGrammarLexer(CaseInsensitiveStream.from(CharStreams.fromString(sql)));
var tokenStream = new CommonTokenStream(lexer);
var grammarParser = new ksql.KsqlGrammarParser(tokenStream);
lexer.addErrorListener(new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
int line, int charPositionInLine,
String msg, RecognitionException e) {
throw new ValidationException("Invalid syntax: " + msg);
}
});
grammarParser.getInterpreter().setPredictionMode(PredictionMode.LL);
try {
return grammarParser.statements();
} catch (Exception e) {
throw new ValidationException("Error parsing ksql query: " + e.getMessage());
}
}
// impl copied from https://github.com/confluentinc/ksql/blob/master/ksqldb-parser/src/main/java/io/confluent/ksql/parser/CaseInsensitiveStream.java
@RequiredArgsConstructor
private static class CaseInsensitiveStream implements CharStream {
@Delegate
final CharStream stream;
public static CaseInsensitiveStream from(CharStream stream) {
// we only need to override LA method
return new CaseInsensitiveStream(stream) {
@Override
public int LA(final int i) {
final int result = stream.LA(i);
switch (result) {
case 0:
case IntStream.EOF:View on GitHub (pinned to 83b5a60cc0)