You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2024/02/07 12:43:59 UTC
(shardingsphere) branch master updated: Refactor ShowRulesUsedStorageUnitRowBuilder (#30055)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 244a3059861 Refactor ShowRulesUsedStorageUnitRowBuilder (#30055)
244a3059861 is described below
commit 244a3059861a2d68c60e7d55039a2d7300bced89
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Feb 7 20:43:53 2024 +0800
Refactor ShowRulesUsedStorageUnitRowBuilder (#30055)
* Refactor ShowRulesUsedStorageUnitRowBuilder
* Refactor ShowRulesUsedStorageUnitRowBuilder
---
.../handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java | 6 +++---
.../handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java | 6 +++---
.../ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java | 9 ++++-----
.../handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java | 6 +++---
.../query/ShowShardingRulesUsedStorageUnitRowBuilder.java | 9 ++++-----
.../engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java | 7 +++----
.../handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java | 8 +++++++-
7 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java
index 78819eeb86d..343404f57c1 100644
--- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java
+++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRulesUsedStorageUnitRowBuilder.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.encrypt.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
import org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -31,8 +31,8 @@ import java.util.stream.Collectors;
public final class ShowEncryptRulesUsedStorageUnitRowBuilder implements ShowRulesUsedStorageUnitRowBuilder<EncryptRule> {
@Override
- public Collection<LocalDataQueryResultRow> getInUsedData(final ShowRulesUsedStorageUnitStatement sqlStatement, final EncryptRule rule) {
- return rule.getConfiguration().getTables().stream().map(each -> new LocalDataQueryResultRow("encrypt", each.getName())).collect(Collectors.toList());
+ public Collection<String> getInUsedResources(final ShowRulesUsedStorageUnitStatement sqlStatement, final EncryptRule rule) {
+ return rule.getConfiguration().getTables().stream().map(EncryptTableRuleConfiguration::getName).collect(Collectors.toList());
}
@Override
diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java
index 807f5630d66..15ddfcf459c 100644
--- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java
+++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRulesUsedStorageUnitRowBuilder.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.mask.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
import org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.apache.shardingsphere.mask.rule.MaskRule;
import java.util.Collection;
@@ -31,8 +31,8 @@ import java.util.stream.Collectors;
public final class ShowMaskRulesUsedStorageUnitRowBuilder implements ShowRulesUsedStorageUnitRowBuilder<MaskRule> {
@Override
- public Collection<LocalDataQueryResultRow> getInUsedData(final ShowRulesUsedStorageUnitStatement sqlStatement, final MaskRule rule) {
- return rule.getConfiguration().getTables().stream().map(each -> new LocalDataQueryResultRow("mask", each.getName())).collect(Collectors.toList());
+ public Collection<String> getInUsedResources(final ShowRulesUsedStorageUnitStatement sqlStatement, final MaskRule rule) {
+ return rule.getConfiguration().getTables().stream().map(MaskTableRuleConfiguration::getName).collect(Collectors.toList());
}
@Override
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java
index 3a6ba3fe4cb..445223aec3a 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
import org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
@@ -34,17 +33,17 @@ import java.util.LinkedList;
public final class ShowReadwriteSplittingRulesUsedStorageUnitRowBuilder implements ShowRulesUsedStorageUnitRowBuilder<ReadwriteSplittingRule> {
@Override
- public Collection<LocalDataQueryResultRow> getInUsedData(final ShowRulesUsedStorageUnitStatement sqlStatement, final ReadwriteSplittingRule rule) {
+ public Collection<String> getInUsedResources(final ShowRulesUsedStorageUnitStatement sqlStatement, final ReadwriteSplittingRule rule) {
if (!sqlStatement.getStorageUnitName().isPresent()) {
return Collections.emptyList();
}
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ Collection<String> result = new LinkedList<>();
for (ReadwriteSplittingDataSourceRuleConfiguration each : rule.getConfiguration().getDataSources()) {
if (each.getWriteDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get())) {
- result.add(new LocalDataQueryResultRow("readwrite_splitting", each.getName()));
+ result.add(each.getName());
}
if (new CaseInsensitiveSet<>(each.getReadDataSourceNames()).contains(sqlStatement.getStorageUnitName().get())) {
- result.add(new LocalDataQueryResultRow("readwrite_splitting", each.getName()));
+ result.add(each.getName());
}
}
return result;
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java
index dcb643dcaa5..2e5908bd66b 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRulesUsedStorageUnitRowBuilder.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shadow.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
import org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import java.util.Collection;
@@ -32,14 +32,14 @@ import java.util.stream.Collectors;
public final class ShowShadowRulesUsedStorageUnitRowBuilder implements ShowRulesUsedStorageUnitRowBuilder<ShadowRule> {
@Override
- public Collection<LocalDataQueryResultRow> getInUsedData(final ShowRulesUsedStorageUnitStatement sqlStatement, final ShadowRule rule) {
+ public Collection<String> getInUsedResources(final ShowRulesUsedStorageUnitStatement sqlStatement, final ShadowRule rule) {
if (!sqlStatement.getStorageUnitName().isPresent()) {
return Collections.emptyList();
}
return rule.getConfiguration().getDataSources().stream()
.filter(each -> each.getShadowDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get())
|| each.getProductionDataSourceName().equalsIgnoreCase(sqlStatement.getStorageUnitName().get()))
- .map(each -> new LocalDataQueryResultRow("shadow", each.getName())).collect(Collectors.toList());
+ .map(ShadowDataSourceConfiguration::getName).collect(Collectors.toList());
}
@Override
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java
index 2493a99983b..5310a735501 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingRulesUsedStorageUnitRowBuilder.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.engine.query.rql.ShowRulesUsedStorageUnitRowBuilder;
import org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -33,13 +32,13 @@ import java.util.LinkedList;
public final class ShowShardingRulesUsedStorageUnitRowBuilder implements ShowRulesUsedStorageUnitRowBuilder<ShardingRule> {
@Override
- public Collection<LocalDataQueryResultRow> getInUsedData(final ShowRulesUsedStorageUnitStatement sqlStatement, final ShardingRule rule) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ public Collection<String> getInUsedResources(final ShowRulesUsedStorageUnitStatement sqlStatement, final ShardingRule rule) {
+ Collection<String> result = new LinkedList<>();
for (ShardingAutoTableRuleConfiguration each : rule.getConfiguration().getAutoTables()) {
- result.add(new LocalDataQueryResultRow("sharding", each.getLogicTable()));
+ result.add(each.getLogicTable());
}
for (ShardingTableRuleConfiguration each : rule.getConfiguration().getTables()) {
- result.add(new LocalDataQueryResultRow("sharding", each.getLogicTable()));
+ result.add(each.getLogicTable());
}
return result;
}
diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java
index 7a95a6a675d..f78aea9507e 100644
--- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java
+++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/query/rql/ShowRulesUsedStorageUnitRowBuilder.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.distsql.handler.engine.query.rql;
import org.apache.shardingsphere.distsql.statement.rql.rule.database.ShowRulesUsedStorageUnitStatement;
-import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
@@ -34,13 +33,13 @@ import java.util.Collection;
public interface ShowRulesUsedStorageUnitRowBuilder<T extends ShardingSphereRule> extends TypedSPI {
/**
- * Get in used data.
+ * Get in used resources.
*
* @param sqlStatement show rules used storage unit statement
* @param rule rule
- * @return in used data
+ * @return in used resources
*/
- Collection<LocalDataQueryResultRow> getInUsedData(ShowRulesUsedStorageUnitStatement sqlStatement, T rule);
+ Collection<String> getInUsedResources(ShowRulesUsedStorageUnitStatement sqlStatement, T rule);
@Override
Class<T> getType();
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
index 67b1e3c5832..0434ecb7dc3 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowRulesUsedStorageUnitExecutor.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.rql;
+import com.google.common.base.CaseFormat;
import lombok.Setter;
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
@@ -33,6 +34,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Show rules used storage unit executor.
@@ -58,7 +60,11 @@ public final class ShowRulesUsedStorageUnitExecutor implements DistSQLQueryExecu
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
for (ShowRulesUsedStorageUnitRowBuilder each : ShardingSphereServiceLoader.getServiceInstances(ShowRulesUsedStorageUnitRowBuilder.class)) {
Optional<ShardingSphereRule> rule = database.getRuleMetaData().findSingleRule(each.getType());
- rule.ifPresent(optional -> result.addAll(each.getInUsedData(sqlStatement, optional)));
+ if (rule.isPresent()) {
+ String type = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, each.getType().getSimpleName().substring(0, each.getType().getSimpleName().indexOf("Rule")));
+ Collection<String> inUsedResources = each.getInUsedResources(sqlStatement, rule.get());
+ result.addAll(inUsedResources.stream().map(resource -> new LocalDataQueryResultRow(type, resource)).collect(Collectors.toList()));
+ }
}
return result;
}