You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/05/25 03:14:42 UTC
[iotdb] branch master updated: [IOTDB-3237] Too much information in SQL parser error message (#5984)
This is an automated email from the ASF dual-hosted git repository.
rong 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 f35f1133f6 [IOTDB-3237] Too much information in SQL parser error message (#5984)
f35f1133f6 is described below
commit f35f1133f680341025b4adf8474fbcfbe5364cb2
Author: Liao Lanyu <48...@users.noreply.github.com>
AuthorDate: Wed May 25 11:14:37 2022 +0800
[IOTDB-3237] Too much information in SQL parser error message (#5984)
---
.../IoTDBSyntaxConventionIdentifierIT.java | 17 +++++++++++++++
.../apache/iotdb/db/qp/strategy/SQLParseError.java | 24 ++++++++++++++++++++++
.../tsfile/read/common/parser/PathParseError.java | 23 +++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java
index 5a22435269..643a29c048 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java
@@ -357,6 +357,23 @@ public class IoTDBSyntaxConventionIdentifierIT {
}
}
+ @Test
+ public void testCreateIllegalStorageGroup() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+
+ try {
+ statement.execute("create storage group root.sg1.d1.");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
@Test
public void testExpression() {
try (Connection connection = EnvFactory.getEnv().getConnection();
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/SQLParseError.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/SQLParseError.java
index f4386df261..1db0a8915a 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/SQLParseError.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/SQLParseError.java
@@ -19,10 +19,16 @@
package org.apache.iotdb.db.qp.strategy;
import org.antlr.v4.runtime.BaseErrorListener;
+import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
+import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.ParseCancellationException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
public class SQLParseError extends BaseErrorListener {
public static final SQLParseError INSTANCE = new SQLParseError();
@@ -35,6 +41,24 @@ public class SQLParseError extends BaseErrorListener {
int charPositionInLine,
String msg,
RecognitionException e) {
+ // make msg clearer
+ if (recognizer instanceof Parser) {
+ IntervalSet expectedTokens = ((Parser) recognizer).getExpectedTokens();
+ String expectedTokensString = expectedTokens.toString(recognizer.getVocabulary());
+ String trimmed = expectedTokensString.replace(" ", "");
+ Set<String> expectedTokenNames =
+ new HashSet<>(Arrays.asList(trimmed.substring(1, trimmed.length() - 1).split(",")));
+
+ if (expectedTokenNames.contains("ID") && expectedTokenNames.contains("QUOTED_ID")) {
+ // node name
+ if (expectedTokenNames.contains("*") && expectedTokenNames.contains("**")) {
+ msg = msg.replace(expectedTokensString, "{ID, QUOTED_ID, *, **}");
+ } else {
+ msg = msg.replace(expectedTokensString, "{ID, QUOTED_ID}");
+ }
+ }
+ }
+
throw new ParseCancellationException("line " + line + ":" + charPositionInLine + " " + msg);
}
}
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/parser/PathParseError.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/parser/PathParseError.java
index c29000b867..e106c408e3 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/parser/PathParseError.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/parser/PathParseError.java
@@ -19,10 +19,16 @@
package org.apache.iotdb.tsfile.read.common.parser;
import org.antlr.v4.runtime.BaseErrorListener;
+import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
+import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.ParseCancellationException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
public class PathParseError extends BaseErrorListener {
public static final PathParseError INSTANCE = new PathParseError();
@@ -34,6 +40,23 @@ public class PathParseError extends BaseErrorListener {
int charPositionInLine,
String msg,
RecognitionException e) {
+ // make msg clearer
+ if (recognizer instanceof Parser) {
+ IntervalSet expectedTokens = ((Parser) recognizer).getExpectedTokens();
+ String expectedTokensString = expectedTokens.toString(recognizer.getVocabulary());
+ String trimmed = expectedTokensString.replace(" ", "");
+ Set<String> expectedTokenNames =
+ new HashSet<>(Arrays.asList(trimmed.substring(1, trimmed.length() - 1).split(",")));
+
+ if (expectedTokenNames.contains("ID") && expectedTokenNames.contains("QUOTED_ID")) {
+ // node name
+ if (expectedTokenNames.contains("*") && expectedTokenNames.contains("**")) {
+ msg = msg.replace(expectedTokensString, "{ID, QUOTED_ID, *, **}");
+ } else {
+ msg = msg.replace(expectedTokensString, "{ID, QUOTED_ID}");
+ }
+ }
+ }
throw new ParseCancellationException("line " + line + ":" + charPositionInLine + " " + msg);
}
}