You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/07/21 07:18:09 UTC
[shardingsphere] branch master updated: Fix MySQL syntax error cannot be thrown to client (#19404)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 ed0ddc4bbca Fix MySQL syntax error cannot be thrown to client (#19404)
ed0ddc4bbca is described below
commit ed0ddc4bbcadaaedd384318a57e790dc4a32e7d4
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Thu Jul 21 15:18:03 2022 +0800
Fix MySQL syntax error cannot be thrown to client (#19404)
* Fix MySQL syntax error cannot be thrown to client
* Remove redundant final modifiers
* Add MySQLSaneQueryResultEngineTest
* Format MySQLSaneQueryResultEngineTest
* Add DefaultSaneQueryResultEngineTest
* Add PostgreSQLSaneQueryResultEngineTest
* Add OpenGaussSaneQueryResultEngineTest
---
.../engine/driver/jdbc/JDBCExecutorCallback.java | 4 +-
.../jdbc/sane/DefaultSaneQueryResultEngine.java | 3 +-
.../driver/jdbc/sane/SaneQueryResultEngine.java | 6 +-
.../sane/mysql/MySQLSaneQueryResultEngine.java | 8 +-
.../opengauss/OpenGaussSaneQueryResultEngine.java | 3 +-
.../PostgreSQLSaneQueryResultEngine.java | 3 +-
.../sane/DefaultSaneQueryResultEngineTest.java | 52 ++++++++++
.../sane/mysql/MySQLSaneQueryResultEngineTest.java | 110 +++++++++++++++++++++
.../OpenGaussSaneQueryResultEngineTest.java} | 24 +++--
.../PostgreSQLSaneQueryResultEngineTest.java} | 24 +++--
.../engine/jdbc/JDBCExecutorCallbackTest.java | 2 +-
.../sql/fixture/FixtureSaneQueryResultEngine.java | 3 +-
.../batch/BatchPreparedStatementExecutor.java | 2 +-
.../executor/callback/ExecuteQueryCallback.java | 2 +-
.../statement/ShardingSpherePreparedStatement.java | 4 +-
.../core/statement/ShardingSphereStatement.java | 4 +-
.../backend/communication/ProxySQLExecutor.java | 3 +-
.../communication/ReactiveProxySQLExecutor.java | 3 +-
.../callback/ProxyJDBCExecutorCallback.java | 4 +-
.../text/distsql/ral/advanced/PreviewHandler.java | 2 +-
.../text/query/MySQLMultiStatementsHandler.java | 2 +-
.../PostgreSQLBatchedStatementsExecutor.java | 2 +-
22 files changed, 221 insertions(+), 49 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java
index 0e280b1dcc6..c2e9e651863 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java
@@ -94,7 +94,7 @@ public abstract class JDBCExecutorCallback<T> implements ExecutorCallback<JDBCEx
if (!isTrunkThread) {
return null;
}
- Optional<T> saneResult = getSaneResult(sqlStatement);
+ Optional<T> saneResult = getSaneResult(sqlStatement, ex);
if (saneResult.isPresent()) {
return saneResult.get();
}
@@ -122,5 +122,5 @@ public abstract class JDBCExecutorCallback<T> implements ExecutorCallback<JDBCEx
protected abstract T executeSQL(String sql, Statement statement, ConnectionMode connectionMode) throws SQLException;
- protected abstract Optional<T> getSaneResult(SQLStatement sqlStatement);
+ protected abstract Optional<T> getSaneResult(SQLStatement sqlStatement, SQLException ex);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngine.java
index 8de97d1697b..eb670d3ed7b 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngine.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.me
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import java.sql.SQLException;
import java.sql.Types;
import java.util.Collections;
import java.util.Optional;
@@ -36,7 +37,7 @@ import java.util.Optional;
public final class DefaultSaneQueryResultEngine implements SaneQueryResultEngine {
@Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
+ public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement, final SQLException ex) {
return sqlStatement instanceof SelectStatement ? Optional.of(createDefaultQueryResult()) : Optional.empty();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/SaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/SaneQueryResultEngine.java
index 50b72842533..7138ee72a66 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/SaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/SaneQueryResultEngine.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.sql.SQLException;
import java.util.Optional;
/**
@@ -32,9 +33,10 @@ public interface SaneQueryResultEngine extends TypedSPI {
/**
* Get sane query result.
- *
+ *
* @param sqlStatement SQL statement
+ * @param ex SQL exception
* @return sane execute result
*/
- Optional<ExecuteResult> getSaneQueryResult(SQLStatement sqlStatement);
+ Optional<ExecuteResult> getSaneQueryResult(SQLStatement sqlStatement, SQLException ex);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java
index 5d8f81d7d0b..adf5b05a9b9 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngine.java
@@ -32,6 +32,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectState
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowOtherStatement;
+import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collections;
@@ -43,8 +44,13 @@ import java.util.Optional;
*/
public final class MySQLSaneQueryResultEngine implements SaneQueryResultEngine {
+ private static final int ER_PARSE_ERROR = 1064;
+
@Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
+ public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement, final SQLException ex) {
+ if (ER_PARSE_ERROR == ex.getErrorCode()) {
+ return Optional.empty();
+ }
if (sqlStatement instanceof SelectStatement) {
return createQueryResult((SelectStatement) sqlStatement);
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java
index 6b423ee31f8..24f2623e579 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.s
import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.sql.SQLException;
import java.util.Optional;
/**
@@ -29,7 +30,7 @@ import java.util.Optional;
public final class OpenGaussSaneQueryResultEngine implements SaneQueryResultEngine {
@Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
+ public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java
index d334b7c1027..452952dd0a9 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.s
import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.sql.SQLException;
import java.util.Optional;
/**
@@ -29,7 +30,7 @@ import java.util.Optional;
public final class PostgreSQLSaneQueryResultEngine implements SaneQueryResultEngine {
@Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
+ public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngineTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngineTest.java
new file mode 100644
index 00000000000..370239022e8
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/DefaultSaneQueryResultEngineTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.sane;
+
+import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
+import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.type.RawMemoryQueryResult;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import org.junit.Test;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class DefaultSaneQueryResultEngineTest {
+
+ @Test
+ public void assertGetSaneQueryResultForOtherStatement() {
+ assertThat(new DefaultSaneQueryResultEngine().getSaneQueryResult(() -> 0, null), is(Optional.empty()));
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForSelectStatement() {
+ Optional<ExecuteResult> actual = new DefaultSaneQueryResultEngine().getSaneQueryResult(new SelectStatement() {
+ }, null);
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), instanceOf(RawMemoryQueryResult.class));
+ RawMemoryQueryResult actualResult = (RawMemoryQueryResult) actual.get();
+ assertThat(actualResult.getRowCount(), is(1L));
+ assertTrue(actualResult.next());
+ assertThat(actualResult.getValue(1, String.class), is("1"));
+ assertFalse(actualResult.next());
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngineTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngineTest.java
new file mode 100644
index 00000000000..ca4922171a8
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/mysql/MySQLSaneQueryResultEngineTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.sane.mysql;
+
+import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
+import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.type.RawMemoryQueryResult;
+import org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLSetStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowOtherStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class MySQLSaneQueryResultEngineTest {
+
+ @Test
+ public void assertGetSaneQueryResultForSyntaxError() {
+ SQLException ex = new SQLException("", "", 1064, null);
+ assertThat(new MySQLSaneQueryResultEngine().getSaneQueryResult(null, ex), is(Optional.empty()));
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForSelectStatementWithFrom() {
+ MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+ selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t"))));
+ assertThat(new MySQLSaneQueryResultEngine().getSaneQueryResult(selectStatement, new SQLException()), is(Optional.empty()));
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForSelectStatementWithoutFrom() {
+ MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+ selectStatement.setProjections(new ProjectionsSegment(0, 0));
+ selectStatement.getProjections().getProjections().add(new ExpressionProjectionSegment(0, 0, "@@session.transaction_read_only"));
+ selectStatement.getProjections().getProjections().add(new ExpressionProjectionSegment(0, 0, "unknown_variable"));
+ Optional<ExecuteResult> actual = new MySQLSaneQueryResultEngine().getSaneQueryResult(selectStatement, new SQLException());
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), instanceOf(RawMemoryQueryResult.class));
+ RawMemoryQueryResult actualResult = (RawMemoryQueryResult) actual.get();
+ assertThat(actualResult.getRowCount(), is(1L));
+ assertTrue(actualResult.next());
+ assertThat(actualResult.getValue(1, String.class), is("0"));
+ assertThat(actualResult.getValue(2, String.class), is("1"));
+ assertFalse(actualResult.next());
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForSelectNoProjectionsStatementWithoutFrom() {
+ MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+ selectStatement.setProjections(new ProjectionsSegment(0, 0));
+ assertThat(new MySQLSaneQueryResultEngine().getSaneQueryResult(selectStatement, new SQLException()), is(Optional.empty()));
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForSetStatement() {
+ Optional<ExecuteResult> actual = new MySQLSaneQueryResultEngine().getSaneQueryResult(new MySQLSetStatement(), new SQLException());
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), instanceOf(UpdateResult.class));
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForShowOtherStatement() {
+ Optional<ExecuteResult> actual = new MySQLSaneQueryResultEngine().getSaneQueryResult(new MySQLShowOtherStatement(), new SQLException());
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), instanceOf(RawMemoryQueryResult.class));
+ RawMemoryQueryResult actualResult = (RawMemoryQueryResult) actual.get();
+ assertThat(actualResult.getRowCount(), is(1L));
+ assertTrue(actualResult.next());
+ assertThat(actualResult.getValue(1, String.class), is("1"));
+ assertFalse(actualResult.next());
+ }
+
+ @Test
+ public void assertGetSaneQueryResultForOtherStatements() {
+ assertThat(new MySQLSaneQueryResultEngine().getSaneQueryResult(new MySQLInsertStatement(), new SQLException()), is(Optional.empty()));
+ }
+
+ @Test
+ public void assertGetType() {
+ assertThat(new MySQLSaneQueryResultEngine().getType(), is("MySQL"));
+ }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngineTest.java
similarity index 60%
copy from shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java
copy to shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngineTest.java
index 6b423ee31f8..bf8d89b7be8 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/opengauss/OpenGaussSaneQueryResultEngineTest.java
@@ -17,24 +17,22 @@
package org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.sane.opengauss;
-import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.sane.SaneQueryResultEngine;
-import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.junit.Test;
import java.util.Optional;
-/**
- * Sane query result engine for openGauss.
- */
-public final class OpenGaussSaneQueryResultEngine implements SaneQueryResultEngine {
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class OpenGaussSaneQueryResultEngineTest {
- @Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
- return Optional.empty();
+ @Test
+ public void assertGetSaneQueryResult() {
+ assertThat(new OpenGaussSaneQueryResultEngine().getSaneQueryResult(null, null), is(Optional.empty()));
}
- @Override
- public String getType() {
- return "openGauss";
+ @Test
+ public void assertGetType() {
+ assertThat(new OpenGaussSaneQueryResultEngine().getType(), is("openGauss"));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngineTest.java
similarity index 60%
copy from shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java
copy to shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngineTest.java
index d334b7c1027..8f2989b142f 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/sane/postgresql/PostgreSQLSaneQueryResultEngineTest.java
@@ -17,24 +17,22 @@
package org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.sane.postgresql;
-import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.sane.SaneQueryResultEngine;
-import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.junit.Test;
import java.util.Optional;
-/**
- * Sane query result engine for PostgreSQL.
- */
-public final class PostgreSQLSaneQueryResultEngine implements SaneQueryResultEngine {
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class PostgreSQLSaneQueryResultEngineTest {
- @Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
- return Optional.empty();
+ @Test
+ public void assertGetSaneQueryResult() {
+ assertThat(new PostgreSQLSaneQueryResultEngine().getSaneQueryResult(null, null), is(Optional.empty()));
}
- @Override
- public String getType() {
- return "PostgreSQL";
+ @Test
+ public void assertGetType() {
+ assertThat(new PostgreSQLSaneQueryResultEngine().getType(), is("PostgreSQL"));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
index 0b953915995..e8360a551cb 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/jdbc/JDBCExecutorCallbackTest.java
@@ -85,7 +85,7 @@ public final class JDBCExecutorCallbackTest {
}
@Override
- protected Optional<Integer> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<Integer> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureSaneQueryResultEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureSaneQueryResultEngine.java
index 2af43bd6b7b..505686ea855 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureSaneQueryResultEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureSaneQueryResultEngine.java
@@ -21,12 +21,13 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.s
import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import java.sql.SQLException;
import java.util.Optional;
public final class FixtureSaneQueryResultEngine implements SaneQueryResultEngine {
@Override
- public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement) {
+ public Optional<ExecuteResult> getSaneQueryResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java
index b6727e417e1..c33a7a80ee1 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java
@@ -147,7 +147,7 @@ public final class BatchPreparedStatementExecutor {
@SuppressWarnings("OptionalContainsCollection")
@Override
- protected Optional<int[]> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<int[]> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/ExecuteQueryCallback.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/ExecuteQueryCallback.java
index a6dec61ecfd..95c83ad3bc7 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/ExecuteQueryCallback.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/ExecuteQueryCallback.java
@@ -47,7 +47,7 @@ public abstract class ExecuteQueryCallback extends JDBCExecutorCallback<QueryRes
}
@Override
- protected final Optional<QueryResult> getSaneResult(final SQLStatement sqlStatement) {
+ protected final Optional<QueryResult> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index b0427cfa581..639a9a3b832 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -345,7 +345,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
}
@Override
- protected Optional<Integer> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<Integer> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
@@ -419,7 +419,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
}
@Override
- protected Optional<Boolean> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<Boolean> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index c263e9c54ac..65546af0aa4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -336,7 +336,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
}
@Override
- protected Optional<Integer> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<Integer> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
@@ -408,7 +408,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
}
@Override
- protected Optional<Boolean> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<Boolean> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
index 06f8bbea0f2..08f59af24bb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
@@ -175,7 +175,8 @@ public final class ProxySQLExecutor {
private List<ExecuteResult> getSaneExecuteResults(final ExecutionContext executionContext, final SQLException originalException) throws SQLException {
DatabaseType databaseType = ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType();
- Optional<ExecuteResult> executeResult = SaneQueryResultEngineFactory.getInstance(databaseType).getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement());
+ Optional<ExecuteResult> executeResult = SaneQueryResultEngineFactory.getInstance(databaseType)
+ .getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement(), originalException);
if (executeResult.isPresent()) {
return Collections.singletonList(executeResult.get());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java
index 9b253db55f0..960acb4ff4d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ReactiveProxySQLExecutor.java
@@ -121,7 +121,8 @@ public final class ReactiveProxySQLExecutor {
private List<ExecuteResult> getSaneExecuteResults(final ExecutionContext executionContext, final SQLException originalException) throws SQLException {
DatabaseType databaseType = ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName()).getResource().getDatabaseType();
- Optional<ExecuteResult> executeResult = SaneQueryResultEngineFactory.getInstance(databaseType).getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement());
+ Optional<ExecuteResult> executeResult = SaneQueryResultEngineFactory.getInstance(databaseType)
+ .getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement(), originalException);
if (executeResult.isPresent()) {
return Collections.singletonList(executeResult.get());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
index 92348e6f37d..5a3d17b5566 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
@@ -101,8 +101,8 @@ public abstract class ProxyJDBCExecutorCallback extends JDBCExecutorCallback<Exe
}
@Override
- protected final Optional<ExecuteResult> getSaneResult(final SQLStatement sqlStatement) {
- return SaneQueryResultEngineFactory.getInstance(getProtocolTypeType()).getSaneQueryResult(sqlStatement);
+ protected final Optional<ExecuteResult> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
+ return SaneQueryResultEngineFactory.getInstance(getProtocolTypeType()).getSaneQueryResult(sqlStatement, ex);
}
private DatabaseType getProtocolTypeType() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java
index ab7ba7564a2..061e75bd322 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/PreviewHandler.java
@@ -154,7 +154,7 @@ public final class PreviewHandler extends QueryableRALBackendHandler<PreviewStat
}
@Override
- protected Optional<ExecuteResult> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<ExecuteResult> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
};
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
index 3a7274d50ce..cb6184edd1b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
@@ -195,7 +195,7 @@ public final class MySQLMultiStatementsHandler implements TextProtocolBackendHan
@SuppressWarnings("OptionalContainsCollection")
@Override
- protected Optional<int[]> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<int[]> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
index 0accbc010df..a36699a95d0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
@@ -202,7 +202,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
@SuppressWarnings("OptionalContainsCollection")
@Override
- protected Optional<int[]> getSaneResult(final SQLStatement sqlStatement) {
+ protected Optional<int[]> getSaneResult(final SQLStatement sqlStatement, final SQLException ex) {
return Optional.empty();
}
}