未验证 提交 0b5ee351 编写于 作者: L Liang Zhang 提交者: GitHub

Fix #7342 (#7464)

上级 05d3d3ad
......@@ -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())) {
......
......@@ -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());
}
}
......@@ -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) {
......
/*
* 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;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册