This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 76af8782980 Refactor ParseErrorException (#30812)
76af8782980 is described below
commit 76af878298031052203d1f71b3c2af549ac881f5
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Apr 9 12:39:17 2024 +0800
Refactor ParseErrorException (#30812)
* Refactor ParseErrorException
* Refactor ParseErrorException
* Rename DialectSQLParsingException
---
.../exception/syntax/sql/DialectSQLParsingException.java} | 6 +++---
.../exception/mysql/mapper/MySQLDialectExceptionMapper.java | 8 ++++----
.../mysql/mapper/MySQLDialectExceptionMapperTest.java | 4 ++--
infra/parser/pom.xml | 2 +-
.../infra/parser/ShardingSphereSQLParserEngine.java | 12 ++++--------
.../handler/distsql/rul/ParseDistSQLExecutorTest.java | 4 ++--
6 files changed, 16 insertions(+), 20 deletions(-)
diff --git
a/infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/exception/ParseErrorException.java
b/infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/exception/syntax/sql/DialectSQLParsingException.java
similarity index 86%
rename from
infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/exception/ParseErrorException.java
rename to
infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/exception/syntax/sql/DialectSQLParsingException.java
index c74b4586287..983cc8e828e 100644
---
a/infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/exception/ParseErrorException.java
+++
b/infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/exception/syntax/sql/DialectSQLParsingException.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.exception.mysql.exception;
+package org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.infra.exception.dialect.exception.SQLDialectException;
/**
- * Parse error exception.
+ * Dialect SQL parsing exception.
*/
@RequiredArgsConstructor
@Getter
-public final class ParseErrorException extends SQLDialectException {
+public final class DialectSQLParsingException extends SQLDialectException {
private static final long serialVersionUID = -750654777434834288L;
diff --git
a/infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapper.java
b/infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapper.java
index ceae12ed5b8..d820671e24c 100644
---
a/infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapper.java
+++
b/infra/exception/dialect/type/mysql/src/main/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapper.java
@@ -36,7 +36,7 @@ import
org.apache.shardingsphere.infra.exception.mysql.exception.ErrorGlobalVari
import
org.apache.shardingsphere.infra.exception.mysql.exception.ErrorLocalVariableException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.HandshakeException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.IncorrectGlobalLocalVariableException;
-import
org.apache.shardingsphere.infra.exception.mysql.exception.ParseErrorException;
+import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql.DialectSQLParsingException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.TooManyPlaceholdersException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.UnknownCharsetException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.UnknownCollationException;
@@ -70,9 +70,9 @@ public final class MySQLDialectExceptionMapper implements
SQLDialectExceptionMap
if (sqlDialectException instanceof TableExistsException) {
return toSQLException(MySQLVendorError.ER_TABLE_EXISTS_ERROR,
((TableExistsException) sqlDialectException).getTableName());
}
- if (sqlDialectException instanceof ParseErrorException) {
- return toSQLException(MySQLVendorError.ER_PARSE_ERROR,
sqlDialectException.getMessage(), ((ParseErrorException)
sqlDialectException).getSymbol(),
- ((ParseErrorException) sqlDialectException).getLine());
+ if (sqlDialectException instanceof DialectSQLParsingException) {
+ return toSQLException(MySQLVendorError.ER_PARSE_ERROR,
sqlDialectException.getMessage(), ((DialectSQLParsingException)
sqlDialectException).getSymbol(),
+ ((DialectSQLParsingException)
sqlDialectException).getLine());
}
if (sqlDialectException instanceof NoSuchTableException) {
return toSQLException(MySQLVendorError.ER_NO_SUCH_TABLE,
((NoSuchTableException) sqlDialectException).getTableName());
diff --git
a/infra/exception/dialect/type/mysql/src/test/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
b/infra/exception/dialect/type/mysql/src/test/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
index 130767e42d5..a7a760acbce 100644
---
a/infra/exception/dialect/type/mysql/src/test/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
+++
b/infra/exception/dialect/type/mysql/src/test/java/org/apache/shardingsphere/infra/exception/mysql/mapper/MySQLDialectExceptionMapperTest.java
@@ -34,7 +34,7 @@ import
org.apache.shardingsphere.infra.exception.mysql.exception.ErrorGlobalVari
import
org.apache.shardingsphere.infra.exception.mysql.exception.ErrorLocalVariableException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.HandshakeException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.IncorrectGlobalLocalVariableException;
-import
org.apache.shardingsphere.infra.exception.mysql.exception.ParseErrorException;
+import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql.DialectSQLParsingException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.UnknownCharsetException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.UnknownCollationException;
import
org.apache.shardingsphere.infra.exception.mysql.exception.UnknownSystemVariableException;
@@ -72,7 +72,7 @@ class MySQLDialectExceptionMapperTest {
Arguments.of(DatabaseCreateExistsException.class,
MySQLVendorError.ER_DB_CREATE_EXISTS_ERROR),
Arguments.of(DatabaseDropNotExistsException.class,
MySQLVendorError.ER_DB_DROP_NOT_EXISTS_ERROR),
Arguments.of(TableExistsException.class,
MySQLVendorError.ER_TABLE_EXISTS_ERROR),
- Arguments.of(ParseErrorException.class,
MySQLVendorError.ER_PARSE_ERROR),
+ Arguments.of(DialectSQLParsingException.class,
MySQLVendorError.ER_PARSE_ERROR),
Arguments.of(NoSuchTableException.class,
MySQLVendorError.ER_NO_SUCH_TABLE),
Arguments.of(InsertColumnsAndValuesMismatchedException.class,
MySQLVendorError.ER_WRONG_VALUE_COUNT_ON_ROW),
Arguments.of(TableModifyInTransactionException.class,
MySQLVendorError.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE),
diff --git a/infra/parser/pom.xml b/infra/parser/pom.xml
index 829e39f9d12..c4cb5a108db 100644
--- a/infra/parser/pom.xml
+++ b/infra/parser/pom.xml
@@ -34,7 +34,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-mysql-dialect-exception</artifactId>
+
<artifactId>shardingsphere-infra-exception-dialect-core</artifactId>
<version>${project.version}</version>
</dependency>
diff --git
a/infra/parser/src/main/java/org/apache/shardingsphere/infra/parser/ShardingSphereSQLParserEngine.java
b/infra/parser/src/main/java/org/apache/shardingsphere/infra/parser/ShardingSphereSQLParserEngine.java
index 5c002429172..ff04127ab68 100644
---
a/infra/parser/src/main/java/org/apache/shardingsphere/infra/parser/ShardingSphereSQLParserEngine.java
+++
b/infra/parser/src/main/java/org/apache/shardingsphere/infra/parser/ShardingSphereSQLParserEngine.java
@@ -20,8 +20,7 @@ package org.apache.shardingsphere.infra.parser;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import
org.apache.shardingsphere.distsql.parser.engine.api.DistSQLStatementParserEngine;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType;
-import
org.apache.shardingsphere.infra.exception.mysql.exception.ParseErrorException;
+import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql.DialectSQLParsingException;
import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine;
import
org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngineFactory;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
@@ -34,14 +33,11 @@ import
org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
*/
public final class ShardingSphereSQLParserEngine implements SQLParserEngine {
- private final DatabaseType databaseType;
-
private final SQLStatementParserEngine sqlStatementParserEngine;
private final DistSQLStatementParserEngine distSQLStatementParserEngine;
public ShardingSphereSQLParserEngine(final DatabaseType databaseType,
final CacheOption sqlStatementCacheOption, final CacheOption
parseTreeCacheOption) {
- this.databaseType = databaseType;
sqlStatementParserEngine =
SQLStatementParserEngineFactory.getSQLStatementParserEngine(databaseType,
sqlStatementCacheOption, parseTreeCacheOption);
distSQLStatementParserEngine = new DistSQLStatementParserEngine();
}
@@ -60,9 +56,9 @@ public final class ShardingSphereSQLParserEngine implements
SQLParserEngine {
String trimSQL = SQLUtils.trimComment(sql);
return distSQLStatementParserEngine.parse(trimSQL);
} catch (final SQLParsingException ignored) {
- throw originalEx instanceof SQLParsingException &&
databaseType instanceof MySQLDatabaseType
- ? new ParseErrorException(originalEx.getMessage(),
((SQLParsingException) originalEx).getSymbol(), ((SQLParsingException)
originalEx).getLine())
- : originalEx;
+ throw (RuntimeException) (originalEx instanceof
SQLParsingException
+ ? new
DialectSQLParsingException(originalEx.getMessage(), ((SQLParsingException)
originalEx).getSymbol(), ((SQLParsingException) originalEx).getLine())
+ : originalEx);
}
}
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/ParseDistSQLExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/ParseDistSQLExecutorTest.java
index f5ef94c6e5c..21d30688f96 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/ParseDistSQLExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/ParseDistSQLExecutorTest.java
@@ -19,7 +19,7 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.rul;
import org.apache.shardingsphere.distsql.statement.rul.sql.ParseStatement;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.infra.exception.mysql.exception.ParseErrorException;
+import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql.DialectSQLParsingException;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.json.JsonUtils;
@@ -93,6 +93,6 @@ class ParseDistSQLExecutorTest {
String sql = "wrong sql";
when(connectionSession.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"MySQL"));
DistSQLQueryBackendHandler handler = new
DistSQLQueryBackendHandler(new ParseStatement(sql), connectionSession);
- assertThrows(ParseErrorException.class, handler::execute);
+ assertThrows(DialectSQLParsingException.class, handler::execute);
}
}