This is an automated email from the ASF dual-hosted git repository.

wuweijie 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 d5c046136b6 Refactor usage of LocalDataQueryResultRow (#30101)
d5c046136b6 is described below

commit d5c046136b68eabfdcd2933ed7cfe2a7a56f981e
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Feb 13 11:52:39 2024 +0800

    Refactor usage of LocalDataQueryResultRow (#30101)
---
 .../encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java | 10 ++--------
 .../mask/distsql/handler/query/ShowMaskRuleExecutor.java       |  4 ++--
 .../ShowStatusFromReadwriteSplittingRulesExecutorTest.java     |  8 ++------
 .../distsql/handler/query/ShowShadowAlgorithmsExecutor.java    |  2 +-
 .../handler/query/ShowDefaultShardingStrategyExecutor.java     |  2 +-
 .../distsql/query/ShowDefaultShardingStrategyExecutorTest.java |  6 +++---
 .../distsql/handler/query/ShowStreamingJobStatusExecutor.java  |  2 +-
 .../cdc/distsql/handler/query/ShowStreamingListExecutor.java   |  3 +--
 .../handler/query/ShowMigrationCheckStatusExecutor.java        |  3 +--
 .../distsql/handler/query/ShowSQLFederationRuleExecutor.java   |  6 +++---
 .../handler/query/ShowSQLFederationRuleExecutorTest.java       |  2 +-
 11 files changed, 18 insertions(+), 30 deletions(-)

diff --git 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
index 6d148026846..fd7235ed3d0 100644
--- 
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
+++ 
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutor.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.encrypt.distsql.handler.query;
 import lombok.Setter;
 import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
 import 
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
@@ -52,13 +51,8 @@ public final class ShowEncryptRuleExecutor implements 
DistSQLQueryExecutor<ShowE
     
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowEncryptRulesStatement sqlStatement, final ContextManager contextManager) {
-        return buildData(rule.getConfiguration(), sqlStatement);
-    }
-    
-    private Collection<LocalDataQueryResultRow> buildData(final 
EncryptRuleConfiguration ruleConfig, final ShowEncryptRulesStatement 
sqlStatement) {
-        return ruleConfig.getTables().stream().filter(each -> null == 
sqlStatement.getTableName() || 
each.getName().equals(sqlStatement.getTableName()))
-                .map(each -> buildColumnData(each, ruleConfig.getEncryptors()))
-                .flatMap(Collection::stream).collect(Collectors.toList());
+        return rule.getConfiguration().getTables().stream().filter(each -> 
null == sqlStatement.getTableName() || 
each.getName().equals(sqlStatement.getTableName()))
+                .map(each -> buildColumnData(each, 
rule.getConfiguration().getEncryptors())).flatMap(Collection::stream).collect(Collectors.toList());
     }
     
     private Collection<LocalDataQueryResultRow> buildColumnData(final 
EncryptTableRuleConfiguration tableRuleConfig, final Map<String, 
AlgorithmConfiguration> encryptors) {
diff --git 
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
 
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
index bf216535edc..9faf5b809f2 100644
--- 
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
+++ 
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskRuleExecutor.java
@@ -52,10 +52,10 @@ public final class ShowMaskRuleExecutor implements 
DistSQLQueryExecutor<ShowMask
                 .map(each -> buildColumnData(each, 
rule.getConfiguration().getMaskAlgorithms())).flatMap(Collection::stream).collect(Collectors.toList());
     }
     
-    private Collection<LocalDataQueryResultRow> buildColumnData(final 
MaskTableRuleConfiguration tableRuleConfig, final Map<String, 
AlgorithmConfiguration> algorithmMap) {
+    private Collection<LocalDataQueryResultRow> buildColumnData(final 
MaskTableRuleConfiguration tableRuleConfig, final Map<String, 
AlgorithmConfiguration> maskAlgorithmConfigs) {
         Collection<LocalDataQueryResultRow> result = new LinkedList<>();
         tableRuleConfig.getColumns().forEach(each -> {
-            AlgorithmConfiguration maskAlgorithmConfig = 
algorithmMap.get(each.getMaskAlgorithm());
+            AlgorithmConfiguration maskAlgorithmConfig = 
maskAlgorithmConfigs.get(each.getMaskAlgorithm());
             result.add(new LocalDataQueryResultRow(tableRuleConfig.getName(), 
each.getLogicColumn(), maskAlgorithmConfig.getType(), 
maskAlgorithmConfig.getProps()));
         });
         return result;
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
index c34dd849830..6a41b2ce6d8 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
@@ -59,15 +59,11 @@ class ShowStatusFromReadwriteSplittingRulesExecutorTest {
     private ShardingSphereDatabase mockDatabase() {
         ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, 
RETURNS_DEEP_STUBS);
         ReadwriteSplittingRule readwriteSplittingRule = 
mock(ReadwriteSplittingRule.class);
-        
when(readwriteSplittingRule.getExportData()).thenReturn(mockExportData());
-        
when(result.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singletonList(readwriteSplittingRule));
+        
when(readwriteSplittingRule.getExportData()).thenReturn(Collections.singletonMap(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE,
 exportDataSources()));
+        
when(result.getRuleMetaData().findRules(ExportableRule.class)).thenReturn(Collections.singleton(readwriteSplittingRule));
         return result;
     }
     
-    private Map<String, Object> mockExportData() {
-        return 
Collections.singletonMap(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE,
 exportDataSources());
-    }
-    
     private Map<String, Map<String, String>> exportDataSources() {
         Map<String, String> exportedDataSources = new LinkedHashMap<>(2, 1F);
         
exportedDataSources.put(ExportableItemConstants.PRIMARY_DATA_SOURCE_NAME, 
"write_ds");
diff --git 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
index d1f071efd40..464e9538134 100644
--- 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
+++ 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
@@ -46,7 +46,7 @@ public final class ShowShadowAlgorithmsExecutor implements 
DistSQLQueryExecutor<
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowShadowAlgorithmsStatement sqlStatement, final ContextManager 
contextManager) {
         String defaultAlgorithm = 
rule.getConfiguration().getDefaultShadowAlgorithmName();
         return 
rule.getConfiguration().getShadowAlgorithms().entrySet().stream()
-                .map(entry -> new LocalDataQueryResultRow(entry.getKey(), 
entry.getValue().getType(), entry.getValue().getProps(), 
Boolean.toString(entry.getKey().equals(defaultAlgorithm))))
+                .map(entry -> new LocalDataQueryResultRow(entry.getKey(), 
entry.getValue().getType(), entry.getValue().getProps(), 
entry.getKey().equals(defaultAlgorithm)))
                 .collect(Collectors.toList());
     }
     
diff --git 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
index 84f319a5b41..ac509ef2a58 100644
--- 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
+++ 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowDefaultShardingStrategyExecutor.java
@@ -67,7 +67,7 @@ public final class ShowDefaultShardingStrategyExecutor 
implements DistSQLQueryEx
         Iterator<String> iterator = 
strategyType.getConfigurationContents(strategyConfig).iterator();
         String shardingColumn = iterator.next();
         String algorithmName = iterator.next();
-        return new LocalDataQueryResultRow(defaultType, 
strategyType.toString(), shardingColumn, algorithmName, 
algorithmConfig.getType(), algorithmConfig.getProps().toString());
+        return new LocalDataQueryResultRow(defaultType, 
strategyType.toString(), shardingColumn, algorithmName, 
algorithmConfig.getType(), algorithmConfig.getProps());
     }
     
     @Override
diff --git 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
index 821f8df69dc..a37eb7dfdce 100644
--- 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
+++ 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowDefaultShardingStrategyExecutorTest.java
@@ -64,7 +64,7 @@ class ShowDefaultShardingStrategyExecutorTest {
         assertThat(row.getCell(3), is("use_id, order_id"));
         assertThat(row.getCell(4), is("database_inline"));
         assertThat(row.getCell(5), is("INLINE"));
-        assertThat(row.getCell(6), is("{algorithm-expression=ds_${user_id % 
2}}"));
+        assertThat(row.getCell(6), 
is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}"));
         ShardingRule rule2 = mock(ShardingRule.class);
         when(rule2.getConfiguration()).thenReturn(createRuleConfiguration2());
         executor = new ShowDefaultShardingStrategyExecutor();
@@ -78,14 +78,14 @@ class ShowDefaultShardingStrategyExecutorTest {
         assertThat(row.getCell(3), is("use_id"));
         assertThat(row.getCell(4), is("database_inline"));
         assertThat(row.getCell(5), is("INLINE"));
-        assertThat(row.getCell(6), is("{algorithm-expression=ds_${user_id % 
2}}"));
+        assertThat(row.getCell(6), 
is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}"));
         row = iterator.next();
         assertThat(row.getCell(1), is("DATABASE"));
         assertThat(row.getCell(2), is("HINT"));
         assertThat(row.getCell(3), is(""));
         assertThat(row.getCell(4), is("database_inline"));
         assertThat(row.getCell(5), is("INLINE"));
-        assertThat(row.getCell(6), is("{algorithm-expression=ds_${user_id % 
2}}"));
+        assertThat(row.getCell(6), 
is("{\"algorithm-expression\":\"ds_${user_id % 2}\"}"));
     }
     
     private ShardingRuleConfiguration createRuleConfiguration1() {
diff --git 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingJobStatusExecutor.java
 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingJobStatusExecutor.java
index eaadf377c27..24ea3f6ee76 100644
--- 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingJobStatusExecutor.java
+++ 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingJobStatusExecutor.java
@@ -65,7 +65,7 @@ public final class ShowStreamingJobStatusExecutor implements 
DistSQLQueryExecuto
             incrementalIdleSeconds = 
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(currentTimeMillis - 
latestActiveTimeMillis));
         }
         return new 
LocalDataQueryResultRow(transmissionJobItemInfo.getShardingItem(), 
jobItemProgress.getDataSourceName(), jobItemProgress.getStatus(),
-                jobItemProgress.isActive() ? Boolean.TRUE.toString() : 
Boolean.FALSE.toString(), jobItemProgress.getProcessedRecordsCount(), 
transmissionJobItemInfo.getInventoryFinishedPercentage(),
+                jobItemProgress.isActive(), 
jobItemProgress.getProcessedRecordsCount(), 
transmissionJobItemInfo.getInventoryFinishedPercentage(),
                 incrementalIdleSeconds, cdcJobItemInfo.getConfirmedPosition(), 
cdcJobItemInfo.getCurrentPosition(), transmissionJobItemInfo.getErrorMessage());
     }
     
diff --git 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingListExecutor.java
 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingListExecutor.java
index ef03fbc8b4b..b128def6b6a 100644
--- 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingListExecutor.java
+++ 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/distsql/handler/query/ShowStreamingListExecutor.java
@@ -46,8 +46,7 @@ public final class ShowStreamingListExecutor implements 
DistSQLQueryExecutor<Sho
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowStreamingListStatement sqlStatement, final ContextManager contextManager) {
         return pipelineJobManager.getJobInfos(new 
PipelineContextKey(InstanceType.PROXY)).stream().map(each -> new 
LocalDataQueryResultRow(each.getJobMetaData().getJobId(),
-                each.getDatabaseName(), each.getTableName(),
-                each.getJobMetaData().getJobItemCount(), 
each.getJobMetaData().isActive() ? Boolean.TRUE.toString() : 
Boolean.FALSE.toString(),
+                each.getDatabaseName(), each.getTableName(), 
each.getJobMetaData().getJobItemCount(), each.getJobMetaData().isActive(),
                 each.getJobMetaData().getCreateTime(), 
Optional.ofNullable(each.getJobMetaData().getStopTime()).orElse(""))).collect(Collectors.toList());
     }
     
