strongduanmu commented on a change in pull request #11345:
URL: https://github.com/apache/shardingsphere/pull/11345#discussion_r673878349



##########
File path: 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -130,15 +141,30 @@ private static void appendRemainTables(final 
SchemaBuilderMaterials materials, f
         return Optional.empty();
     }
     
-    private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader dialectLoader, final SchemaBuilderMaterials 
materials, final Map<String, TableMetaData> tables) throws SQLException {
+    private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader dialectLoader,
+            final SchemaBuilderMaterials materials, final Map<String, 
TableMetaData> tables, final Collection<String> ruleLogicTables) throws 
SQLException {
+
+        Map<String, String> actualTable2LogicTableMap = 
getActualTable2LogicTableMap(materials, ruleLogicTables);
+
         Collection<Future<Map<String, TableMetaData>>> futures = new 
LinkedList<>();
-        Collection<String> existedTables = 
getExistedTables(materials.getRules(), tables);
         for (DataSource each : materials.getDataSourceMap().values()) {
-            futures.add(EXECUTOR_SERVICE.submit(() -> dialectLoader.load(each, 
existedTables)));
+            futures.add(EXECUTOR_SERVICE.submit(() -> dialectLoader.load(each, 
Collections.emptyList())));
         }
         for (Future<Map<String, TableMetaData>> each : futures) {
             try {
-                tables.putAll(each.get());
+                Map<String, TableMetaData> tableMetaMap = each.get();
+                for (Map.Entry<String, TableMetaData> one : 
tableMetaMap.entrySet()) {
+                    String actualTableName = one.getKey();
+                    String logicTableName = 
actualTable2LogicTableMap.get(actualTableName);

Review comment:
       Maybe it's better to extract this code into a method.

##########
File path: 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -130,15 +137,30 @@ private static void appendRemainTables(final 
SchemaBuilderMaterials materials, f
         return Optional.empty();
     }
     
-    private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader dialectLoader, final SchemaBuilderMaterials 
materials, final Map<String, TableMetaData> tables) throws SQLException {
+    private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader dialectLoader,
+            final SchemaBuilderMaterials materials, final Map<String, 
TableMetaData> tables, final Collection<String> ruleLogicTables) throws 
SQLException {
+
+        Map<String, String> actualTable2LogicTableMap = 
getActualTable2LogicTableMap(materials, ruleLogicTables);
+
         Collection<Future<Map<String, TableMetaData>>> futures = new 
LinkedList<>();
-        Collection<String> existedTables = 
getExistedTables(materials.getRules(), tables);
         for (DataSource each : materials.getDataSourceMap().values()) {
-            futures.add(EXECUTOR_SERVICE.submit(() -> dialectLoader.load(each, 
existedTables)));
+            futures.add(EXECUTOR_SERVICE.submit(() -> dialectLoader.load(each, 
Collections.emptyList())));

Review comment:
       @Beyondeclipse If it is no longer needed, please delete this parameter.

##########
File path: 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -130,15 +141,30 @@ private static void appendRemainTables(final 
SchemaBuilderMaterials materials, f
         return Optional.empty();
     }
     
-    private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader dialectLoader, final SchemaBuilderMaterials 
materials, final Map<String, TableMetaData> tables) throws SQLException {
+    private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader dialectLoader,
+            final SchemaBuilderMaterials materials, final Map<String, 
TableMetaData> tables, final Collection<String> ruleLogicTables) throws 
SQLException {
+
+        Map<String, String> actualTable2LogicTableMap = 
getActualTable2LogicTableMap(materials, ruleLogicTables);
+
         Collection<Future<Map<String, TableMetaData>>> futures = new 
LinkedList<>();
-        Collection<String> existedTables = 
getExistedTables(materials.getRules(), tables);
         for (DataSource each : materials.getDataSourceMap().values()) {
-            futures.add(EXECUTOR_SERVICE.submit(() -> dialectLoader.load(each, 
existedTables)));
+            futures.add(EXECUTOR_SERVICE.submit(() -> dialectLoader.load(each, 
Collections.emptyList())));
         }
         for (Future<Map<String, TableMetaData>> each : futures) {
             try {
-                tables.putAll(each.get());
+                Map<String, TableMetaData> tableMetaMap = each.get();
+                for (Map.Entry<String, TableMetaData> one : 
tableMetaMap.entrySet()) {

Review comment:
       Please modify param name according official code conduct.

##########
File path: 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -147,9 +173,35 @@ private static void appendDialectRemainTables(final 
DialectTableMetaDataLoader d
             }
         }
     }
-    
+
+    private static Map<String, String> getActualTable2LogicTableMap(final 
SchemaBuilderMaterials materials, final Collection<String> ruleLogicTables) {
+        List<DataNodeContainedRule> dataNodeContainedRuleList = 
materials.getRules().stream()
+                .filter(each -> each instanceof DataNodeContainedRule)
+                .map(each -> (DataNodeContainedRule) each)
+                .collect(Collectors.toList());
+        if (CollectionUtils.isEmpty(dataNodeContainedRuleList)) {
+            return Collections.emptyMap();
+        }
+
+        int size = dataNodeContainedRuleList.stream()
+                .mapToInt(each -> each.getAllDataNodes().entrySet().stream()
+                        .mapToInt(entry -> entry.getValue().size())
+                        .sum())
+                .sum();
+        Map<String, String> actualTable2LogicTableMap = new HashMap<>(size);

Review comment:
       Please refer official code conduct to change the code style.

##########
File path: 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
##########
@@ -84,43 +89,45 @@
     
     private static Map<String, TableMetaData> 
buildActualTableMetaDataMap(final SchemaBuilderMaterials materials) throws 
SQLException {
         Map<String, TableMetaData> result = new 
HashMap<>(materials.getRules().size(), 1);
-        appendRemainTables(materials, result);
-        for (ShardingSphereRule rule : materials.getRules()) {
-            if (rule instanceof TableContainedRule) {
-                for (String table : ((TableContainedRule) rule).getTables()) {
-                    if (!result.containsKey(table)) {
-                        TableMetaDataBuilder.load(table, 
materials).map(optional -> result.put(table, optional));
+        Collection<String> ruleLogicTables = materials.getRules().stream()
+                .filter(rule -> rule instanceof TableContainedRule)
+                .flatMap(rule -> ((TableContainedRule) 
rule).getTables().stream())
+                .collect(Collectors.toSet());
+        appendRemainTables(materials, result, ruleLogicTables);

Review comment:
       @Beyondeclipse If you adjust the order of execution, the result 
parameter will contain the rule table.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to