This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 5e0b09b310e Add AggregatedDataSourceRuleAttribute to reuse aggregated
datasource in kernel and enhance TablelessRouteEngine broadcast route logic
(#33941)
5e0b09b310e is described below
commit 5e0b09b310ec450efe0c6ed820988b2f627ca5fe
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Sat Dec 7 18:59:48 2024 +0800
Add AggregatedDataSourceRuleAttribute to reuse aggregated datasource in
kernel and enhance TablelessRouteEngine broadcast route logic (#33941)
* Add AggregatedDataSourceRuleAttribute to reuse aggregated datasource in
kernel and enhance TablelessRouteEngine broadcast route logic
* fix unit test
* fix unit test
* fix unit test
* fix unit test
* fix e2e test case
* add new TablelessDataSourceUnicastRouteEngine
---
.../broadcast/rule/BroadcastRule.java | 40 +++------------
.../merge/dal/ShardingDALResultMerger.java | 20 ++++----
.../merge/dal/show/LogicTablesMergedResult.java | 40 ++++++---------
.../shardingsphere/sharding/rule/ShardingRule.java | 13 ++++-
.../sharding/rule/builder/ShardingRuleBuilder.java | 2 +-
.../checker/ShardingRouteCacheableCheckerTest.java | 2 +-
.../dal/show/LogicTablesMergedResultTest.java | 2 +-
.../dal/show/ShowCreateTableMergedResultTest.java | 2 +-
.../dal/show/ShowTableStatusMergedResultTest.java | 2 +-
.../reviser/ShardingMetaDataReviseEntryTest.java | 2 +-
.../constraint/ShardingConstraintReviserTest.java | 2 +-
.../fixture/ShardingRouteEngineFixtureBuilder.java | 17 +++---
.../ShardingDatabaseBroadcastRouteEngineTest.java | 3 +-
.../ShardingTableBroadcastRouteEngineTest.java | 2 +-
.../unicast/ShardingUnicastRouteEngineTest.java | 2 +-
.../sharding/rule/ShardingRuleTest.java | 60 ++++++++++++----------
.../query/ShowShardingTableNodesExecutorTest.java | 2 +-
...ator.java => PhysicalDataSourceAggregator.java} | 14 ++---
.../infra/metadata/database/rule/RuleMetaData.java | 16 ++++++
.../AggregatedDataSourceRuleAttribute.java} | 26 +++++-----
.../connection/kernel/KernelProcessorTest.java | 13 +++++
.../engine/tableless/TablelessRouteEngine.java | 7 +--
.../tableless/TablelessRouteEngineFactory.java | 35 +++++++++----
.../tableless/router/TablelessSQLRouter.java | 11 +++-
.../TablelessDataSourceBroadcastRouteEngine.java | 6 +--
.../TablelessInstanceBroadcastRouteEngine.java | 5 +-
.../type/ignore/TablelessIgnoreRouteEngine.java | 5 +-
.../TablelessDataSourceUnicastRouteEngine.java} | 32 +++++++++---
.../infra/route/engine/SQLRouteEngineTest.java | 5 ++
.../engine/router/TablelessSQLRouterTest.java | 9 +++-
.../tableless/TablelessRouteEngineFactoryTest.java | 34 ++++++++----
.../ShardingSphereDatabaseMetaDataTest.java | 2 +-
.../SingleRuleConfigurationDecorator.java | 4 +-
.../single/route/SingleSQLRouter.java | 3 +-
.../shardingsphere/single/rule/SingleRule.java | 17 +++---
.../query/ShowUnloadedSingleTablesExecutor.java | 4 +-
.../handler/update/LoadSingleTableExecutor.java | 4 +-
.../update/LoadSingleTableExecutorTest.java | 6 +--
.../ImportDatabaseConfigurationExecutorTest.java | 2 +
.../test/e2e/engine/type/DALE2EIT.java | 14 +++--
.../mysql/show_table_status.xml | 47 +++++++++++++++++
.../mysql/show_tables.xml} | 22 ++++----
.../src/test/resources/cases/dal/e2e-dal-set.xml | 2 +-
.../src/test/resources/cases/dal/e2e-dal-show.xml | 11 ++++
44 files changed, 365 insertions(+), 204 deletions(-)
diff --git
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
index 959640d4b45..070e19425c7 100644
---
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
+++
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
@@ -24,16 +24,16 @@ import
org.apache.shardingsphere.broadcast.constant.BroadcastOrder;
import
org.apache.shardingsphere.broadcast.rule.attribute.BroadcastDataNodeRuleAttribute;
import
org.apache.shardingsphere.broadcast.rule.attribute.BroadcastTableNamesRuleAttribute;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
-import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
/**
* Broadcast rule.
@@ -51,36 +51,12 @@ public final class BroadcastRule implements DatabaseRule {
public BroadcastRule(final BroadcastRuleConfiguration config, final
Map<String, DataSource> dataSources, final Collection<ShardingSphereRule>
builtRules) {
configuration = config;
- dataSourceNames = getAggregatedDataSourceNames(dataSources,
builtRules);
+ Map<String, DataSource> aggregatedDataSources = new
RuleMetaData(builtRules).findAttribute(AggregatedDataSourceRuleAttribute.class)
+
.map(AggregatedDataSourceRuleAttribute::getAggregatedDataSources).orElseGet(()
-> PhysicalDataSourceAggregator.getAggregatedDataSources(dataSources,
builtRules));
+ dataSourceNames = new
CaseInsensitiveSet<>(aggregatedDataSources.keySet());
tables = new CaseInsensitiveSet<>(config.getTables());
- attributes = new RuleAttributes(new
BroadcastDataNodeRuleAttribute(dataSourceNames, tables), new
BroadcastTableNamesRuleAttribute(tables));
- }
-
- private Collection<String> getAggregatedDataSourceNames(final Map<String,
DataSource> dataSources, final Collection<ShardingSphereRule> builtRules) {
- Collection<String> result = new
CaseInsensitiveSet<>(dataSources.keySet());
- for (ShardingSphereRule each : builtRules) {
- Optional<DataSourceMapperRuleAttribute> ruleAttribute =
each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class);
- if (ruleAttribute.isPresent()) {
- result = getAggregatedDataSourceNames(result,
ruleAttribute.get());
- }
- }
- return result;
- }
-
- private Collection<String> getAggregatedDataSourceNames(final
Collection<String> dataSourceNames, final DataSourceMapperRuleAttribute
ruleAttribute) {
- Collection<String> result = new CaseInsensitiveSet<>();
- for (Entry<String, Collection<String>> entry :
ruleAttribute.getDataSourceMapper().entrySet()) {
- for (String each : entry.getValue()) {
- if (dataSourceNames.contains(each)) {
- dataSourceNames.remove(each);
- if (!result.contains(entry.getKey())) {
- result.add(entry.getKey());
- }
- }
- }
- }
- result.addAll(dataSourceNames);
- return result;
+ attributes = new RuleAttributes(new
BroadcastDataNodeRuleAttribute(dataSourceNames, tables),
+ new BroadcastTableNamesRuleAttribute(tables), new
AggregatedDataSourceRuleAttribute(aggregatedDataSources));
}
/**
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
index 17cf2c35701..f4c7b5c0f4d 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
@@ -36,11 +36,11 @@ import
org.apache.shardingsphere.sharding.merge.dal.show.ShowIndexMergedResult;
import
org.apache.shardingsphere.sharding.merge.dal.show.ShowTableStatusMergedResult;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowCreateTableStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowDatabasesStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowIndexStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowTableStatusStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowTablesStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateTableStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowDatabasesStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowIndexStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTableStatusStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement;
import java.sql.SQLException;
import java.util.Collections;
@@ -60,20 +60,20 @@ public final class ShardingDALResultMerger implements
ResultMerger {
public MergedResult merge(final List<QueryResult> queryResults, final
SQLStatementContext sqlStatementContext,
final ShardingSphereDatabase database, final
ConnectionContext connectionContext) throws SQLException {
SQLStatement dalStatement = sqlStatementContext.getSqlStatement();
- if (dalStatement instanceof MySQLShowDatabasesStatement) {
+ if (dalStatement instanceof ShowDatabasesStatement) {
return new LocalDataMergedResult(Collections.singleton(new
LocalDataQueryResultRow(databaseName)));
}
ShardingSphereSchema schema = getSchema(sqlStatementContext, database);
- if (dalStatement instanceof MySQLShowTablesStatement) {
+ if (dalStatement instanceof ShowTablesStatement) {
return new LogicTablesMergedResult(shardingRule,
sqlStatementContext, schema, queryResults);
}
- if (dalStatement instanceof MySQLShowTableStatusStatement) {
+ if (dalStatement instanceof ShowTableStatusStatement) {
return new ShowTableStatusMergedResult(shardingRule,
sqlStatementContext, schema, queryResults);
}
- if (dalStatement instanceof MySQLShowIndexStatement) {
+ if (dalStatement instanceof ShowIndexStatement) {
return new ShowIndexMergedResult(shardingRule,
sqlStatementContext, schema, queryResults);
}
- if (dalStatement instanceof MySQLShowCreateTableStatement) {
+ if (dalStatement instanceof ShowCreateTableStatement) {
return new ShowCreateTableMergedResult(shardingRule,
sqlStatementContext, schema, queryResults);
}
return new TransparentMergedResult(queryResults.get(0));
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
index 16c5babe3f3..6df02c7b513 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResult.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.merge.dal.show;
+import com.cedarsoftware.util.CaseInsensitiveMap;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import
org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryMergedResult;
@@ -27,11 +28,10 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sharding.rule.ShardingTable;
import java.sql.SQLException;
-import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
-import java.util.Set;
/**
* Logic tables merged result.
@@ -46,32 +46,24 @@ public class LogicTablesMergedResult extends
MemoryMergedResult<ShardingRule> {
@Override
protected final List<MemoryQueryResultRow> init(final ShardingRule rule,
final ShardingSphereSchema schema,
final SQLStatementContext
sqlStatementContext, final List<QueryResult> queryResults) throws SQLException {
- List<MemoryQueryResultRow> result = new LinkedList<>();
- Set<String> tableNames = new HashSet<>();
+ Map<String, MemoryQueryResultRow> result = new CaseInsensitiveMap<>();
for (QueryResult each : queryResults) {
while (each.next()) {
- createMemoryQueryResultRow(rule, schema, each,
tableNames).ifPresent(result::add);
+ MemoryQueryResultRow memoryResultSetRow = new
MemoryQueryResultRow(each);
+ String actualTableName =
memoryResultSetRow.getCell(1).toString();
+ Optional<ShardingTable> shardingTable =
rule.findShardingTableByActualTable(actualTableName);
+ if (shardingTable.isPresent()) {
+ String logicTableName =
shardingTable.get().getLogicTable();
+ memoryResultSetRow.setCell(1, logicTableName);
+ setCellValue(memoryResultSetRow, logicTableName,
actualTableName, schema.getTable(logicTableName), rule);
+ result.putIfAbsent(logicTableName, memoryResultSetRow);
+ } else {
+ setCellValue(memoryResultSetRow, actualTableName,
actualTableName, schema.getTable(actualTableName), rule);
+ result.putIfAbsent(actualTableName, memoryResultSetRow);
+ }
}
}
- return result;
- }
-
- private Optional<MemoryQueryResultRow> createMemoryQueryResultRow(final
ShardingRule rule,
- final
ShardingSphereSchema schema, final QueryResult queryResult, final Set<String>
tableNames) throws SQLException {
- MemoryQueryResultRow memoryResultSetRow = new
MemoryQueryResultRow(queryResult);
- String actualTableName = memoryResultSetRow.getCell(1).toString();
- Optional<ShardingTable> shardingTable =
rule.findShardingTableByActualTable(actualTableName);
- if (shardingTable.isPresent() &&
tableNames.add(shardingTable.get().getLogicTable())) {
- String logicTableName = shardingTable.get().getLogicTable();
- memoryResultSetRow.setCell(1, logicTableName);
- setCellValue(memoryResultSetRow, logicTableName, actualTableName,
schema.getTable(logicTableName), rule);
- return Optional.of(memoryResultSetRow);
- }
- if (rule.getShardingTables().isEmpty() ||
tableNames.add(actualTableName)) {
- setCellValue(memoryResultSetRow, actualTableName, actualTableName,
schema.getTable(actualTableName), rule);
- return Optional.of(memoryResultSetRow);
- }
- return Optional.empty();
+ return new LinkedList<>(result.values());
}
protected void setCellValue(final MemoryQueryResultRow memoryResultSetRow,
final String logicTableName, final String actualTableName, final
ShardingSphereTable table, final ShardingRule rule) {
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index c8fa9618481..758d45b663c 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -33,8 +33,12 @@ import
org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import
org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContextAware;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -115,7 +119,8 @@ public final class ShardingRule implements DatabaseRule {
private final ShardingRuleChecker shardingRuleChecker = new
ShardingRuleChecker(this);
- public ShardingRule(final ShardingRuleConfiguration ruleConfig, final
Map<String, DataSource> dataSources, final ComputeNodeInstanceContext
computeNodeInstanceContext) {
+ public ShardingRule(final ShardingRuleConfiguration ruleConfig, final
Map<String, DataSource> dataSources, final ComputeNodeInstanceContext
computeNodeInstanceContext,
+ final Collection<ShardingSphereRule> builtRules) {
configuration = ruleConfig;
dataSourceNames = getDataSourceNames(ruleConfig.getTables(),
ruleConfig.getAutoTables(), dataSources.keySet());
ruleConfig.getShardingAlgorithms().forEach((key, value) ->
shardingAlgorithms.put(key, TypedSPILoader.getService(ShardingAlgorithm.class,
value.getType(), value.getProps())));
@@ -137,7 +142,11 @@ public final class ShardingRule implements DatabaseRule {
((ComputeNodeInstanceContextAware)
defaultKeyGenerateAlgorithm).setComputeNodeInstanceContext(computeNodeInstanceContext);
}
shardingCache = null == ruleConfig.getShardingCache() ? null : new
ShardingCache(ruleConfig.getShardingCache(), this);
- attributes = new RuleAttributes(new
ShardingDataNodeRuleAttribute(shardingTables), new
ShardingTableNamesRuleAttribute(shardingTables.values()));
+ // TODO check sharding rule configuration according to aggregated data
sources
+ Map<String, DataSource> aggregatedDataSources = new
RuleMetaData(builtRules).findAttribute(AggregatedDataSourceRuleAttribute.class)
+
.map(AggregatedDataSourceRuleAttribute::getAggregatedDataSources).orElseGet(()
-> PhysicalDataSourceAggregator.getAggregatedDataSources(dataSources,
builtRules));
+ attributes = new RuleAttributes(new
ShardingDataNodeRuleAttribute(shardingTables), new
ShardingTableNamesRuleAttribute(shardingTables.values()),
+ new AggregatedDataSourceRuleAttribute(aggregatedDataSources));
shardingRuleChecker.check(ruleConfig);
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
index ec7e816fbe9..2cdcf1b1c56 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
@@ -39,7 +39,7 @@ public final class ShardingRuleBuilder implements
DatabaseRuleBuilder<ShardingRu
public ShardingRule build(final ShardingRuleConfiguration ruleConfig,
final String databaseName, final DatabaseType protocolType,
final ResourceMetaData resourceMetaData, final
Collection<ShardingSphereRule> builtRules, final ComputeNodeInstanceContext
computeNodeInstanceContext) {
ShardingSpherePreconditions.checkNotEmpty(resourceMetaData.getDataSourceMap(),
() -> new MissingRequiredShardingConfigurationException("Data source",
databaseName));
- return new ShardingRule(ruleConfig,
resourceMetaData.getDataSourceMap(), computeNodeInstanceContext);
+ return new ShardingRule(ruleConfig,
resourceMetaData.getDataSourceMap(), computeNodeInstanceContext, builtRules);
}
@Override
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
index 7bed052dfe1..4ca1d047cbd 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableCheckerTest.java
@@ -113,7 +113,7 @@ class ShardingRouteCacheableCheckerTest {
ruleConfig.getTables().add(nonCacheableTableSharding);
ruleConfig.setShardingCache(new ShardingCacheConfiguration(100, new
ShardingCacheOptionsConfiguration(true, 0, 0)));
return new ShardingRule(ruleConfig, Maps.of("ds_0", new
MockedDataSource(), "ds_1", new MockedDataSource()),
- new
ComputeNodeInstanceContext(mock(ComputeNodeInstance.class), props -> 0, null,
null, null));
+ new
ComputeNodeInstanceContext(mock(ComputeNodeInstance.class), props -> 0, null,
null, null), Collections.emptyList());
}
private TimestampServiceRule createTimeServiceRule() {
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResultTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResultTest.java
index 0ce146aaa92..8d4bd523941 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResultTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/LogicTablesMergedResultTest.java
@@ -55,7 +55,7 @@ class LogicTablesMergedResultTest {
private ShardingRule createShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("table", "ds.table_${0..2}"));
- return new ShardingRule(shardingRuleConfig, Maps.of("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, Maps.of("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
}
@Test
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
index 8ca0eeff754..4136510fb20 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowCreateTableMergedResultTest.java
@@ -60,7 +60,7 @@ class ShowCreateTableMergedResultTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("foo_tbl", "ds.foo_tbl_${0..2}"));
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("bar_tbl", "ds.bar_tbl_${0..2}"));
- return new ShardingRule(shardingRuleConfig, Maps.of("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, Maps.of("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
}
private ShardingSphereSchema createSchema() {
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
index 3f1dceaf958..d00a7ee4f83 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/show/ShowTableStatusMergedResultTest.java
@@ -64,7 +64,7 @@ class ShowTableStatusMergedResultTest {
private ShardingRule buildShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("table", "ds.table_${0..2}"));
- return new ShardingRule(shardingRuleConfig, Maps.of("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, Maps.of("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
}
@Test
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/ShardingMetaDataReviseEntryTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/ShardingMetaDataReviseEntryTest.java
index b074a92a3e7..2d4203f81eb 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/ShardingMetaDataReviseEntryTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/ShardingMetaDataReviseEntryTest.java
@@ -84,7 +84,7 @@ class ShardingMetaDataReviseEntryTest {
ShardingRuleConfiguration ruleConfig =
createShardingRuleConfiguration();
ComputeNodeInstanceContext computeNodeInstanceContext =
mock(ComputeNodeInstanceContext.class);
when(computeNodeInstanceContext.getWorkerId()).thenReturn(0);
- return new ShardingRule(ruleConfig, Collections.singletonMap("ds", new
MockedDataSource()), computeNodeInstanceContext);
+ return new ShardingRule(ruleConfig, Collections.singletonMap("ds", new
MockedDataSource()), computeNodeInstanceContext, Collections.emptyList());
}
private ShardingRuleConfiguration createShardingRuleConfiguration() {
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviserTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviserTest.java
index f570e5fe18d..f3228bac501 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviserTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviserTest.java
@@ -56,7 +56,7 @@ class ShardingConstraintReviserTest {
private ShardingRule createShardingRule() {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ruleConfig.setTables(Collections.singleton(new
ShardingTableRuleConfiguration("table_name", "ds.table_name")));
- return new ShardingRule(ruleConfig, Collections.singletonMap("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(ruleConfig, Collections.singletonMap("ds", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
}
@Test
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
index 620fe317ca1..f08ea964f75 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
@@ -78,7 +78,7 @@ public final class ShardingRouteEngineFixtureBuilder {
shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_${user_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put(
"t_order_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_${order_id % 2}"))));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
/**
@@ -92,7 +92,7 @@ public final class ShardingRouteEngineFixtureBuilder {
shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_${user_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put(
"t_order_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_${order_id % 3}"))));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
/**
@@ -110,7 +110,7 @@ public final class ShardingRouteEngineFixtureBuilder {
"t_order_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_${order_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put(
"t_order_item_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_item_${order_id % 2}"))));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
/**
@@ -127,7 +127,7 @@ public final class ShardingRouteEngineFixtureBuilder {
"t_order_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_${order_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put(
"t_order_item_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_item_${order_id % 2}"))));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
/**
@@ -139,7 +139,7 @@ public final class ShardingRouteEngineFixtureBuilder {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleWithHintConfiguration());
shardingRuleConfig.getShardingAlgorithms().put("core_hint_fixture",
new AlgorithmConfiguration("CORE.HINT.FIXTURE", new Properties()));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
/**
@@ -157,7 +157,7 @@ public final class ShardingRouteEngineFixtureBuilder {
shardingRuleConfig.getShardingAlgorithms().put("ds_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_${user_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put(
"t_hint_ds_test_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_hint_ds_test_${order_id % 2}"))));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
/**
@@ -180,7 +180,8 @@ public final class ShardingRouteEngineFixtureBuilder {
"t_order_item_inline", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_item_${user_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put("t_user_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "t_user_${user_id % 2}"))));
shardingRuleConfig.getShardingAlgorithms().put("core_hint_fixture",
new AlgorithmConfiguration("CORE.HINT.FIXTURE", new Properties()));
- return new ShardingRule(shardingRuleConfig, Maps.of("ds_0", new
MockedDataSource(), "ds_1", new MockedDataSource(), "main", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, Maps.of("ds_0", new
MockedDataSource(), "ds_1", new MockedDataSource(), "main", new
MockedDataSource()), mock(ComputeNodeInstanceContext.class),
+ Collections.emptyList());
}
/**
@@ -200,7 +201,7 @@ public final class ShardingRouteEngineFixtureBuilder {
new Property("datetime-interval-amount", "1"),
new Property("datetime-interval-unit", "MONTHS"));
shardingRuleConfig.getShardingAlgorithms().put("interval_test", new
AlgorithmConfiguration("INTERVAL", props));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
private static ShardingTableRuleConfiguration
createInlineTableRuleConfiguration(final String tableName,
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRouteEngineTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRouteEngineTest.java
index 8bafb983a8d..ae73f57d8d5 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRouteEngineTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingDatabaseBroadcastRouteEngineTest.java
@@ -28,6 +28,7 @@ import
org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
@@ -43,7 +44,7 @@ class ShardingDatabaseBroadcastRouteEngineTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..2}"));
RouteContext routeContext = shardingDatabaseBroadcastRouteEngine
- .route(new ShardingRule(shardingRuleConfig, Maps.of("ds_0",
new MockedDataSource(), "ds_1", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class)));
+ .route(new ShardingRule(shardingRuleConfig, Maps.of("ds_0",
new MockedDataSource(), "ds_1", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
assertThat(routeContext.getRouteUnits().size(), is(2));
assertThat(routeUnits.get(0).getDataSourceMapper().getActualName(),
is("ds_0"));
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
index fbc5ef5ee97..f3e9f6ce36d 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
@@ -129,7 +129,7 @@ class ShardingTableBroadcastRouteEngineTest {
private ShardingRule createShardingRule() {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ruleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order", "ds${0..1}.t_order_${0..1}"));
- return new ShardingRule(ruleConfig, Maps.of("ds_0", new
MockedDataSource(), "ds_1", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(ruleConfig, Maps.of("ds_0", new
MockedDataSource(), "ds_1", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
private SQLStatementContext createSQLStatementContext(final
Collection<String> tableNames) {
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngineTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngineTest.java
index 0e43304f2fb..cac50c8c295 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngineTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRouteEngineTest.java
@@ -50,7 +50,7 @@ class ShardingUnicastRouteEngineTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new
ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..2}"));
rule = new ShardingRule(shardingRuleConfig,
- Maps.of("ds_0", new MockedDataSource(), "ds_1", new
MockedDataSource(), "ds_2", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class));
+ Maps.of("ds_0", new MockedDataSource(), "ds_1", new
MockedDataSource(), "ds_2", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
@Test
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 132b6706023..bc846a380f8 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -120,7 +120,7 @@ class ShardingRuleTest {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ruleConfig.setDefaultDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "MOD"));
ruleConfig.getShardingAlgorithms().put("MOD", new
AlgorithmConfiguration("MOD", PropertiesBuilder.build(new
Property("sharding-count", "2"))));
- assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -128,7 +128,7 @@ class ShardingRuleTest {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ruleConfig.setDefaultTableShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "MOD"));
ruleConfig.getShardingAlgorithms().put("MOD", new
AlgorithmConfiguration("MOD", PropertiesBuilder.build(new
Property("sharding-count", "2"))));
- assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -138,7 +138,7 @@ class ShardingRuleTest {
tableRuleConfig.setDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "MOD"));
ruleConfig.getTables().add(tableRuleConfig);
ruleConfig.getShardingAlgorithms().put("MOD", new
AlgorithmConfiguration("MOD", PropertiesBuilder.build(new
Property("sharding-count", "2"))));
- assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -148,7 +148,7 @@ class ShardingRuleTest {
tableRuleConfig.setTableShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "MOD"));
ruleConfig.getTables().add(tableRuleConfig);
ruleConfig.getShardingAlgorithms().put("MOD", new
AlgorithmConfiguration("MOD", PropertiesBuilder.build(new
Property("sharding-count", "2"))));
- assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -158,7 +158,7 @@ class ShardingRuleTest {
autoTableRuleConfig.setShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "INLINE"));
ruleConfig.getAutoTables().add(autoTableRuleConfig);
ruleConfig.getShardingAlgorithms().put("INLINE", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "t_order_%{order_id % 2}"))));
- assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -171,7 +171,7 @@ class ShardingRuleTest {
duplicateTableRuleConfig.setTableShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "MOD"));
ruleConfig.getTables().add(duplicateTableRuleConfig);
ruleConfig.getShardingAlgorithms().put("INLINE", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "t_order_%{order_id % 2}"))));
- assertThrows(DuplicateShardingActualDataNodeException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(DuplicateShardingActualDataNodeException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -181,7 +181,7 @@ class ShardingRuleTest {
tableRuleConfig.setTableShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "order_id_inline"));
ruleConfig.getTables().add(tableRuleConfig);
ruleConfig.getShardingAlgorithms().put("order_id_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "t_order_${order_id % 2}"))));
- assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(AlgorithmInitializationException.class, () -> new
ShardingRule(ruleConfig, Collections.emptyMap(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -197,7 +197,7 @@ class ShardingRuleTest {
ruleConfig.getTables().add(versionTableRuleConfig);
ruleConfig.getShardingAlgorithms().put("order_id_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "t_order_${order_id % 2}"))));
ruleConfig.getShardingAlgorithms().put("user_id_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_${user_id % 2}"))));
- assertDoesNotThrow(() -> new ShardingRule(ruleConfig,
Collections.emptyMap(), mock(ComputeNodeInstanceContext.class,
RETURNS_DEEP_STUBS)));
+ assertDoesNotThrow(() -> new ShardingRule(ruleConfig,
Collections.emptyMap(), mock(ComputeNodeInstanceContext.class),
Collections.emptyList()));
}
@Test
@@ -209,7 +209,7 @@ class ShardingRuleTest {
ruleConfig.getTables().add(tableRuleConfig);
ruleConfig.getShardingAlgorithms().put("t_order_interval_inline",
new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression",
"t_order_interval_${order_id.substring(0, 6)}"))));
- assertDoesNotThrow(() -> new ShardingRule(ruleConfig,
Collections.emptyMap(), mock(ComputeNodeInstanceContext.class,
RETURNS_DEEP_STUBS)));
+ assertDoesNotThrow(() -> new ShardingRule(ruleConfig,
Collections.emptyMap(), mock(ComputeNodeInstanceContext.class),
Collections.emptyList()));
}
@Test
@@ -315,7 +315,8 @@ class ShardingRuleTest {
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.setDefaultDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("column", "CORE.STANDARD.FIXTURE"));
shardingRuleConfig.getShardingAlgorithms().put("core_standard_fixture", new
AlgorithmConfiguration("CORE.STANDARD.FIXTURE", new Properties()));
- Optional<String> actual = new ShardingRule(shardingRuleConfig,
createDataSources(),
mock(ComputeNodeInstanceContext.class)).findShardingColumn("column",
"LOGIC_TABLE");
+ Optional<String> actual =
+ new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class),
Collections.emptyList()).findShardingColumn("column", "LOGIC_TABLE");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("column"));
}
@@ -326,7 +327,8 @@ class ShardingRuleTest {
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.setDefaultTableShardingStrategy(new
StandardShardingStrategyConfiguration("column", "core_standard_fixture"));
shardingRuleConfig.getShardingAlgorithms().put("core_standard_fixture", new
AlgorithmConfiguration("CORE.STANDARD.FIXTURE", new Properties()));
- Optional<String> actual = new ShardingRule(shardingRuleConfig,
createDataSources(),
mock(ComputeNodeInstanceContext.class)).findShardingColumn("column",
"LOGIC_TABLE");
+ Optional<String> actual =
+ new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class),
Collections.emptyList()).findShardingColumn("column", "LOGIC_TABLE");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("column"));
}
@@ -336,7 +338,8 @@ class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
shardingRuleConfig.getShardingAlgorithms().put("core_standard_fixture", new
AlgorithmConfiguration("CORE.STANDARD.FIXTURE", new Properties()));
- Optional<String> actual = new ShardingRule(shardingRuleConfig,
createDataSources(),
mock(ComputeNodeInstanceContext.class)).findShardingColumn("column",
"logic_Table");
+ Optional<String> actual =
+ new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class),
Collections.emptyList()).findShardingColumn("column", "logic_Table");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("column"));
}
@@ -346,7 +349,8 @@ class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithTableStrategies());
shardingRuleConfig.getShardingAlgorithms().put("core_standard_fixture", new
AlgorithmConfiguration("CORE.STANDARD.FIXTURE", new Properties()));
- Optional<String> actual = new ShardingRule(shardingRuleConfig,
createDataSources(),
mock(ComputeNodeInstanceContext.class)).findShardingColumn("column",
"logic_Table");
+ Optional<String> actual =
+ new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class),
Collections.emptyList()).findShardingColumn("column", "logic_Table");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("column"));
}
@@ -355,7 +359,8 @@ class ShardingRuleTest {
void assertIsNotShardingColumn() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies());
- Optional<String> actual = new ShardingRule(shardingRuleConfig,
createDataSources(),
mock(ComputeNodeInstanceContext.class)).findShardingColumn("column",
"other_Table");
+ Optional<String> actual =
+ new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class),
Collections.emptyList()).findShardingColumn("column", "other_Table");
assertFalse(actual.isPresent());
}
@@ -385,7 +390,7 @@ class ShardingRuleTest {
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
shardingRuleConfig.getTables().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(new
ShardingTableReferenceRuleConfiguration("foo",
shardingTableRuleConfig.getLogicTable() + "," +
subTableRuleConfig.getLogicTable()));
- assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -397,7 +402,7 @@ class ShardingRuleTest {
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
shardingRuleConfig.getTables().add(subTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add(new
ShardingTableReferenceRuleConfiguration("foo",
shardingTableRuleConfig.getLogicTable() + "," +
subTableRuleConfig.getLogicTable()));
- assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -412,7 +417,7 @@ class ShardingRuleTest {
shardingRuleConfig.getShardingAlgorithms().put("shardingAlgorithmDB",
new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_%{ds_id % 2}"))));
subTableRuleConfig.setDatabaseShardingStrategy(new
StandardShardingStrategyConfiguration("ds_id", "subAlgorithmDB"));
shardingRuleConfig.getShardingAlgorithms().put("subAlgorithmDB", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "ds_%{ds_id % 3}"))));
- assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -429,7 +434,7 @@ class ShardingRuleTest {
subTableRuleConfig.setTableShardingStrategy(new
StandardShardingStrategyConfiguration("table_id", "subAlgorithmTBL"));
shardingRuleConfig.getShardingAlgorithms().put(
"subAlgorithmTBL", new AlgorithmConfiguration("INLINE",
PropertiesBuilder.build(new Property("algorithm-expression", "table_%{table_id
% 3}"))));
- assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -446,7 +451,7 @@ class ShardingRuleTest {
shardingRuleConfig.setDefaultTableShardingStrategy(new
StandardShardingStrategyConfiguration("table_id", "table_inline"));
shardingRuleConfig.setDefaultShardingColumn("table_id");
shardingRuleConfig.getShardingAlgorithms().put("table_inline", new
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new
Property("algorithm-expression", "table_%{table_id % 3}"))));
- assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class)));
+ assertThrows(InvalidBindingTablesException.class, () -> new
ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList()));
}
@Test
@@ -502,7 +507,7 @@ class ShardingRuleTest {
autoTableRuleConfig.setShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "hash_mod"));
shardingRuleConfig.getAutoTables().add(autoTableRuleConfig);
shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new
AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new
Property("sharding-count", "4"))));
- ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class));
+ ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
assertThat(shardingRule.getDataSourceNames(), is(new
LinkedHashSet<>(Arrays.asList("ds_0", "ds_1", "resource0", "resource1"))));
}
@@ -511,7 +516,7 @@ class ShardingRuleTest {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
- ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class));
+ ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
assertThat(shardingRule.getDataSourceNames(), is(new
LinkedHashSet<>(Arrays.asList("ds_0", "ds_1"))));
}
@@ -522,14 +527,14 @@ class ShardingRuleTest {
autoTableRuleConfig.setShardingStrategy(new
StandardShardingStrategyConfiguration("order_id", "hash_mod"));
shardingRuleConfig.getAutoTables().add(autoTableRuleConfig);
shardingRuleConfig.getShardingAlgorithms().put("hash_mod", new
AlgorithmConfiguration("hash_mod", PropertiesBuilder.build(new
Property("sharding-count", "4"))));
- ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class));
+ ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
assertThat(shardingRule.getDataSourceNames(), is(new
LinkedHashSet<>(Arrays.asList("resource0", "resource1"))));
}
@Test
void assertGetDataSourceNamesWithoutShardingTablesAndShardingAutoTables() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
- ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class));
+ ShardingRule shardingRule = new ShardingRule(shardingRuleConfig,
createDataSources(), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
assertThat(shardingRule.getDataSourceNames(), is(new
LinkedHashSet<>(Arrays.asList("ds_0", "ds_1", "resource0", "resource1"))));
}
@@ -552,14 +557,14 @@ class ShardingRuleTest {
shardingRuleConfig.getKeyGenerators().put("default", new
AlgorithmConfiguration("UUID", new Properties()));
shardingRuleConfig.getKeyGenerators().put("auto_increment", new
AlgorithmConfiguration("AUTO_INCREMENT.FIXTURE", new Properties()));
shardingRuleConfig.getAuditors().put("audit_algorithm", new
AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
private ShardingRule createMinimumShardingRule() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig =
createTableRuleConfiguration("LOGIC_TABLE", "ds_${0..1}.table_${0..2}");
shardingRuleConfig.getTables().add(shardingTableRuleConfig);
- return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
private ShardingTableRuleConfiguration createTableRuleConfiguration(final
String logicTableName, final String actualDataNodes) {
@@ -590,7 +595,8 @@ class ShardingRuleTest {
void assertFindShardingColumnForComplexShardingStrategy() {
ShardingRuleConfiguration shardingRuleConfig = new
ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(createTableRuleConfigWithComplexStrategies());
- Optional<String> actual = new ShardingRule(shardingRuleConfig,
createDataSources(),
mock(ComputeNodeInstanceContext.class)).findShardingColumn("column1",
"LOGIC_TABLE");
+ Optional<String> actual =
+ new ShardingRule(shardingRuleConfig, createDataSources(),
mock(ComputeNodeInstanceContext.class),
Collections.emptyList()).findShardingColumn("column1", "LOGIC_TABLE");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("COLUMN1"));
}
@@ -709,7 +715,7 @@ class ShardingRuleTest {
void assertIsAllTablesInSameDataSource() {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ruleConfig.getTables().add(new
ShardingTableRuleConfiguration("LOGIC_TABLE", "ds_${0}.table_${0..2}"));
- ShardingRule shardingRule = new ShardingRule(ruleConfig,
Maps.of("resource0", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class));
+ ShardingRule shardingRule = new ShardingRule(ruleConfig,
Maps.of("resource0", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
assertTrue(shardingRule.isAllTablesInSameDataSource(Collections.singleton("logic_Table")));
}
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutorTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutorTest.java
index 26ecc24bc90..d33fc4b06a1 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutorTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableNodesExecutorTest.java
@@ -72,7 +72,7 @@ class ShowShardingTableNodesExecutorTest {
Optional<ShardingRuleConfiguration> shardingRuleConfig =
ShardingRuleConfigurationConverter.findAndConvertShardingRuleConfiguration(yamlRootConfig.getRules());
assertTrue(shardingRuleConfig.isPresent());
return new ShardingRule(shardingRuleConfig.get(),
- Maps.of("ds_1", new MockedDataSource(), "ds_2", new
MockedDataSource(), "ds_3", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class));
+ Maps.of("ds_1", new MockedDataSource(), "ds_2", new
MockedDataSource(), "ds_3", new MockedDataSource()),
mock(ComputeNodeInstanceContext.class), Collections.emptyList());
}
private void assertOrder(final ShardingRule rule) throws SQLException {
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalResourceAggregator.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalDataSourceAggregator.java
similarity index 80%
rename from
infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalResourceAggregator.java
rename to
infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalDataSourceAggregator.java
index aa34579181e..1142c6ef9d5 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalResourceAggregator.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/PhysicalDataSourceAggregator.java
@@ -30,30 +30,30 @@ import java.util.Map.Entry;
import java.util.Optional;
/**
- * Physical resource aggregator.
+ * Physical data source aggregator.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PhysicalResourceAggregator {
+public final class PhysicalDataSourceAggregator {
/**
- * Get aggregated resources.
+ * Get aggregated data sources.
*
* @param dataSourceMap data source map
* @param builtRules built rules
- * @return aggregated resources
+ * @return aggregated data sources
*/
- public static Map<String, DataSource> getAggregatedResources(final
Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule>
builtRules) {
+ public static Map<String, DataSource> getAggregatedDataSources(final
Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule>
builtRules) {
Map<String, DataSource> result = new
CaseInsensitiveMap<>(dataSourceMap);
for (ShardingSphereRule each : builtRules) {
Optional<DataSourceMapperRuleAttribute> ruleAttribute =
each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class);
if (ruleAttribute.isPresent()) {
- result = getAggregatedResources(result, ruleAttribute.get());
+ result = getAggregatedDataSources(result, ruleAttribute.get());
}
}
return result;
}
- private static Map<String, DataSource> getAggregatedResources(final
Map<String, DataSource> dataSourceMap, final DataSourceMapperRuleAttribute
ruleAttribute) {
+ private static Map<String, DataSource> getAggregatedDataSources(final
Map<String, DataSource> dataSourceMap, final DataSourceMapperRuleAttribute
ruleAttribute) {
Map<String, DataSource> result = new CaseInsensitiveMap<>();
for (Entry<String, Collection<String>> entry :
ruleAttribute.getDataSourceMapper().entrySet()) {
for (String each : entry.getValue()) {
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java
index a7c2f4efe1d..bdba62d6671 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java
@@ -176,4 +176,20 @@ public final class RuleMetaData {
}
return result;
}
+
+ /**
+ * Get rule attributes.
+ *
+ * @param attributeClass rule attribute class
+ * @param <T> type of rule attributes
+ * @return rule attributes
+ */
+ public <T extends RuleAttribute> Optional<T> findAttribute(final Class<T>
attributeClass) {
+ for (ShardingSphereRule each : rules) {
+ if
(each.getAttributes().findAttribute(attributeClass).isPresent()) {
+ return each.getAttributes().findAttribute(attributeClass);
+ }
+ }
+ return Optional.empty();
+ }
}
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/aggregate/AggregatedDataSourceRuleAttribute.java
similarity index 57%
copy from
infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/aggregate/AggregatedDataSourceRuleAttribute.java
index 07873b74a05..a79864c023e 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/aggregate/AggregatedDataSourceRuleAttribute.java
@@ -15,23 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.route.engine.tableless;
+package org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.infra.route.context.RouteContext;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute;
+
+import javax.sql.DataSource;
+import java.util.Map;
/**
- * Tableless route engine.
+ * Aggregated data source rule attribute.
*/
-public interface TablelessRouteEngine {
+@RequiredArgsConstructor
+@Getter
+public final class AggregatedDataSourceRuleAttribute implements RuleAttribute {
- /**
- * Route.
- *
- * @param globalRuleMetaData global rule meta data
- * @param database database
- * @return route context
- */
- RouteContext route(RuleMetaData globalRuleMetaData, ShardingSphereDatabase
database);
+ private final Map<String, DataSource> aggregatedDataSources;
}
diff --git
a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
index b96980cd544..adb9653b444 100644
---
a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
+++
b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
@@ -29,6 +29,8 @@ import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -39,6 +41,7 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.Test;
+import javax.sql.DataSource;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
@@ -76,8 +79,18 @@ class KernelProcessorTest {
private Collection<ShardingSphereRule> mockShardingSphereRule() {
Collection<ShardingSphereRule> result = new LinkedList<>();
SQLTranslatorRule sqlTranslatorRule = mock(SQLTranslatorRule.class);
+ when(sqlTranslatorRule.getAttributes()).thenReturn(new
RuleAttributes());
when(sqlTranslatorRule.translate(any(), any(), any(), any(), any(),
any())).thenReturn(new SQLTranslatorContext("", Collections.emptyList()));
result.add(sqlTranslatorRule);
+ result.add(mockAggregatedDataSourceRule());
+ return result;
+ }
+
+ private ShardingSphereRule mockAggregatedDataSourceRule() {
+ ShardingSphereRule result = mock(ShardingSphereRule.class,
RETURNS_DEEP_STUBS);
+ AggregatedDataSourceRuleAttribute ruleAttribute =
mock(AggregatedDataSourceRuleAttribute.class);
+
when(ruleAttribute.getAggregatedDataSources()).thenReturn(Collections.singletonMap("ds_0",
mock(DataSource.class)));
+
when(result.getAttributes().findAttribute(AggregatedDataSourceRuleAttribute.class)).thenReturn(Optional.of(ruleAttribute));
return result;
}
}
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
index 07873b74a05..a7e2d4bb092 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngine.java
@@ -17,10 +17,11 @@
package org.apache.shardingsphere.infra.route.engine.tableless;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
+import java.util.Collection;
+
/**
* Tableless route engine.
*/
@@ -30,8 +31,8 @@ public interface TablelessRouteEngine {
* Route.
*
* @param globalRuleMetaData global rule meta data
- * @param database database
+ * @param aggregatedDataSources aggregated data sources
* @return route context
*/
- RouteContext route(RuleMetaData globalRuleMetaData, ShardingSphereDatabase
database);
+ RouteContext route(RuleMetaData globalRuleMetaData, Collection<String>
aggregatedDataSources);
}
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java
index ffdd319c194..785c2f1265e 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactory.java
@@ -21,10 +21,14 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CloseStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.TablelessDataSourceBroadcastRouteEngine;
import
org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.TablelessInstanceBroadcastRouteEngine;
import
org.apache.shardingsphere.infra.route.engine.tableless.type.ignore.TablelessIgnoreRouteEngine;
+import
org.apache.shardingsphere.infra.route.engine.tableless.type.unicast.unicast.TablelessDataSourceUnicastRouteEngine;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AlterResourceGroupStatement;
@@ -48,6 +52,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStat
import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropFunctionStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropSchemaStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTablespaceStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DMLStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.TCLStatement;
/**
@@ -60,24 +65,29 @@ public final class TablelessRouteEngineFactory {
* Create new instance of route engine.
*
* @param queryContext query context
+ * @param database database
* @return created instance
*/
- public static TablelessRouteEngine newInstance(final QueryContext
queryContext) {
+ public static TablelessRouteEngine newInstance(final QueryContext
queryContext, final ShardingSphereDatabase database) {
SQLStatement sqlStatement =
queryContext.getSqlStatementContext().getSqlStatement();
+ // TODO remove this logic when proxy and jdbc support all dal
statement @duanzhengqiang
if (sqlStatement instanceof DALStatement) {
- return getDALRouteEngine(sqlStatement);
+ return getDALRouteEngine(sqlStatement, database);
}
// TODO remove this logic when savepoint handle in proxy and jdbc
adapter @zhangcheng
if (sqlStatement instanceof TCLStatement) {
return new TablelessDataSourceBroadcastRouteEngine();
}
if (sqlStatement instanceof DDLStatement) {
- return getDDLRouteEngine(queryContext.getSqlStatementContext());
+ return getDDLRouteEngine(queryContext.getSqlStatementContext(),
database);
+ }
+ if (sqlStatement instanceof DMLStatement) {
+ return getDMLRouteEngine(queryContext.getSqlStatementContext(),
queryContext.getConnectionContext());
}
return new TablelessIgnoreRouteEngine();
}
- private static TablelessRouteEngine getDALRouteEngine(final SQLStatement
sqlStatement) {
+ private static TablelessRouteEngine getDALRouteEngine(final SQLStatement
sqlStatement, final ShardingSphereDatabase database) {
if (sqlStatement instanceof ShowTablesStatement || sqlStatement
instanceof ShowTableStatusStatement || sqlStatement instanceof SetStatement) {
return new TablelessDataSourceBroadcastRouteEngine();
}
@@ -85,7 +95,7 @@ public final class TablelessRouteEngineFactory {
return new TablelessDataSourceBroadcastRouteEngine();
}
if (isResourceGroupStatement(sqlStatement)) {
- return new TablelessInstanceBroadcastRouteEngine();
+ return new TablelessInstanceBroadcastRouteEngine(database);
}
return new TablelessIgnoreRouteEngine();
}
@@ -95,9 +105,9 @@ public final class TablelessRouteEngineFactory {
|| sqlStatement instanceof SetResourceGroupStatement;
}
- private static TablelessRouteEngine getDDLRouteEngine(final
SQLStatementContext sqlStatementContext) {
+ private static TablelessRouteEngine getDDLRouteEngine(final
SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database)
{
if (sqlStatementContext instanceof CursorAvailable) {
- return getCursorRouteEngine(sqlStatementContext);
+ return getCursorRouteEngine(sqlStatementContext, database);
}
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
if (isFunctionDDLStatement(sqlStatement) ||
isSchemaDDLStatement(sqlStatement)) {
@@ -114,13 +124,20 @@ public final class TablelessRouteEngineFactory {
return sqlStatement instanceof CreateSchemaStatement || sqlStatement
instanceof AlterSchemaStatement || sqlStatement instanceof DropSchemaStatement;
}
- private static TablelessRouteEngine getCursorRouteEngine(final
SQLStatementContext sqlStatementContext) {
+ private static TablelessRouteEngine getCursorRouteEngine(final
SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database)
{
if (sqlStatementContext instanceof CloseStatementContext &&
((CloseStatementContext) sqlStatementContext).getSqlStatement().isCloseAll()) {
return new TablelessDataSourceBroadcastRouteEngine();
}
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
if (sqlStatement instanceof CreateTablespaceStatement || sqlStatement
instanceof AlterTablespaceStatement || sqlStatement instanceof
DropTablespaceStatement) {
- return new TablelessInstanceBroadcastRouteEngine();
+ return new TablelessInstanceBroadcastRouteEngine(database);
+ }
+ return new TablelessIgnoreRouteEngine();
+ }
+
+ private static TablelessRouteEngine getDMLRouteEngine(final
SQLStatementContext sqlStatementContext, final ConnectionContext
connectionContext) {
+ if (sqlStatementContext instanceof SelectStatementContext) {
+ return new
TablelessDataSourceUnicastRouteEngine(connectionContext);
}
return new TablelessIgnoreRouteEngine();
}
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/router/TablelessSQLRouter.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/router/TablelessSQLRouter.java
index a0ad0b13b30..7b6db6aa005 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/router/TablelessSQLRouter.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/router/TablelessSQLRouter.java
@@ -17,10 +17,12 @@
package org.apache.shardingsphere.infra.route.engine.tableless.router;
+import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.infra.route.engine.tableless.TablelessRouteEngineFactory;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import java.util.Collection;
@@ -43,8 +45,15 @@ public final class TablelessSQLRouter {
public RouteContext route(final QueryContext queryContext, final
RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database,
final Collection<String> tableNames, final
RouteContext routeContext) {
if (tableNames.isEmpty() && routeContext.getRouteUnits().isEmpty()) {
- return
TablelessRouteEngineFactory.newInstance(queryContext).route(globalRuleMetaData,
database);
+ Collection<String> aggregatedDataSources =
getAggregatedDataSources(database);
+ return TablelessRouteEngineFactory.newInstance(queryContext,
database).route(globalRuleMetaData, aggregatedDataSources);
}
return routeContext;
}
+
+ private Collection<String> getAggregatedDataSources(final
ShardingSphereDatabase database) {
+ Collection<AggregatedDataSourceRuleAttribute> attributes =
database.getRuleMetaData().getAttributes(AggregatedDataSourceRuleAttribute.class);
+ ShardingSpherePreconditions.checkNotEmpty(attributes, () -> new
UnsupportedOperationException("Can not find aggregated data source"));
+ return
attributes.iterator().next().getAggregatedDataSources().keySet();
+ }
}
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessDataSourceBroadcastRouteEngine.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessDataSourceBroadcastRouteEngine.java
index b0a87f65144..307f6bdf784 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessDataSourceBroadcastRouteEngine.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessDataSourceBroadcastRouteEngine.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
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.infra.route.engine.tableless.TablelessRouteEngine;
+import java.util.Collection;
import java.util.Collections;
/**
@@ -32,9 +32,9 @@ import java.util.Collections;
public final class TablelessDataSourceBroadcastRouteEngine implements
TablelessRouteEngine {
@Override
- public RouteContext route(final RuleMetaData globalRuleMetaData, final
ShardingSphereDatabase database) {
+ public RouteContext route(final RuleMetaData globalRuleMetaData, final
Collection<String> aggregatedDataSources) {
RouteContext result = new RouteContext();
- for (String each :
database.getResourceMetaData().getStorageUnits().keySet()) {
+ for (String each : aggregatedDataSources) {
result.getRouteUnits().add(new RouteUnit(new RouteMapper(each,
each), Collections.emptyList()));
}
return result;
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
index c160dadecb9..e1bf67935ae 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import
org.apache.shardingsphere.infra.route.engine.tableless.TablelessRouteEngine;
+import java.util.Collection;
import java.util.Collections;
/**
@@ -33,8 +34,10 @@ import java.util.Collections;
@RequiredArgsConstructor
public final class TablelessInstanceBroadcastRouteEngine implements
TablelessRouteEngine {
+ private final ShardingSphereDatabase database;
+
@Override
- public RouteContext route(final RuleMetaData globalRuleMetaData, final
ShardingSphereDatabase database) {
+ public RouteContext route(final RuleMetaData globalRuleMetaData, final
Collection<String> aggregatedDataSources) {
RouteContext result = new RouteContext();
for (String each :
database.getResourceMetaData().getAllInstanceDataSourceNames()) {
result.getRouteUnits().add(new RouteUnit(new RouteMapper(each,
each), Collections.emptyList()));
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/ignore/TablelessIgnoreRouteEngine.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/ignore/TablelessIgnoreRouteEngine.java
index 060a3345cbf..132bdd6d17f 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/ignore/TablelessIgnoreRouteEngine.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/ignore/TablelessIgnoreRouteEngine.java
@@ -17,18 +17,19 @@
package org.apache.shardingsphere.infra.route.engine.tableless.type.ignore;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.infra.route.engine.tableless.TablelessRouteEngine;
+import java.util.Collection;
+
/**
* Tableless ignore route engine.
*/
public final class TablelessIgnoreRouteEngine implements TablelessRouteEngine {
@Override
- public RouteContext route(final RuleMetaData globalRuleMetaData, final
ShardingSphereDatabase database) {
+ public RouteContext route(final RuleMetaData globalRuleMetaData, final
Collection<String> aggregatedDataSources) {
return new RouteContext();
}
}
diff --git
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/unicast/unicast/TablelessDataSourceUnicastRouteEngine.java
similarity index 53%
copy from
infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
copy to
infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/unicast/unicast/TablelessDataSourceUnicastRouteEngine.java
index c160dadecb9..39d6381c6d3 100644
---
a/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/broadcast/TablelessInstanceBroadcastRouteEngine.java
+++
b/infra/route/src/main/java/org/apache/shardingsphere/infra/route/engine/tableless/type/unicast/unicast/TablelessDataSourceUnicastRouteEngine.java
@@ -15,30 +15,46 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast;
+package
org.apache.shardingsphere.infra.route.engine.tableless.type.unicast.unicast;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
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.infra.route.engine.tableless.TablelessRouteEngine;
+import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
/**
- * Tableless instance broadcast route engine.
+ * Tableless datasource unicast route engine.
*/
@RequiredArgsConstructor
-public final class TablelessInstanceBroadcastRouteEngine implements
TablelessRouteEngine {
+public final class TablelessDataSourceUnicastRouteEngine implements
TablelessRouteEngine {
+
+ private final ConnectionContext connectionContext;
@Override
- public RouteContext route(final RuleMetaData globalRuleMetaData, final
ShardingSphereDatabase database) {
+ public RouteContext route(final RuleMetaData globalRuleMetaData, final
Collection<String> aggregatedDataSources) {
RouteContext result = new RouteContext();
- for (String each :
database.getResourceMetaData().getAllInstanceDataSourceNames()) {
- result.getRouteUnits().add(new RouteUnit(new RouteMapper(each,
each), Collections.emptyList()));
- }
+ RouteMapper dataSourceMapper =
getDataSourceRouteMapper(aggregatedDataSources);
+ result.getRouteUnits().add(new RouteUnit(dataSourceMapper,
Collections.emptyList()));
return result;
}
+
+ private RouteMapper getDataSourceRouteMapper(final Collection<String>
dataSourceNames) {
+ String dataSourceName = getRandomDataSourceName(dataSourceNames);
+ return new RouteMapper(dataSourceName, dataSourceName);
+ }
+
+ private String getRandomDataSourceName(final Collection<String>
dataSourceNames) {
+ Collection<String> usedDataSourceNames =
connectionContext.getUsedDataSourceNames();
+ List<String> availableDataSourceNames = new
ArrayList<>(usedDataSourceNames.isEmpty() ? dataSourceNames :
usedDataSourceNames);
+ return
availableDataSourceNames.get(ThreadLocalRandom.current().nextInt(availableDataSourceNames.size()));
+ }
}
diff --git
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
index f5c0e2095ea..51745cb3a55 100644
---
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
+++
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
@@ -29,6 +29,7 @@ import
org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.infra.route.fixture.rule.DataSourceRouteRuleFixture;
import
org.apache.shardingsphere.infra.route.fixture.rule.TableRouteRuleFixture;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.junit.jupiter.api.BeforeEach;
@@ -38,6 +39,7 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -129,6 +131,9 @@ class SQLRouteEngineTest {
SQLRouteEngine sqlRouteEngine = new
SQLRouteEngine(Collections.emptyList(), new ConfigurationProperties(new
Properties()));
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), connectionContext, metaData);
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("ds_0",
mock(StorageUnit.class)));
+ AggregatedDataSourceRuleAttribute ruleAttribute =
mock(AggregatedDataSourceRuleAttribute.class);
+
when(ruleAttribute.getAggregatedDataSources()).thenReturn(Collections.singletonMap("ds_0",
mock(DataSource.class)));
+
when(database.getRuleMetaData().getAttributes(AggregatedDataSourceRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
RouteContext routeContext = sqlRouteEngine.route(queryContext,
mock(RuleMetaData.class), database);
assertThat(routeContext.getRouteUnits().size(), is(1));
assertThat(routeContext.getRouteUnits().iterator().next().getDataSourceMapper().getActualName(),
is("ds_0"));
diff --git
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/router/TablelessSQLRouterTest.java
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/router/TablelessSQLRouterTest.java
index db8dd14d99c..604aea42cc9 100644
---
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/router/TablelessSQLRouterTest.java
+++
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/router/TablelessSQLRouterTest.java
@@ -23,6 +23,7 @@ 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.infra.route.engine.tableless.router.TablelessSQLRouter;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -30,11 +31,14 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import javax.sql.DataSource;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class TablelessSQLRouterTest {
@@ -45,11 +49,14 @@ class TablelessSQLRouterTest {
@Mock
private RuleMetaData ruleMetaData;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
@Test
void assertRouteWhenTableNameRouteUnitIsAllEmpty() {
+ AggregatedDataSourceRuleAttribute ruleAttribute =
mock(AggregatedDataSourceRuleAttribute.class);
+
when(ruleAttribute.getAggregatedDataSources()).thenReturn(Collections.singletonMap("ds_0",
mock(DataSource.class)));
+
when(database.getRuleMetaData().getAttributes(AggregatedDataSourceRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
RouteContext actual = new TablelessSQLRouter().route(queryContext,
ruleMetaData, database, Collections.emptyList(), new RouteContext());
assertTrue(actual.getOriginalDataNodes().isEmpty());
assertTrue(actual.getRouteUnits().isEmpty());
diff --git
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
index df0ac9d6a8c..13f71e9dc82 100644
---
a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
+++
b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
@@ -20,17 +20,21 @@ package
org.apache.shardingsphere.infra.route.engine.tableless;
import
org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CloseStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.TablelessDataSourceBroadcastRouteEngine;
import
org.apache.shardingsphere.infra.route.engine.tableless.type.broadcast.TablelessInstanceBroadcastRouteEngine;
+import
org.apache.shardingsphere.infra.route.engine.tableless.type.unicast.unicast.TablelessDataSourceUnicastRouteEngine;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.DALStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterSchemaStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateSchemaStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropSchemaStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.tcl.TCLStatement;
import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLCreateResourceGroupStatement;
import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLSetResourceGroupStatement;
@@ -66,6 +70,9 @@ class TablelessRouteEngineFactoryTest {
@Mock
private TablesContext tablesContext;
+ @Mock
+ private ShardingSphereDatabase database;
+
@BeforeEach
void setUp() {
when(((TableAvailable)
sqlStatementContext).getTablesContext()).thenReturn(tablesContext);
@@ -83,7 +90,7 @@ class TablelessRouteEngineFactoryTest {
MySQLSetResourceGroupStatement resourceGroupStatement =
mock(MySQLSetResourceGroupStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(resourceGroupStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext,
mock(ShardingSphereDatabase.class));
assertThat(actual,
instanceOf(TablelessInstanceBroadcastRouteEngine.class));
}
@@ -92,7 +99,7 @@ class TablelessRouteEngineFactoryTest {
DALStatement dalStatement = mock(MySQLShowDatabasesStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
@@ -106,7 +113,7 @@ class TablelessRouteEngineFactoryTest {
TCLStatement tclStatement = mock(TCLStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(tclStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
@@ -118,7 +125,7 @@ class TablelessRouteEngineFactoryTest {
private void assertNewInstanceForDALSet(final DALStatement dalStatement) {
when(sqlStatementContext.getSqlStatement()).thenReturn(dalStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
@@ -127,7 +134,7 @@ class TablelessRouteEngineFactoryTest {
MySQLCreateResourceGroupStatement resourceGroupStatement =
mock(MySQLCreateResourceGroupStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(resourceGroupStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessInstanceBroadcastRouteEngine.class));
}
@@ -139,7 +146,7 @@ class TablelessRouteEngineFactoryTest {
when(closeStatementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
when(closeStatementContext.getSqlStatement()).thenReturn(closeStatement);
QueryContext queryContext = new QueryContext(closeStatementContext,
"", Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
@@ -147,7 +154,7 @@ class TablelessRouteEngineFactoryTest {
void assertNewInstanceForCreateSchemaStatement() {
QueryContext queryContext = mock(QueryContext.class,
RETURNS_DEEP_STUBS);
when(queryContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(CreateSchemaStatement.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
@@ -155,7 +162,7 @@ class TablelessRouteEngineFactoryTest {
void assertNewInstanceForAlterSchemaStatement() {
QueryContext queryContext = mock(QueryContext.class,
RETURNS_DEEP_STUBS);
when(queryContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(AlterSchemaStatement.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
@@ -163,7 +170,16 @@ class TablelessRouteEngineFactoryTest {
void assertNewInstanceForDropSchemaStatement() {
QueryContext queryContext = mock(QueryContext.class,
RETURNS_DEEP_STUBS);
when(queryContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(DropSchemaStatement.class));
- TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext);
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
assertThat(actual,
instanceOf(TablelessDataSourceBroadcastRouteEngine.class));
}
+
+ @Test
+ void assertNewInstanceForSelectStatement() {
+ QueryContext queryContext = mock(QueryContext.class,
RETURNS_DEEP_STUBS);
+
when(queryContext.getSqlStatementContext()).thenReturn(mock(SelectStatementContext.class));
+
when(queryContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(SelectStatement.class));
+ TablelessRouteEngine actual =
TablelessRouteEngineFactory.newInstance(queryContext, database);
+ assertThat(actual,
instanceOf(TablelessDataSourceUnicastRouteEngine.class));
+ }
}
diff --git
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
index 722e6b02e05..895439242c5 100644
---
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
+++
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
@@ -106,7 +106,7 @@ class ShardingSphereDatabaseMetaDataTest {
ShardingRuleConfiguration ruleConfig = new ShardingRuleConfiguration();
ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration(TABLE_NAME, DATA_SOURCE_NAME + "." + TABLE_NAME);
ruleConfig.setTables(Collections.singleton(shardingTableRuleConfig));
- return new ShardingRule(ruleConfig, Maps.of(DATA_SOURCE_NAME, new
MockedDataSource()), mock(ComputeNodeInstanceContext.class));
+ return new ShardingRule(ruleConfig, Maps.of(DATA_SOURCE_NAME, new
MockedDataSource()), mock(ComputeNodeInstanceContext.class),
Collections.emptyList());
}
@Test
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index 78e4cdb3911..908d51be858 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -23,7 +23,7 @@ import
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.constant.SingleTableConstants;
@@ -63,7 +63,7 @@ public final class SingleRuleConfigurationDecorator
implements RuleConfiguration
if (!isExpandRequired(splitTables)) {
return splitTables;
}
- Map<String, DataSource> aggregatedDataSources =
PhysicalResourceAggregator.getAggregatedResources(dataSources, builtRules);
+ Map<String, DataSource> aggregatedDataSources =
PhysicalDataSourceAggregator.getAggregatedDataSources(dataSources, builtRules);
DatabaseType databaseType = dataSources.isEmpty() ?
DatabaseTypeEngine.getDefaultStorageType() :
DatabaseTypeEngine.getStorageType(dataSources.values().iterator().next());
Collection<String> excludedTables =
SingleTableLoadUtils.getExcludedTables(builtRules);
Map<String, Collection<DataNode>> actualDataNodes =
SingleTableDataNodeLoader.load(databaseName, aggregatedDataSources,
excludedTables);
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
index 24523813990..53aef4832ae 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
@@ -36,6 +36,7 @@ import
org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.single.constant.SingleOrder;
import org.apache.shardingsphere.single.route.engine.SingleRouteEngine;
import org.apache.shardingsphere.single.rule.SingleRule;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement;
import java.util.Collection;
import java.util.Collections;
@@ -101,7 +102,7 @@ public final class SingleSQLRouter implements
EntranceSQLRouter<SingleRule>, Dec
result.add(each);
}
}
- return result;
+ return sqlStatementContext.getSqlStatement() instanceof
CreateTableStatement ? result : rule.getSingleTables(result);
}
private Collection<String> getDistributedTableNames(final
ShardingSphereDatabase database) {
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
index c84acb585ce..50211a03eb3 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
@@ -26,11 +26,13 @@ import
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
import
org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
+import
org.apache.shardingsphere.infra.rule.attribute.datasource.aggregate.AggregatedDataSourceRuleAttribute;
import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.constant.SingleOrder;
@@ -69,17 +71,18 @@ public final class SingleRule implements DatabaseRule {
private final RuleAttributes attributes;
public SingleRule(final SingleRuleConfiguration ruleConfig, final String
databaseName,
- final DatabaseType protocolType, final Map<String,
DataSource> dataSourceMap, final Collection<ShardingSphereRule> builtRules) {
+ final DatabaseType protocolType, final Map<String,
DataSource> dataSources, final Collection<ShardingSphereRule> builtRules) {
configuration = ruleConfig;
defaultDataSource = ruleConfig.getDefaultDataSource().orElse(null);
- Map<String, DataSource> aggregateDataSourceMap =
PhysicalResourceAggregator.getAggregatedResources(dataSourceMap, builtRules);
- dataSourceNames = new
CaseInsensitiveSet<>(aggregateDataSourceMap.keySet());
+ Map<String, DataSource> aggregatedDataSources = new
RuleMetaData(builtRules).findAttribute(AggregatedDataSourceRuleAttribute.class)
+
.map(AggregatedDataSourceRuleAttribute::getAggregatedDataSources).orElseGet(()
-> PhysicalDataSourceAggregator.getAggregatedDataSources(dataSources,
builtRules));
+ dataSourceNames = new
CaseInsensitiveSet<>(aggregatedDataSources.keySet());
this.protocolType = protocolType;
- singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName,
protocolType, aggregateDataSourceMap, builtRules, configuration.getTables());
+ singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName,
protocolType, aggregatedDataSources, builtRules, configuration.getTables());
SingleTableMapperRuleAttribute tableMapperRuleAttribute = new
SingleTableMapperRuleAttribute(singleTableDataNodes.values());
mutableDataNodeRuleAttribute = new
SingleMutableDataNodeRuleAttribute(configuration, dataSourceNames,
singleTableDataNodes, protocolType, tableMapperRuleAttribute);
- attributes = new RuleAttributes(
- new SingleDataNodeRuleAttribute(singleTableDataNodes),
tableMapperRuleAttribute, new
SingleExportableRuleAttribute(tableMapperRuleAttribute),
mutableDataNodeRuleAttribute);
+ attributes = new RuleAttributes(new
SingleDataNodeRuleAttribute(singleTableDataNodes), tableMapperRuleAttribute,
+ new SingleExportableRuleAttribute(tableMapperRuleAttribute),
mutableDataNodeRuleAttribute, new
AggregatedDataSourceRuleAttribute(aggregatedDataSources));
}
/**
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
index 72b4fe68d3c..a9ca2dcc080 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTablesExecutor.java
@@ -24,7 +24,7 @@ import
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecut
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -67,7 +67,7 @@ public final class ShowUnloadedSingleTablesExecutor
implements DistSQLQueryExecu
private Map<String, Collection<DataNode>> getActualDataNodes(final
ShardingSphereDatabase database) {
ResourceMetaData resourceMetaData = database.getResourceMetaData();
- Map<String, DataSource> aggregateDataSourceMap =
PhysicalResourceAggregator.getAggregatedResources(
+ Map<String, DataSource> aggregateDataSourceMap =
PhysicalDataSourceAggregator.getAggregatedDataSources(
resourceMetaData.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry ->
entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new)),
database.getRuleMetaData().getRules());
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
index 644adff1042..b1157fc4419 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
@@ -30,7 +30,7 @@ import
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storag
import
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.InvalidStorageUnitStatusException;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
@@ -113,7 +113,7 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
private void checkShouldExistActualTables(final LoadSingleTableStatement
sqlStatement, final Collection<String> storageUnitNames, final String
defaultSchemaName) {
Map<String, DataSource> dataSourceMap =
database.getResourceMetaData().getStorageUnits().entrySet()
.stream().collect(Collectors.toMap(Entry::getKey, entry ->
entry.getValue().getDataSource()));
- Map<String, DataSource> aggregatedDataSourceMap =
PhysicalResourceAggregator.getAggregatedResources(dataSourceMap,
database.getRuleMetaData().getRules());
+ Map<String, DataSource> aggregatedDataSourceMap =
PhysicalDataSourceAggregator.getAggregatedDataSources(dataSourceMap,
database.getRuleMetaData().getRules());
Collection<String> invalidDataSources =
storageUnitNames.stream().filter(each ->
!aggregatedDataSourceMap.containsKey(each)).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(invalidDataSources.isEmpty(),
() -> new InvalidStorageUnitStatusException(String.format("`%s` is invalid,
please use `%s`",
String.join(",", invalidDataSources), String.join(",",
aggregatedDataSourceMap.keySet()))));
diff --git
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
index c5c3d8ce1fe..17c3edf0c9d 100644
---
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
+++
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
@@ -25,7 +25,7 @@ import
org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundEx
import
org.apache.shardingsphere.infra.exception.kernel.metadata.datanode.InvalidDataNodeFormatException;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalResourceAggregator;
+import
org.apache.shardingsphere.infra.metadata.database.resource.PhysicalDataSourceAggregator;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -66,7 +66,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
-@StaticMockSettings({SingleTableDataNodeLoader.class,
SingleTableLoadUtils.class, PhysicalResourceAggregator.class})
+@StaticMockSettings({SingleTableDataNodeLoader.class,
SingleTableLoadUtils.class, PhysicalDataSourceAggregator.class})
@MockitoSettings(strictness = Strictness.LENIENT)
class LoadSingleTableExecutorTest {
@@ -125,7 +125,7 @@ class LoadSingleTableExecutorTest {
StorageUnit storageUnit = mock(StorageUnit.class);
when(storageUnit.getDataSource()).thenReturn(new MockedDataSource());
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("foo_ds",
storageUnit));
- when(PhysicalResourceAggregator.getAggregatedResources(any(),
any())).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
+ when(PhysicalDataSourceAggregator.getAggregatedDataSources(any(),
any())).thenReturn(Collections.singletonMap("foo_ds", new MockedDataSource()));
LoadSingleTableStatement sqlStatement = new
LoadSingleTableStatement(Collections.singleton(new SingleTableSegment("foo_ds",
"foo_tbl")));
assertThrows(TableNotFoundException.class, () -> new
DistSQLUpdateExecuteEngine(sqlStatement, "foo_db",
mockContextManager(mock(SingleRule.class))).executeUpdate());
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
index 9df98fe3b29..7d49a7ac639 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
@@ -51,6 +51,7 @@ import java.net.URL;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -142,6 +143,7 @@ class ImportDatabaseConfigurationExecutorTest {
when(database.getName()).thenReturn(databaseName);
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class);
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
+ when(database.getRuleMetaData().getRules()).thenReturn(new
LinkedList<>());
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
StorageUnit storageUnit = mock(StorageUnit.class);
DataSource dataSource = new MockedDataSource();
diff --git
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java
index b6eb8ed5058..9a7a6a46930 100644
---
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java
+++
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/engine/type/DALE2EIT.java
@@ -21,11 +21,11 @@ import
org.apache.shardingsphere.infra.util.datetime.DateTimeFormatterFactory;
import org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetColumn;
import
org.apache.shardingsphere.test.e2e.cases.dataset.metadata.DataSetMetaData;
import org.apache.shardingsphere.test.e2e.cases.dataset.row.DataSetRow;
-import org.apache.shardingsphere.test.e2e.env.E2EEnvironmentAware;
-import org.apache.shardingsphere.test.e2e.env.E2EEnvironmentEngine;
import
org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseArgumentsProvider;
import org.apache.shardingsphere.test.e2e.engine.arg.E2ETestCaseSettings;
import org.apache.shardingsphere.test.e2e.engine.context.E2ETestContext;
+import org.apache.shardingsphere.test.e2e.env.E2EEnvironmentAware;
+import org.apache.shardingsphere.test.e2e.env.E2EEnvironmentEngine;
import
org.apache.shardingsphere.test.e2e.framework.param.array.E2ETestParameterFactory;
import
org.apache.shardingsphere.test.e2e.framework.param.model.AssertionTestParameter;
import org.apache.shardingsphere.test.e2e.framework.type.SQLCommandType;
@@ -70,7 +70,7 @@ class DALE2EIT implements E2EEnvironmentAware {
}
private void assertExecute(final E2ETestContext context) throws
SQLException {
- try (Connection connection =
this.environmentSetupEngine.getTargetDataSource().getConnection()) {
+ try (Connection connection =
environmentSetupEngine.getTargetDataSource().getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute(context.getSQL());
assertExecuteResult(context, statement);
@@ -92,7 +92,10 @@ class DALE2EIT implements E2EEnvironmentAware {
}
private void assertResultSet(final E2ETestContext context, final ResultSet
resultSet) throws SQLException {
- assertMetaData(resultSet.getMetaData(), getExpectedColumns(context));
+ // TODO fix wrong column label when execuete SHOW TABLES with jdbc
adapter
+ if (!"SHOW TABLES".equalsIgnoreCase(context.getSQL())) {
+ assertMetaData(resultSet.getMetaData(),
getExpectedColumns(context));
+ }
assertRows(resultSet, context.getDataSet().getRows());
}
@@ -145,6 +148,9 @@ class DALE2EIT implements E2EEnvironmentAware {
}
private void assertObjectValue(final ResultSet actual, final int
columnIndex, final String columnLabel, final String expected) throws
SQLException {
+ if (E2ETestContext.NOT_VERIFY_FLAG.equals(expected)) {
+ return;
+ }
assertThat(String.valueOf(actual.getObject(columnIndex)),
is(expected));
assertThat(String.valueOf(actual.getObject(columnLabel)),
is(expected));
}
diff --git
a/test/e2e/sql/src/test/resources/cases/dal/dataset/dbtbl_with_readwrite_splitting/mysql/show_table_status.xml
b/test/e2e/sql/src/test/resources/cases/dal/dataset/dbtbl_with_readwrite_splitting/mysql/show_table_status.xml
new file mode 100644
index 00000000000..2703f68208a
--- /dev/null
+++
b/test/e2e/sql/src/test/resources/cases/dal/dataset/dbtbl_with_readwrite_splitting/mysql/show_table_status.xml
@@ -0,0 +1,47 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="Name" />
+ <column name="Engine" />
+ <column name="Version" />
+ <column name="Row_format" />
+ <column name="Rows" />
+ <column name="Avg_row_length" />
+ <column name="Data_length" />
+ <column name="Max_data_length" />
+ <column name="Index_length" />
+ <column name="Data_free" />
+ <column name="Auto_increment" />
+ <column name="Create_time" />
+ <column name="Update_time" />
+ <column name="Check_time" />
+ <column name="Collation" />
+ <column name="Checksum" />
+ <column name="Create_options" />
+ <column name="Comment" />
+ </metadata>
+ <row values="t_country, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0, 0, 0,
null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_order, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0, 0, 0,
null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_order_item, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0, 0, 0,
null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_product, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0, 0, 0,
null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_product_category, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0,
0, 0, null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_user, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0, 0, 0, null,
NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_merchant, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0, 0, 0,
null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+ <row values="t_product_detail, InnoDB, 10, Dynamic, 0, 0, NOT_VERIFY, 0,
0, 0, null, NOT_VERIFY, null, null, utf8mb3_general_ci, null, , " />
+</dataset>
diff --git a/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
b/test/e2e/sql/src/test/resources/cases/dal/dataset/dbtbl_with_readwrite_splitting/mysql/show_tables.xml
similarity index 64%
copy from test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
copy to
test/e2e/sql/src/test/resources/cases/dal/dataset/dbtbl_with_readwrite_splitting/mysql/show_tables.xml
index ba55ccaec8d..1fe53aee2e2 100644
--- a/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
+++
b/test/e2e/sql/src/test/resources/cases/dal/dataset/dbtbl_with_readwrite_splitting/mysql/show_tables.xml
@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
@@ -16,11 +15,16 @@
~ limitations under the License.
-->
-<e2e-test-cases>
- <!-- TODO support set variable statement for proxy adapter in issue #24124
-->
- <test-case sql="SET @order_id := 1, @item_id := 2" db-types="MySQL"
scenario-types="db,tbl,readwrite_splitting,encrypt,shadow" adapters="jdbc">
- <assertion expected-data-file="select_session_variables.xml">
- <assertion-sql sql="SELECT @order_id, @item_id" />
- </assertion>
- </test-case>
-</e2e-test-cases>
+<dataset>
+ <metadata>
+ <column name="Tables_in_dbtbl_with_readwrite_splitting" />
+ </metadata>
+ <row values="t_country" />
+ <row values="t_order" />
+ <row values="t_order_item" />
+ <row values="t_product" />
+ <row values="t_product_category" />
+ <row values="t_user" />
+ <row values="t_merchant" />
+ <row values="t_product_detail" />
+</dataset>
diff --git a/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
b/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
index ba55ccaec8d..ff29228004d 100644
--- a/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
+++ b/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-set.xml
@@ -20,7 +20,7 @@
<!-- TODO support set variable statement for proxy adapter in issue #24124
-->
<test-case sql="SET @order_id := 1, @item_id := 2" db-types="MySQL"
scenario-types="db,tbl,readwrite_splitting,encrypt,shadow" adapters="jdbc">
<assertion expected-data-file="select_session_variables.xml">
- <assertion-sql sql="SELECT @order_id, @item_id" />
+ <assertion-sql sql="/* SHARDINGSPHERE_HINT: WRITE_ROUTE_ONLY=true
*/SELECT @order_id, @item_id" />
</assertion>
</test-case>
</e2e-test-cases>
diff --git a/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-show.xml
b/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-show.xml
index 7b23e2159c3..8ee7753d799 100644
--- a/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-show.xml
+++ b/test/e2e/sql/src/test/resources/cases/dal/e2e-dal-show.xml
@@ -20,14 +20,25 @@
<test-case sql="SHOW DATABASES" db-types="MySQL"
scenario-types="dbtbl_with_readwrite_splitting,readwrite_splitting,dbtbl_with_readwrite_splitting_and_encrypt,sharding_and_encrypt,encrypt_and_readwrite_splitting"
adapters="proxy">
<assertion expected-data-file="show_databases.xml" />
</test-case>
+
+ <test-case sql="SHOW TABLES" db-types="MySQL"
scenario-types="dbtbl_with_readwrite_splitting" adapters="jdbc">
+ <assertion expected-data-file="show_tables.xml" />
+ </test-case>
+
+ <test-case sql="SHOW TABLE STATUS" db-types="MySQL"
scenario-types="dbtbl_with_readwrite_splitting" adapters="jdbc">
+ <assertion expected-data-file="show_table_status.xml" />
+ </test-case>
+
<test-case sql="CREATE VIEW t_order_sharding_view AS SELECT o.* FROM
t_order o INNER JOIN t_order_item i ON o.order_id = i.order_id"
db-types="MySQL" scenario-types="db,tbl">
<assertion expected-data-file="show_create_table_with_view.xml">
<assertion-sql sql="SHOW CREATE TABLE t_order_sharding_view" />
</assertion>
</test-case>
+
<test-case db-types="MySQL" scenario-types="passthrough" adapters="proxy"
sql="SELECT @@activate_all_roles_on_login, @@admin_address, @@admin_port,
@@admin_ssl_ca, @@admin_ssl_capath, @@admin_ssl_cert, @@admin_ssl_cipher,
@@admin_ssl_crl, @@admin_ssl_crlpath, @@admin_ssl_key,
@@admin_tls_ciphersuites, @@admin_tls_version, @@authentication_policy,
@@auto_generate_certs, @@auto_increment_increment, @@auto_increment_offset,
@@autocommit, @@automatic_sp_privileges, @@avoid_temporal_upgra [...]
<assertion expected-data-file="select_system_variables.xml" />
</test-case>
+
<test-case db-types="MySQL" scenario-types="passthrough" adapters="proxy"
sql="SELECT @@global.activate_all_roles_on_login AS
activate_all_roles_on_login, @@global.admin_address AS admin_address,
@@global.admin_port AS admin_port, @@global.admin_ssl_ca AS admin_ssl_ca,
@@global.admin_ssl_capath AS admin_ssl_capath, @@global.admin_ssl_cert AS
admin_ssl_cert, @@global.admin_ssl_cipher AS admin_ssl_cipher,
@@global.admin_ssl_crl AS admin_ssl_crl, @@global.admin_ssl_crlpath AS
admin_ssl_ [...]
<assertion
expected-data-file="select_aliased_system_variables_with_scope.xml" />
</test-case>