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

kimmking 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 0b5ee35  Fix #7342 (#7464)
0b5ee35 is described below

commit 0b5ee351bad3ce2dbe52003b55d4f9fa52fcaf36
Author: Liang Zhang <terrym...@163.com>
AuthorDate: Tue Sep 15 19:48:30 2020 +0800

    Fix #7342 (#7464)
---
 .../merge/dal/show/LogicTablesMergedResult.java    |  2 +-
 .../merge/dal/show/ShowTablesMergedResultTest.java |  6 ---
 .../shardingsphere/infra/route/DataNodeRouter.java | 17 +++----
 .../UnconfiguredSchemaRouteDecorator.java          | 54 ++++++++++++++++++++++
 4 files changed, 64 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
index bb3a15e..10dc185 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
@@ -53,7 +53,7 @@ public class LogicTablesMergedResult extends 
MemoryMergedResult<ShardingRule> {
                 String actualTableName = 
memoryResultSetRow.getCell(1).toString();
                 Optional<TableRule> tableRule = 
shardingRule.findTableRuleByActualTable(actualTableName);
                 if (!tableRule.isPresent()) {
-                    if (shardingRule.getTableRules().isEmpty() || 
schemaMetaData.containsTable(actualTableName) && 
tableNames.add(actualTableName)) {
+                    if (shardingRule.getTableRules().isEmpty() || 
tableNames.add(actualTableName)) {
                         result.add(memoryResultSetRow);
                     }
                 } else if (tableNames.add(tableRule.get().getLogicTable())) {
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
index f3f7f73..33d3641 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTablesMergedResultTest.java
@@ -82,10 +82,4 @@ public final class ShowTablesMergedResultTest {
         LogicTablesMergedResult actual = new 
LogicTablesMergedResult(shardingRule, mock(SQLStatementContext.class), 
schemaMetaData, Collections.singletonList(createQueryResult("table_0")));
         assertTrue(actual.next());
     }
-    
-    @Test
-    public void assertNextForActualTableNameNotInTableRule() throws 
SQLException {
-        LogicTablesMergedResult actual = new 
LogicTablesMergedResult(shardingRule, mock(SQLStatementContext.class), 
schemaMetaData, Collections.singletonList(createQueryResult("table_3")));
-        assertFalse(actual.next());
-    }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/DataNodeRouter.java
 
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/DataNodeRouter.java
index 53d75e1..957233a 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/DataNodeRouter.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/DataNodeRouter.java
@@ -17,19 +17,20 @@
 
 package org.apache.shardingsphere.infra.route;
 
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
-import org.apache.shardingsphere.sql.parser.binder.SQLStatementContextFactory;
-import 
org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext;
-import 
org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import 
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteResult;
 import org.apache.shardingsphere.infra.route.decorator.RouteDecorator;
+import 
org.apache.shardingsphere.infra.route.decorator.UnconfiguredSchemaRouteDecorator;
 import org.apache.shardingsphere.infra.route.hook.SPIRoutingHook;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.sql.parser.binder.SQLStatementContextFactory;
+import 
org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext;
+import 
org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
 import java.util.Collection;
 import java.util.List;
@@ -89,7 +90,7 @@ public final class DataNodeRouter {
         for (Entry<ShardingSphereRule, RouteDecorator> entry : 
decorators.entrySet()) {
             result = entry.getValue().decorate(result, metaData, 
entry.getKey(), props);
         }
-        return result;
+        return new UnconfiguredSchemaRouteDecorator().decorate(result, 
metaData);
     }
     
     private RouteContext createRouteContext(final SQLStatement sqlStatement, 
final List<Object> parameters) {
diff --git 
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/decorator/UnconfiguredSchemaRouteDecorator.java
 
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/decorator/UnconfiguredSchemaRouteDecorator.java
new file mode 100644
index 0000000..bf3d8a7
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/decorator/UnconfiguredSchemaRouteDecorator.java
@@ -0,0 +1,54 @@
+/*
+ * 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.route.decorator;
+
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+import org.apache.shardingsphere.infra.route.context.RouteMapper;
+import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowTablesStatement;
+
+import java.util.Collections;
+
+/**
+ * Unconfigured schema route decorator.
+ */
+public final class UnconfiguredSchemaRouteDecorator {
+    
+    /**
+     * Decorate route context.
+     *
+     * @param routeContext route context
+     * @param metaData meta data of ShardingSphere
+     * @return decorated route context
+     */
+    public RouteContext decorate(final RouteContext routeContext, final 
ShardingSphereMetaData metaData) {
+        if 
(isNeedUnconfiguredSchema(routeContext.getSqlStatementContext().getSqlStatement()))
 {
+            for (String each : 
metaData.getRuleSchemaMetaData().getUnconfiguredSchemaMetaDataMap().keySet()) {
+                routeContext.getRouteResult().getRouteUnits().add(new 
RouteUnit(new RouteMapper(each, each), Collections.emptyList()));
+            }
+        }
+        return routeContext;
+    }
+    
+    // TODO use dynamic config to judge UnconfiguredSchema
+    private boolean isNeedUnconfiguredSchema(final SQLStatement sqlStatement) {
+        return sqlStatement instanceof MySQLShowTablesStatement;
+    }
+}

Reply via email to