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

zhangliang 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 2ee217ebdf0 Add SQLFederationNotFoundSchemaSQLException (#31367)
2ee217ebdf0 is described below

commit 2ee217ebdf061f12e5ed40203647b34baf4b4813
Author: zhaojinchao <[email protected]>
AuthorDate: Thu May 23 23:26:33 2024 +0800

    Add SQLFederationNotFoundSchemaSQLException (#31367)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  7 +++--
 .../sqlfederation/engine/SQLFederationEngine.java  |  2 ++
 .../SQLFederationSchemaNotFoundException.java      | 32 ++++++++++++++++++++++
 4 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md 
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 408bd36cb14..9f3990fdf3b 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -192,6 +192,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 
|-------------|-----------|---------------------------------------------------------|
 | 20100       | 42000     | Unsupported SQL node conversion for SQL statement 
'%s'. |
 | 20101       | 42000     | SQL federation does not support SQL '%s'.          
     |
+| 20102       | 42S02     | SQL federation schema not found SQL '%s'.          
    |
 
 ### 读写分离
 
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md 
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 32b027a75d8..36f50139c9f 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -188,10 +188,11 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 
 ### SQL Federation
 
-| Vendor Code | SQL State | Reason                                             
     |
-|-------------|-----------|---------------------------------------------------------|
+| Vendor Code | SQL State | Reason                                             
    |
+|-------------|-----------|--------------------------------------------------------|
 | 20100       | 42000     | Unsupported SQL node conversion for SQL statement 
'%s'. |
-| 20101       | 42000     | SQL federation does not support SQL '%s'.          
     |
+| 20101       | 42000     | SQL federation does not support SQL '%s'.          
    |
+| 20102       | 42S02     | SQL federation schema not found SQL '%s'.          
    |
 
 ### Readwrite-splitting
 
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
index c82b5c31098..a81a1a08d5c 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
@@ -59,6 +59,7 @@ import 
org.apache.shardingsphere.sqlfederation.optimizer.SQLFederationCompilerEn
 import 
org.apache.shardingsphere.sqlfederation.optimizer.SQLFederationExecutionPlan;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContext;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerMetaData;
+import 
org.apache.shardingsphere.sqlfederation.optimizer.exception.SQLFederationSchemaNotFoundException;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.exception.SQLFederationUnsupportedSQLException;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.metadata.schema.SQLFederationTable;
 import 
org.apache.shardingsphere.sqlfederation.optimizer.planner.cache.ExecutionPlanCacheKey;
@@ -181,6 +182,7 @@ public final class SQLFederationEngine implements 
AutoCloseable {
             SqlToRelConverter converter = 
SQLFederationPlannerUtils.createSqlToRelConverter(catalogReader, validator, 
SQLFederationPlannerUtils.createRelOptCluster(DEFAULT_DATA_TYPE_FACTORY),
                     
sqlFederationRule.getOptimizerContext().getSqlParserRule(), 
sqlFederationRule.getOptimizerContext().getParserContext(databaseName).getDatabaseType(),
 true);
             Schema sqlFederationSchema = 
catalogReader.getRootSchema().plus().getSubSchema(schemaName);
+            ShardingSpherePreconditions.checkNotNull(sqlFederationSchema, () 
-> new 
SQLFederationSchemaNotFoundException(federationContext.getQueryContext().getSql()));
             SQLFederationExecutionPlan executionPlan = 
compileQuery(prepareEngine, callback, federationContext, databaseName, 
schemaName, sqlFederationSchema, converter);
             resultSet = executePlan(federationContext, executionPlan, 
validator, converter, sqlFederationSchema);
             return resultSet;
diff --git 
a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/exception/SQLFederationSchemaNotFoundException.java
 
b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/exception/SQLFederationSchemaNotFoundException.java
new file mode 100644
index 00000000000..a2f8de499ec
--- /dev/null
+++ 
b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/exception/SQLFederationSchemaNotFoundException.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sqlfederation.optimizer.exception;
+
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * SQL federation schema not found exception.
+ */
+public final class SQLFederationSchemaNotFoundException extends 
SQLFederationSQLException {
+    
+    private static final long serialVersionUID = 1273654561551534516L;
+    
+    public SQLFederationSchemaNotFoundException(final String sql) {
+        super(XOpenSQLState.NOT_FOUND, 2, "SQL federation schema not found SQL 
'%s'.", sql);
+    }
+}

Reply via email to