Skip to content

Commit

Permalink
Refactor ShardingSphereStatisticsCollector (#30248)
Browse files Browse the repository at this point in the history
* Refactor YamlBroadcastRuleConfigurationSwapper

* Refactor ShardingSphereStatisticsCollector
  • Loading branch information
terrymanu authored Feb 22, 2024
1 parent db55939 commit d248bae
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ public final class ShardingStatisticsTableCollector implements ShardingSphereSta
private static final String SHARDING_TABLE_STATISTICS = "sharding_table_statistics";

@Override
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table,
final Map<String, ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table, final Map<String, ShardingSphereDatabase> databases) throws SQLException {
ShardingSphereTableData result = new ShardingSphereTableData(SHARDING_TABLE_STATISTICS);
DatabaseType protocolType = shardingSphereDatabases.values().iterator().next().getProtocolType();
DatabaseType protocolType = databases.values().iterator().next().getProtocolType();
DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(protocolType).getDialectDatabaseMetaData();
if (dialectDatabaseMetaData.getDefaultSchema().isPresent()) {
collectFromDatabase(shardingSphereDatabases.get(databaseName), result);
collectFromDatabase(databases.get(databaseName), result);
} else {
for (ShardingSphereDatabase each : shardingSphereDatabases.values()) {
for (ShardingSphereDatabase each : databases.values()) {
collectFromDatabase(each, result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public interface ShardingSphereStatisticsCollector extends TypedSPI {
*
* @param databaseName database name
* @param table table
* @param shardingSphereDatabases ShardingSphere databases
* @param databases databases
* @return ShardingSphere table data
* @throws SQLException sql exception
* @throws SQLException SQL exception
*/
Optional<ShardingSphereTableData> collect(String databaseName, ShardingSphereTable table, Map<String, ShardingSphereDatabase> shardingSphereDatabases) throws SQLException;
Optional<ShardingSphereTableData> collect(String databaseName, ShardingSphereTable table, Map<String, ShardingSphereDatabase> databases) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ public final class PgClassTableCollector implements ShardingSphereStatisticsColl
+ "AND relname NOT LIKE 'matviewmap\\_%' AND relname NOT LIKE 'mlog\\_%' AND pg_catalog.pg_table_is_visible(oid);";

@Override
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table,
final Map<String, ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
Collection<ShardingSphereRowData> rows = ShardingSphereTableDataCollectorUtils.collectRowData(shardingSphereDatabases.get(databaseName),
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table, final Map<String, ShardingSphereDatabase> databases) throws SQLException {
Collection<ShardingSphereRowData> rows = ShardingSphereTableDataCollectorUtils.collectRowData(databases.get(databaseName),
table, Arrays.stream(COLUMN_NAMES.split(",")).map(String::trim).collect(Collectors.toList()), SELECT_SQL);
Collection<ShardingSphereRowData> rowData = decorateTableName(rows, table, shardingSphereDatabases.get(databaseName).getRuleMetaData().getRules());
Collection<ShardingSphereRowData> rowData = decorateTableName(rows, table, databases.get(databaseName).getRuleMetaData().getRules());
ShardingSphereTableData result = new ShardingSphereTableData(PG_CLASS);
result.getRows().addAll(rowData);
return Optional.of(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public final class PgNamespaceTableCollector implements ShardingSphereStatistics
private static final String SELECT_SQL = "SELECT " + COLUMN_NAMES + " FROM pg_catalog.pg_namespace";

@Override
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table,
final Map<String, ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
Collection<ShardingSphereRowData> rows = ShardingSphereTableDataCollectorUtils.collectRowData(shardingSphereDatabases.get(databaseName),
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table, final Map<String, ShardingSphereDatabase> databases) throws SQLException {
Collection<ShardingSphereRowData> rows = ShardingSphereTableDataCollectorUtils.collectRowData(databases.get(databaseName),
table, Arrays.stream(COLUMN_NAMES.split(",")).map(String::trim).collect(Collectors.toList()), SELECT_SQL);
ShardingSphereTableData result = new ShardingSphereTableData(PG_NAMESPACE);
result.getRows().addAll(rows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
public final class StatisticsCollectorFixture implements ShardingSphereStatisticsCollector {

@Override
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table,
final Map<String, ShardingSphereDatabase> shardingSphereDatabases) throws SQLException {
public Optional<ShardingSphereTableData> collect(final String databaseName, final ShardingSphereTable table, final Map<String, ShardingSphereDatabase> databases) throws SQLException {
ShardingSphereTableData shardingSphereTableData = new ShardingSphereTableData("test_table");
shardingSphereTableData.getRows().add(new ShardingSphereRowData(Arrays.asList("1", "2")));
return Optional.of(shardingSphereTableData);
Expand Down

0 comments on commit d248bae

Please sign in to comment.