You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/09/01 07:48:40 UTC
[shardingsphere] branch master updated: Add table not exists exception. (#28330)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 d8c4511d06c Add table not exists exception. (#28330)
d8c4511d06c is described below
commit d8c4511d06c78aad70d7e7471a4055195a7f6ccc
Author: Chuxin Chen <ch...@qq.com>
AuthorDate: Fri Sep 1 15:48:29 2023 +0800
Add table not exists exception. (#28330)
* Add table not exists exception.
* Add table not exists exception.
* Add table not exists exception.
* Add table not exists exception.
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../from/impl/SimpleTableSegmentBinder.java | 18 +++++++++++-
.../from/impl/JoinTableSegmentBinderTest.java | 4 +++
.../from/impl/SimpleTableSegmentBinderTest.java | 17 +++++++++++
.../from/impl/SubqueryTableSegmentBinderTest.java | 3 ++
.../statement/DeleteStatementBinderTest.java | 3 ++
.../binder/statement/MergeStatementBinderTest.java | 4 +++
.../statement/SelectStatementBinderTest.java | 3 ++
.../statement/UpdateStatementBinderTest.java | 3 ++
.../infra/exception/TableNotExistsException.java | 33 ++++++++++++++++++++++
.../type/HBaseDeleteOperationConverterTest.java | 2 ++
.../type/HBaseUpdateOperationConverterTest.java | 2 ++
.../prepare/MySQLComStmtPrepareExecutorTest.java | 1 +
.../query/MySQLComQueryPacketExecutorTest.java | 1 +
.../query/MySQLMultiStatementsHandlerTest.java | 3 ++
.../PostgreSQLComDescribeExecutorTest.java | 3 ++
.../parse/PostgreSQLComParseExecutorTest.java | 1 +
18 files changed, 102 insertions(+), 1 deletion(-)
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 2966dd4ae89..7df4412ed7e 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
@@ -21,6 +21,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 42000 | 10004 | Unsupported SQL node conversion for SQL statement \`%s\`. |
| HY000 | 10005 | Column '%s' in %s is ambiguous. |
| 42S02 | 10006 | Unknown column '%s' in '%s'. |
+| 42S02 | 10007 | Table or view \`%s\` does not exist. |
| 42000 | 10010 | Rule does not exist. |
| 42S02 | 10020 | Schema \`%s\` does not exist. |
| 42S02 | 10021 | Single table \`%s\` does not exist. |
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 6e0746c654f..22aaf389820 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
@@ -21,6 +21,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 42000 | 10004 | Unsupported SQL node conversion for SQL statement \`%s\`. |
| HY000 | 10005 | Column '%s' in %s is ambiguous. |
| 42S02 | 10006 | Unknown column '%s' in '%s'. |
+| 42S02 | 10007 | Table or view \`%s\` does not exist. |
| 42000 | 10010 | Rule does not exist. |
| 42S02 | 10020 | Schema \`%s\` does not exist. |
| 42S02 | 10021 | Single table \`%s\` does not exist. |
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
index 2216a39d1d2..e189c3a93b2 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinder.java
@@ -26,6 +26,9 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.database.opengauss.type.OpenGaussDatabaseType;
import org.apache.shardingsphere.infra.database.postgresql.type.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.exception.TableNotExistsException;
+import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.metadata.database.schema.builder.SystemSchemaBuilderRule;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
@@ -74,7 +77,7 @@ public final class SimpleTableSegmentBinder {
public static SimpleTableSegment bind(final SimpleTableSegment segment, final SQLStatementBinderContext statementBinderContext, final Map<String, TableSegmentBinderContext> tableBinderContexts) {
IdentifierValue originalDatabase = getDatabaseName(segment, statementBinderContext);
IdentifierValue originalSchema = getSchemaName(segment, statementBinderContext);
- // TODO check database and schema
+ checkTableExists(segment.getTableName().getIdentifier().getValue(), statementBinderContext, originalDatabase.getValue(), originalSchema.getValue());
ShardingSphereSchema schema = statementBinderContext.getMetaData().getDatabase(originalDatabase.getValue()).getSchema(originalSchema.getValue());
tableBinderContexts.put(segment.getAliasName().orElseGet(() -> segment.getTableName().getIdentifier().getValue()),
createSimpleTableBinderContext(segment, schema, originalDatabase, originalSchema, statementBinderContext.getDatabaseType()));
@@ -122,4 +125,17 @@ public final class SimpleTableSegmentBinder {
}
return new TableSegmentBinderContext(projectionSegments);
}
+
+ private static void checkTableExists(final String tableName, final SQLStatementBinderContext statementBinderContext, final String databaseName, final String schemaName) {
+ if ("dual".equalsIgnoreCase(tableName)) {
+ return;
+ }
+ if (SystemSchemaBuilderRule.isSystemTable(schemaName, tableName)) {
+ return;
+ }
+ ShardingSpherePreconditions.checkState(statementBinderContext.getMetaData().containsDatabase(databaseName)
+ && statementBinderContext.getMetaData().getDatabase(databaseName).containsSchema(schemaName)
+ && statementBinderContext.getMetaData().getDatabase(databaseName).getSchema(schemaName).containsTable(tableName),
+ () -> new TableNotExistsException(tableName));
+ }
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java
index 0b8e985b882..7f6bc4d476f 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinderTest.java
@@ -250,6 +250,10 @@ class JoinTableSegmentBinderTest {
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order_item")).thenReturn(true);
return result;
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
index b9a9f767a65..3a63b4be718 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SimpleTableSegmentBinderTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinderCon
import org.apache.shardingsphere.infra.binder.statement.SQLStatementBinderContext;
import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.exception.TableNotExistsException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -39,6 +40,7 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -122,6 +124,21 @@ class SimpleTableSegmentBinderTest {
when(result.getDatabase("sharding_db").getSchema("sharding_db")).thenReturn(schema);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema("public")).thenReturn(schema);
when(result.getDatabase("sharding_db").getSchema("test")).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
+ when(result.containsDatabase("sharding_db")).thenReturn(true);
+ when(result.getDatabase("sharding_db").containsSchema("sharding_db")).thenReturn(true);
+ when(result.getDatabase("sharding_db").getSchema("sharding_db").containsTable("t_order")).thenReturn(true);
return result;
}
+
+ @Test
+ void assertBindTableNotExists() {
+ SimpleTableSegment simpleTableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("t_not_exists")));
+ ShardingSphereMetaData metaData = createMetaData();
+ Map<String, TableSegmentBinderContext> tableBinderContexts = new CaseInsensitiveMap<>();
+ assertThrows(TableNotExistsException.class,
+ () -> SimpleTableSegmentBinder.bind(simpleTableSegment, new SQLStatementBinderContext(metaData, DefaultDatabase.LOGIC_NAME, databaseType), tableBinderContexts));
+ }
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java
index 8cff2484e1d..e0bdbc223c4 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/from/impl/SubqueryTableSegmentBinderTest.java
@@ -138,6 +138,9 @@ class SubqueryTableSegmentBinderTest {
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
return result;
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/DeleteStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/DeleteStatementBinderTest.java
index 97e93fe3aa6..986ba26090c 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/DeleteStatementBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/DeleteStatementBinderTest.java
@@ -76,6 +76,9 @@ class DeleteStatementBinderTest {
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
return result;
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/MergeStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/MergeStatementBinderTest.java
index 7cdf2382e21..46af27db8cc 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/MergeStatementBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/MergeStatementBinderTest.java
@@ -95,6 +95,10 @@ class MergeStatementBinderTest {
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order_item")).thenReturn(true);
return result;
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SelectStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SelectStatementBinderTest.java
index e5a2cfa9f9d..4e2cc0242aa 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SelectStatementBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/SelectStatementBinderTest.java
@@ -111,6 +111,9 @@ class SelectStatementBinderTest {
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
return result;
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/UpdateStatementBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/UpdateStatementBinderTest.java
index 6dad29e3dad..234057d8b2d 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/UpdateStatementBinderTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/UpdateStatementBinderTest.java
@@ -76,6 +76,9 @@ class UpdateStatementBinderTest {
new ShardingSphereColumn("status", Types.INTEGER, false, false, false, true, false, false)));
ShardingSphereMetaData result = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(result.containsDatabase(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(result.getDatabase(DefaultDatabase.LOGIC_NAME).getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_order")).thenReturn(true);
return result;
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotExistsException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotExistsException.java
new file mode 100644
index 00000000000..28141de15fb
--- /dev/null
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/TableNotExistsException.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;
+
+/**
+ * Table not exists exception.
+ */
+public final class TableNotExistsException extends MetaDataSQLException {
+
+ private static final long serialVersionUID = -2507596759730534895L;
+
+ public TableNotExistsException(final String tableName) {
+ super(XOpenSQLState.NOT_FOUND, 7, "Table or view `%s` does not exist.", tableName);
+ }
+}
diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java
index c8a1e55bf28..9f5382b1550 100644
--- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java
+++ b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseDeleteOperationConverterTest.java
@@ -76,6 +76,8 @@ class HBaseDeleteOperationConverterTest {
ShardingSphereTable table = new ShardingSphereTable("t_test_order", Collections.singletonList(new ShardingSphereColumn("rowKey", Types.VARCHAR, true, false, false, false, true, false)),
Collections.emptyList(), Collections.emptyList());
when(database.getSchema(DefaultDatabase.LOGIC_NAME).getTable("t_test_order")).thenReturn(table);
+ when(database.containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(database.getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_test_order")).thenReturn(true);
Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database);
return new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
diff --git a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java
index 46f24540b55..4aaefbf457f 100644
--- a/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java
+++ b/proxy/backend/type/hbase/src/test/java/org/apache/shardingsphere/proxy/backend/hbase/converter/type/HBaseUpdateOperationConverterTest.java
@@ -77,6 +77,8 @@ class HBaseUpdateOperationConverterTest {
ShardingSphereTable table = new ShardingSphereTable("t_test_order", Arrays.asList(new ShardingSphereColumn("rowKey", Types.VARCHAR, true, false, false, false, true, false),
new ShardingSphereColumn("age", Types.INTEGER, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList());
when(database.getSchema(DefaultDatabase.LOGIC_NAME).getTable("t_test_order")).thenReturn(table);
+ when(database.containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(database.getSchema(DefaultDatabase.LOGIC_NAME).containsTable("t_test_order")).thenReturn(true);
Map<String, ShardingSphereDatabase> databases = Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database);
return new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
index a645a4f7113..945165e6fd2 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutorTest.java
@@ -208,6 +208,7 @@ class MySQLComStmtPrepareExecutorTest {
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "MySQL"),
new ResourceMetaData("foo_db", Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), Collections.singletonMap("foo_db", schema));
when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database);
+ when(result.getMetaDataContexts().getMetaData().containsDatabase("foo_db")).thenReturn(true);
return result;
}
}
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
index f4097c49e09..eea216efe80 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
@@ -154,6 +154,7 @@ class MySQLComQueryPacketExecutorTest {
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "MySQL"),
new ResourceMetaData("foo_db", Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), Collections.singletonMap("foo_db", schema));
when(result.getMetaData().getDatabase("foo_db")).thenReturn(database);
+ when(result.getMetaData().containsDatabase("foo_db")).thenReturn(true);
return result;
}
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
index 5c9db921a50..e84d35be991 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
@@ -123,6 +123,9 @@ class MySQLMultiStatementsHandlerTest {
ShardingSphereTable table = new ShardingSphereTable("t", Arrays.asList(new ShardingSphereColumn("id", Types.BIGINT, true, false, false, false, true, false),
new ShardingSphereColumn("v", Types.INTEGER, false, false, false, false, true, false)), Collections.emptyList(), Collections.emptyList());
when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getSchema("foo_db").getTable("t")).thenReturn(table);
+ when(result.getMetaDataContexts().getMetaData().containsDatabase("foo_db")).thenReturn(true);
+ when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").containsSchema("foo_db")).thenReturn(true);
+ when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db").getSchema("foo_db").containsTable("t")).thenReturn(true);
return result;
}
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
index 45da4ae6d92..b44e5a902d2 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
@@ -404,6 +404,9 @@ class PostgreSQLComDescribeExecutorTest {
when(storageUnit.getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).getResourceMetaData().getStorageUnitMetaData().getStorageUnits())
.thenReturn(Collections.singletonMap("ds_0", storageUnit));
+ when(result.getMetaDataContexts().getMetaData().containsDatabase(DATABASE_NAME)).thenReturn(true);
+ when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).containsSchema("public")).thenReturn(true);
+ when(result.getMetaDataContexts().getMetaData().getDatabase(DATABASE_NAME).getSchema("public").containsTable(TABLE_NAME)).thenReturn(true);
return result;
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
index 9f6cce134db..56b62df345c 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
@@ -190,6 +190,7 @@ class PostgreSQLComParseExecutorTest {
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"),
new ResourceMetaData("foo_db", Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), Collections.singletonMap("public", schema));
when(result.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database);
+ when(result.getMetaDataContexts().getMetaData().containsDatabase("foo_db")).thenReturn(true);
return result;
}
}