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 2665f90  correct exception message when not contains schema (#11464)
2665f90 is described below

commit 2665f9000dbf22f43274e1ce3c70f18b18a830e0
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri Jul 23 17:07:12 2021 +0800

    correct exception message when not contains schema (#11464)
    
    * fix exception when sql without table
    
    * correct exception message
---
 .../statement/dml/InsertStatementContext.java      |  6 +++--
 .../statement/dml/SelectStatementContext.java      |  5 +++-
 .../infra/exception/SchemaNotExistedException.java | 30 ++++++++++++++++++++++
 .../frontend/mysql/err/MySQLErrPacketFactory.java  |  3 ++-
 4 files changed, 40 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
index 71034ac..200385d 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.infra.binder.statement.dml;
 
-import com.google.common.base.Preconditions;
 import lombok.Getter;
 import 
org.apache.shardingsphere.infra.binder.segment.insert.keygen.GeneratedKeyContext;
 import 
org.apache.shardingsphere.infra.binder.segment.insert.keygen.engine.GeneratedKeyContextEngine;
@@ -27,6 +26,7 @@ import 
org.apache.shardingsphere.infra.binder.segment.insert.values.OnDuplicateU
 import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import 
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
 import org.apache.shardingsphere.infra.binder.type.TableAvailable;
+import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
@@ -85,7 +85,9 @@ public final class InsertStatementContext extends 
CommonSQLStatementContext<Inse
     private ShardingSphereSchema getSchema(final Map<String, 
ShardingSphereMetaData> metaDataMap, final String defaultSchemaName) {
         String schemaName = 
tablesContext.getSchemaName().orElse(defaultSchemaName);
         ShardingSphereMetaData metaData = metaDataMap.get(schemaName);
-        Preconditions.checkState(null != metaData, String.format("Can not get 
metaData by schemaName [%s].", schemaName));
+        if (null == metaData) {
+            throw new SchemaNotExistedException(schemaName);
+        }
         return metaData.getSchema();
     }
     
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 9671b5e..5c5c76c 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -34,6 +34,7 @@ import 
org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import 
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
 import org.apache.shardingsphere.infra.binder.type.TableAvailable;
 import org.apache.shardingsphere.infra.binder.type.WhereAvailable;
+import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
@@ -113,7 +114,9 @@ public final class SelectStatementContext extends 
CommonSQLStatementContext<Sele
     private ShardingSphereSchema getSchema(final Map<String, 
ShardingSphereMetaData> metaDataMap, final String defaultSchemaName) {
         String schemaName = 
tablesContext.getSchemaName().orElse(defaultSchemaName);
         ShardingSphereMetaData metaData = metaDataMap.get(schemaName);
-        Preconditions.checkState(null != metaData, "Can not get meta data by 
schema mame `%s`.", schemaName);
+        if (null == metaData) {
+            throw new SchemaNotExistedException(schemaName);
+        }
         return metaData.getSchema();
     }
     
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotExistedException.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotExistedException.java
new file mode 100644
index 0000000..4165ce8
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/SchemaNotExistedException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.exception;
+
+/**
+ * Schema does not exist exception.
+ */
+public final class SchemaNotExistedException extends ShardingSphereException {
+    
+    private static final long serialVersionUID = -1818822065202117480L;
+    
+    public SchemaNotExistedException(final String schemaName) {
+        super(String.format("Schema '%s' doesn't exist.", schemaName));
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index 6b64495..df57689 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.db.protocol.error.CommonErrorCode;
 import 
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode;
 import 
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket;
 import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
+import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
 import org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException;
 import 
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
 import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
@@ -71,7 +72,7 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof UnknownDatabaseException) {
             return new MySQLErrPacket(1, MySQLServerErrorCode.ER_BAD_DB_ERROR, 
((UnknownDatabaseException) cause).getDatabaseName());
         }
-        if (cause instanceof NoDatabaseSelectedException) {
+        if (cause instanceof NoDatabaseSelectedException || cause instanceof 
SchemaNotExistedException) {
             return new MySQLErrPacket(1, MySQLServerErrorCode.ER_NO_DB_ERROR);
         }
         if (cause instanceof DBCreateExistsException) {

Reply via email to