This is an automated email from the ASF dual-hosted git repository.

JackieTien97 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 5adec0b0961 [Parser] Skip error recovery in the SLL stage of the tree 
and table SQL parsers (#19175)
5adec0b0961 is described below

commit 5adec0b0961d5f12b4ee2d76a427362d78b3dcf2
Author: Christofer Dutz <[email protected]>
AuthorDate: Sun Nov 8 07:21:56 2026 +0100

    [Parser] Skip error recovery in the SLL stage of the tree and table SQL 
parsers (#19175)
---
 .../db/queryengine/plan/parser/StatementGenerator.java      |  4 ++++
 .../queryengine/plan/relational/sql/parser/SqlParser.java   | 13 ++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/StatementGenerator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/StatementGenerator.java
index 7464e6d99fb..046a94c1fa2 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/StatementGenerator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/StatementGenerator.java
@@ -94,6 +94,7 @@ import org.apache.iotdb.service.rpc.thrift.TSRawDataQueryReq;
 import org.apache.iotdb.service.rpc.thrift.TSSetSchemaTemplateReq;
 import org.apache.iotdb.service.rpc.thrift.TSUnsetSchemaTemplateReq;
 
+import org.antlr.v4.runtime.BailErrorStrategy;
 import org.antlr.v4.runtime.CharStream;
 import org.antlr.v4.runtime.CharStreams;
 import org.antlr.v4.runtime.CommonTokenStream;
@@ -857,6 +858,9 @@ public class StatementGenerator {
 
       IoTDBSqlParser parser1 = new IoTDBSqlParser(tokens1);
       parser1.getInterpreter().setPredictionMode(PredictionMode.SLL);
+      // Any error in this stage falls back to the LL stage below, which 
reports it, so
+      // the SLL stage needs no recovery; BailErrorStrategy also skips the 
per-rule sync() checks.
+      parser1.setErrorHandler(new BailErrorStrategy());
       parser1.removeErrorListeners();
       parser1.addErrorListener(SqlParseError.INSTANCE);
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/SqlParser.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/SqlParser.java
index 3f741e635e4..809665c0ef0 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/SqlParser.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/SqlParser.java
@@ -34,6 +34,7 @@ import 
org.apache.iotdb.db.relational.grammar.sql.RelationalSqlLexer;
 import org.apache.iotdb.db.relational.grammar.sql.RelationalSqlParser;
 
 import org.antlr.v4.runtime.ANTLRErrorListener;
+import org.antlr.v4.runtime.BailErrorStrategy;
 import org.antlr.v4.runtime.BaseErrorListener;
 import org.antlr.v4.runtime.CharStreams;
 import org.antlr.v4.runtime.CommonToken;
@@ -47,6 +48,7 @@ import org.antlr.v4.runtime.Recognizer;
 import org.antlr.v4.runtime.Token;
 import org.antlr.v4.runtime.atn.PredictionMode;
 import org.antlr.v4.runtime.misc.Pair;
+import org.antlr.v4.runtime.misc.ParseCancellationException;
 import org.antlr.v4.runtime.tree.TerminalNode;
 
 import java.time.ZoneId;
@@ -158,7 +160,7 @@ public class SqlParser {
 
       // Override the default error strategy to not attempt inserting or 
deleting a token.
       // Otherwise, it messes up error reporting
-      parser.setErrorHandler(
+      DefaultErrorStrategy reportingErrorStrategy =
           new DefaultErrorStrategy() {
             @Override
             public Token recoverInline(Parser recognizer) throws 
RecognitionException {
@@ -167,7 +169,11 @@ public class SqlParser {
               }
               throw new InputMismatchException(recognizer, nextTokensState, 
nextTokensContext);
             }
-          });
+          };
+      // Any error in the SLL stage falls back to the LL stage, which reports 
it with the strategy
+      // above, so the SLL stage needs no recovery; BailErrorStrategy also 
skips the per-rule sync()
+      // checks.
+      parser.setErrorHandler(new BailErrorStrategy());
 
       parser.addParseListener(new 
PostProcessor(Arrays.asList(parser.getRuleNames()), parser));
 
@@ -183,10 +189,11 @@ public class SqlParser {
           // first, try parsing with potentially faster SLL mode
           parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
           tree = parseFunction.apply(parser);
-        } catch (ParsingException ex) {
+        } catch (ParsingException | ParseCancellationException ex) {
           // if we fail, parse with LL mode
           tokenStream.seek(0); // rewind input stream
           parser.reset();
+          parser.setErrorHandler(reportingErrorStrategy);
 
           parser.getInterpreter().setPredictionMode(PredictionMode.LL);
           tree = parseFunction.apply(parser);

Reply via email to