diff --git 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
index c3508838d22..a853fb010c7 100644
--- 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
+++ 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/data/pipeline/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
@@ -48,8 +48,7 @@ public final class ShowMigrationCheckStatusExecutor 
implements DistSQLQueryExecu
     }
     
     private LocalDataQueryResultRow convert(final ConsistencyCheckJobItemInfo 
info) {
-        String checkResult = null == info.getCheckSuccess() ? "" : 
info.getCheckSuccess().toString();
-        return new LocalDataQueryResultRow(info.getTableNames(), checkResult, 
info.getCheckFailedTableNames(), info.isActive(),
+        return new LocalDataQueryResultRow(info.getTableNames(), 
info.getCheckSuccess(), info.getCheckFailedTableNames(), info.isActive(),
                 info.getInventoryFinishedPercentage(), 
info.getInventoryRemainingSeconds(), info.getIncrementalIdleSeconds(),
                 info.getCheckBeginTime(), info.getCheckEndTime(), 
info.getDurationSeconds(), info.getAlgorithmType(), info.getAlgorithmProps(), 
info.getErrorMessage());
     }
diff --git 
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
 
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
index e35c6161a91..5794439f2cf 100644
--- 
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
+++ 
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutor.java
@@ -46,9 +46,9 @@ public final class ShowSQLFederationRuleExecutor implements 
DistSQLQueryExecutor
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowSQLFederationRuleStatement sqlStatement, final ContextManager 
contextManager) {
         SQLFederationRuleConfiguration ruleConfig = rule.getConfiguration();
-        String sqlFederationEnabled = 
String.valueOf(ruleConfig.isSqlFederationEnabled());
-        String allQueryUseSQLFederation = 
String.valueOf(ruleConfig.isAllQueryUseSQLFederation());
-        String executionPlanCache = null != ruleConfig.getExecutionPlanCache() 
? ruleConfig.getExecutionPlanCache().toString() : "";
+        boolean sqlFederationEnabled = ruleConfig.isSqlFederationEnabled();
+        boolean allQueryUseSQLFederation = 
ruleConfig.isAllQueryUseSQLFederation();
+        String executionPlanCache = null == ruleConfig.getExecutionPlanCache() 
? "" : ruleConfig.getExecutionPlanCache().toString();
         return Collections.singleton(new 
LocalDataQueryResultRow(sqlFederationEnabled, allQueryUseSQLFederation, 
executionPlanCache));
     }
     
diff --git 
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
 
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
index 4767a279c12..72f77ecf124 100644
--- 
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
+++ 
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
 class ShowSQLFederationRuleExecutorTest {
     
     @Test
-    void assertSQLFederationRule() {
+    void assertGetRows() {
         ShowSQLFederationRuleExecutor executor = new 
ShowSQLFederationRuleExecutor();
         SQLFederationRule rule = mock(SQLFederationRule.class);
         when(rule.getConfiguration()).thenReturn(new 
SQLFederationRuleConfiguration(true, true, new CacheOption(2000, 65535L)));

Reply via email to