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

menghaoran 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 9491e6f  Add checking for using RDL out of execution order (#7656)
9491e6f is described below

commit 9491e6f95952af36a73f97474d298117267cc3e1
Author: Juan Pan(Trista) <[email protected]>
AuthorDate: Mon Sep 28 19:44:07 2020 +0800

    Add checking for using RDL out of execution order (#7656)
---
 .../mysql/constant/MySQLServerErrorCode.java       |  2 ++
 .../backend/exception/RuleNotExistsException.java  | 26 ++++++++++++++++++++++
 .../text/admin/BroadcastBackendHandler.java        |  4 ++++
 .../backend/text/admin/UnicastBackendHandler.java  |  4 ++++
 .../backend/text/query/QueryBackendHandler.java    | 11 ++-------
 .../explain/ShardingCTLExplainBackendHandler.java  | 12 ++++++++--
 .../executor/HintShowTableStatusExecutor.java      | 13 +++++++++--
 .../text/admin/BroadcastBackendHandlerTest.java    |  4 +++-
 .../ShardingCTLExplainBackendHandlerTest.java      |  3 ++-
 .../hint/ShardingCTLHintBackendHandlerTest.java    |  9 +++++---
 .../frontend/mysql/MySQLErrPacketFactory.java      |  4 ++++
 11 files changed, 74 insertions(+), 18 deletions(-)

diff --git 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
index e381946..4a23ba1 100644
--- 
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
+++ 
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
@@ -50,6 +50,8 @@ public enum MySQLServerErrorCode implements SQLErrorCode {
     
     ER_NOT_SUPPORTED_YET(1235, "42000", "This version of ShardingProxy doesn't 
yet support this SQL. '%s'"),
     
+    ER_SP_DOES_NOT_EXIST(1305, "42000", "Message: Datasource or ShardingSphere 
rule does not exist"),
+    
     ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE(3176, "HY000", 
             "Please do not modify the %s table with an XA transaction. This is 
an internal system table used to store GTIDs for committed transactions. " 
                     + "Although modifying it can lead to an inconsistent GTID 
state, if neccessary you can modify it with a non-XA transaction.");
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/RuleNotExistsException.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/RuleNotExistsException.java
new file mode 100644
index 0000000..e3da32f
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/RuleNotExistsException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.proxy.backend.exception;
+
+/**
+ * Rule does not exist exception.
+ */
+public final class RuleNotExistsException extends BackendException {
+    
+    private static final long serialVersionUID = -4150905802300104824L;
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandler.java
index 0b491ab..64d0dd5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandler.java
@@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
 import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
@@ -48,6 +49,9 @@ public final class BroadcastBackendHandler implements 
TextProtocolBackendHandler
         String originalSchema = backendConnection.getSchemaName();
         for (String each : ProxyContext.getInstance().getAllSchemaNames()) {
             backendConnection.setCurrentSchema(each);
+            if (!ProxyContext.getInstance().getSchema(each).isComplete()) {
+                throw new RuleNotExistsException();
+            }
             
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatement, sql, 
backendConnection).execute();
         }
         backendConnection.setCurrentSchema(originalSchema);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandler.java
index a5eb530..a19a6c6 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandler.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicati
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
 import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
@@ -55,6 +56,9 @@ public final class UnicastBackendHandler implements 
TextProtocolBackendHandler {
             if (schemaContexts.isEmpty()) {
                 throw new NoDatabaseSelectedException();
             }
+            if (!schemaContexts.values().iterator().next().isComplete()) {
+                throw new RuleNotExistsException();
+            }
             // TODO we should remove set default ShardingSphere schema after 
parser can recognize all DAL broadcast SQL.
             
backendConnection.setCurrentSchema(schemaContexts.keySet().iterator().next());
         }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
index 47dd119..df51b96 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
@@ -19,21 +19,18 @@ package org.apache.shardingsphere.proxy.backend.text.query;
 
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.context.schema.SchemaContext;
-import 
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader;
 import 
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
 import 
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
-import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
 import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
 import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Collections;
 
 /**
  * Backend handler with query.
@@ -58,16 +55,12 @@ public final class QueryBackendHandler implements 
TextProtocolBackendHandler {
             throw new NoDatabaseSelectedException();
         }
         if (!schemaContext.isComplete()) {
-            return getDefaultQueryResponse(backendConnection.getSchemaName());
+            throw new RuleNotExistsException();
         }
         databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatement, sql, 
backendConnection);
         return databaseCommunicationEngine.execute();
     }
     
-    private QueryResponse getDefaultQueryResponse(final String schemaName) {
-        return new QueryResponse(Collections.singletonList(new 
QueryHeader(schemaName, "", "", "", 255, Types.VARCHAR, 0, false, false, false, 
false)));
-    }
-    
     @Override
     public boolean next() throws SQLException {
         return null != databaseCommunicationEngine && 
databaseCommunicationEngine.next();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
index 12de035..96fdea1 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
@@ -18,13 +18,15 @@
 package org.apache.shardingsphere.proxy.backend.text.sctl.explain;
 
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
 import org.apache.shardingsphere.infra.context.schema.SchemaContext;
+import org.apache.shardingsphere.infra.context.sql.LogicSQLContext;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.infra.context.sql.LogicSQLContext;
-import org.apache.shardingsphere.infra.context.kernel.KernelProcessor;
+import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
@@ -60,6 +62,12 @@ public final class ShardingCTLExplainBackendHandler 
implements TextProtocolBacke
             throw new InvalidShardingCTLFormatException(sql);
         }
         SchemaContext schemaContext = 
ProxyContext.getInstance().getSchema(backendConnection.getSchemaName());
+        if (null == schemaContext) {
+            throw new NoDatabaseSelectedException();
+        }
+        if (!schemaContext.isComplete()) {
+            throw new RuleNotExistsException();
+        }
         SQLStatement sqlStatement = 
schemaContext.getRuntimeContext().getSqlParserEngine().parse(explainStatement.get().getSql(),
 false);
         LogicSQLContext logicSQLContext = new LogicSQLContext(schemaContext, 
explainStatement.get().getSql(), Collections.emptyList(), sqlStatement);
         executionUnits = new 
KernelProcessor().generateExecutionContext(logicSQLContext, 
ProxyContext.getInstance().getSchemaContexts().getProps()).getExecutionUnits().iterator();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/internal/executor/HintShowTableStatusExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/internal/executor/HintShowTableStatusExecutor.java
index 58c36f3..388c93c 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/internal/executor/HintShowTableStatusExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/internal/executor/HintShowTableStatusExecutor.java
@@ -19,11 +19,14 @@ package 
org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.executor
 
 import com.google.common.base.Joiner;
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.context.schema.SchemaContext;
 import 
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader;
 import org.apache.shardingsphere.infra.hint.HintManager;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.command.HintShowTableStatusCommand;
 import 
org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.result.HintShowTableStatusResult;
 import 
org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
@@ -56,8 +59,14 @@ public final class HintShowTableStatusExecutor extends 
AbstractHintQueryExecutor
     @Override
     protected MergedResult createMergedResult() {
         Map<String, HintShowTableStatusResult> results = new HashMap<>();
-        Collection<String> tableNames = 
-                
ProxyContext.getInstance().getSchema(backendConnection.getSchemaName()).getSchema().getMetaData().getRuleSchemaMetaData().getConfiguredSchemaMetaData().getAllTableNames();
+        SchemaContext schemaContext = 
ProxyContext.getInstance().getSchema(backendConnection.getSchemaName());
+        if (null == schemaContext) {
+            throw new NoDatabaseSelectedException();
+        }
+        if (!schemaContext.isComplete()) {
+            throw new RuleNotExistsException();
+        }
+        Collection<String> tableNames = 
schemaContext.getSchema().getMetaData().getRuleSchemaMetaData().getConfiguredSchemaMetaData().getAllTableNames();
         for (String each : tableNames) {
             if (HintManager.isDatabaseShardingOnly()) {
                 fillShardingValues(results, each, 
HintManager.getDatabaseShardingValues(), Collections.emptyList());
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandlerTest.java
index 5a7e29d..67f9f42 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandlerTest.java
@@ -91,7 +91,9 @@ public final class BroadcastBackendHandlerTest {
     private Map<String, SchemaContext> getSchemaContextMap() {
         Map<String, SchemaContext> result = new HashMap<>(10);
         for (int i = 0; i < 10; i++) {
-            result.put(String.format(SCHEMA_PATTERN, i), 
mock(SchemaContext.class));
+            SchemaContext schemaContext = mock(SchemaContext.class);
+            when(schemaContext.isComplete()).thenReturn(true);
+            result.put(String.format(SCHEMA_PATTERN, i), schemaContext);
         }
         return result;
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
index 7feffdb..b71b877 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
@@ -9,6 +9,7 @@ import 
org.apache.shardingsphere.infra.context.schema.runtime.RuntimeContext;
 import org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
@@ -65,7 +66,7 @@ public final class ShardingCTLExplainBackendHandlerTest {
     private Map<String, SchemaContext> getSchemaContextMap() {
         RuntimeContext runtimeContext = new RuntimeContext(null, null, new 
ShardingSphereSQLParserEngine(new StandardSQLParserEngine("MySQL")));
         ShardingSphereSchema schema = new 
ShardingSphereSchema(Collections.emptyList(),
-                Collections.emptyList(), Collections.singletonMap("ds0", 
mock(DataSource.class)), mock(ShardingSphereMetaData.class, 
RETURNS_DEEP_STUBS));
+                Collections.singleton(mock(ShardingSphereRule.class)), 
Collections.singletonMap("ds0", mock(DataSource.class)), 
mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS));
         return Collections.singletonMap("schema", new SchemaContext("schema", 
schema, runtimeContext));
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
index a4d71ab..a3ea27f 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
@@ -31,6 +31,7 @@ import org.apache.shardingsphere.infra.hint.HintManager;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.metadata.datasource.DataSourceMetaDatas;
 import org.apache.shardingsphere.infra.metadata.schema.RuleSchemaMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
@@ -49,6 +50,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import javax.sql.DataSource;
 import java.lang.reflect.Field;
 import java.sql.SQLException;
 import java.sql.Types;
@@ -206,11 +208,12 @@ public final class ShardingCTLHintBackendHandlerTest {
     }
     
     private Map<String, SchemaContext> getSchemaContextMap() {
-        SchemaContext result = mock(SchemaContext.class);
         ShardingSphereSchema shardingSphereSchema = 
mock(ShardingSphereSchema.class);
-        when(result.getSchema()).thenReturn(shardingSphereSchema);
-        when(shardingSphereSchema.getMetaData()).thenReturn(new 
ShardingSphereMetaData(mock(DataSourceMetaDatas.class), 
+        when(shardingSphereSchema.getMetaData()).thenReturn(new 
ShardingSphereMetaData(mock(DataSourceMetaDatas.class),
                 new RuleSchemaMetaData(new 
SchemaMetaData(ImmutableMap.of("user", mock(TableMetaData.class))), 
Collections.emptyMap()), "sharding_db"));
+        
when(shardingSphereSchema.getRules()).thenReturn(Collections.singleton(mock(ShardingSphereRule.class)));
+        
when(shardingSphereSchema.getDataSources()).thenReturn(Collections.singletonMap("ds",
 mock(DataSource.class)));
+        SchemaContext result = new SchemaContext("schema", 
shardingSphereSchema, null);
         return Collections.singletonMap("schema", result);
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
index 3b5cdbf..a0bf7bd 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
@@ -27,6 +27,7 @@ import 
org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException;
 import 
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
 import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.RuleNotExistsException;
 import 
org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException;
 import 
org.apache.shardingsphere.proxy.backend.exception.UnknownDatabaseException;
 import org.apache.shardingsphere.proxy.backend.text.sctl.ShardingCTLErrorCode;
@@ -90,6 +91,9 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof ShardingSphereConfigurationException || cause 
instanceof SQLParsingException) {
             return new MySQLErrPacket(1, 
MySQLServerErrorCode.ER_NOT_SUPPORTED_YET, cause.getMessage());
         }
+        if (cause instanceof RuleNotExistsException) {
+            return new MySQLErrPacket(1, 
MySQLServerErrorCode.ER_SP_DOES_NOT_EXIST);
+        }
         return new MySQLErrPacket(1, CommonErrorCode.UNKNOWN_EXCEPTION, 
cause.getMessage());
     }
 }

Reply via email to