strongduanmu commented on code in PR #21424:
URL: https://github.com/apache/shardingsphere/pull/21424#discussion_r990865462


##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.metadata.data;
+
+import 
org.apache.shardingsphere.data.pipeline.spi.data.collector.ShardingSphereDataCollector;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import javax.sql.DataSource;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Sharding statistics table data collector.
+ */
+public class ShardingStatisticsTableCollector implements 
ShardingSphereDataCollector {
+    
+    private static final String SHARDING_STATISTICS_TABLE = 
"sharding_statistics_table";
+    
+    private static final String SHARDING_SPHERE = "shardingsphere";
+    
+    private static final String MYSQL_TABLE_ROWS_AND_DATA_LENGTH = "SELECT 
TABLE_ROWS, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA = 
'%s' AND TABLE_NAME = '%s'";
+    
+    @Override
+    public void collectShardingSphereData(final ShardingSphereData 
shardingSphereData, final String databaseName, final 
Collection<ShardingSphereRule> rules,

Review Comment:
   Do you think rename this method to collect is better?



##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.metadata.data;
+
+import 
org.apache.shardingsphere.data.pipeline.spi.data.collector.ShardingSphereDataCollector;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import javax.sql.DataSource;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Sharding statistics table data collector.
+ */
+public class ShardingStatisticsTableCollector implements 
ShardingSphereDataCollector {
+    
+    private static final String SHARDING_STATISTICS_TABLE = 
"sharding_statistics_table";
+    
+    private static final String SHARDING_SPHERE = "shardingsphere";
+    
+    private static final String MYSQL_TABLE_ROWS_AND_DATA_LENGTH = "SELECT 
TABLE_ROWS, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA = 
'%s' AND TABLE_NAME = '%s'";
+    
+    @Override
+    public void collectShardingSphereData(final ShardingSphereData 
shardingSphereData, final String databaseName, final 
Collection<ShardingSphereRule> rules,
+                                          final Map<String, DataSource> 
dataSources, final DatabaseType databaseType) throws SQLException {
+        ShardingRule shardingRule = null;
+        for (ShardingSphereRule each : rules) {

Review Comment:
   Can we use common findSingleRule method?



##########
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.metadata.data;
+
+import 
org.apache.shardingsphere.data.pipeline.spi.data.collector.ShardingSphereDataCollector;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereRowData;
+import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.apache.shardingsphere.sharding.rule.TableRule;
+
+import javax.sql.DataSource;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Sharding statistics table data collector.
+ */
+public class ShardingStatisticsTableCollector implements 
ShardingSphereDataCollector {
+    
+    private static final String SHARDING_STATISTICS_TABLE = 
"sharding_statistics_table";
+    
+    private static final String SHARDING_SPHERE = "shardingsphere";
+    
+    private static final String MYSQL_TABLE_ROWS_AND_DATA_LENGTH = "SELECT 
TABLE_ROWS, DATA_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA = 
'%s' AND TABLE_NAME = '%s'";
+    
+    @Override
+    public void collectShardingSphereData(final ShardingSphereData 
shardingSphereData, final String databaseName, final 
Collection<ShardingSphereRule> rules,
+                                          final Map<String, DataSource> 
dataSources, final DatabaseType databaseType) throws SQLException {
+        ShardingRule shardingRule = null;
+        for (ShardingSphereRule each : rules) {
+            if (each instanceof ShardingRule) {
+                shardingRule = (ShardingRule) each;
+                break;
+            }
+        }
+        if (null == shardingRule) {
+            return;
+        }
+        ShardingSphereTableData tableData = new 
ShardingSphereTableData(SHARDING_STATISTICS_TABLE);

Review Comment:
   Please extract this logic to a private method.



-- 
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