Skip to content

Commit

Permalink
Add convert on LocalDataQueryResultRow (#30097)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Feb 12, 2024
1 parent c9a2109 commit 800e95d
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;

import java.util.Arrays;
Expand Down Expand Up @@ -75,11 +74,11 @@ private Collection<LocalDataQueryResultRow> buildColumnData(final EncryptTableRu
each.getAssistedQuery().map(EncryptColumnItemRuleConfiguration::getName).orElse(""),
each.getLikeQuery().map(EncryptColumnItemRuleConfiguration::getName).orElse(""),
encryptorAlgorithmConfig.getType(),
PropertiesConverter.convert(encryptorAlgorithmConfig.getProps()),
encryptorAlgorithmConfig.getProps(),
null == assistedQueryEncryptorAlgorithmConfig ? "" : assistedQueryEncryptorAlgorithmConfig.getType(),
null == assistedQueryEncryptorAlgorithmConfig ? "" : PropertiesConverter.convert(assistedQueryEncryptorAlgorithmConfig.getProps()),
null == assistedQueryEncryptorAlgorithmConfig ? "" : assistedQueryEncryptorAlgorithmConfig.getProps(),
null == likeQueryEncryptorAlgorithmConfig ? "" : likeQueryEncryptorAlgorithmConfig.getType(),
null == likeQueryEncryptorAlgorithmConfig ? "" : PropertiesConverter.convert(likeQueryEncryptorAlgorithmConfig.getProps())));
null == likeQueryEncryptorAlgorithmConfig ? "" : likeQueryEncryptorAlgorithmConfig.getProps()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.apache.shardingsphere.mask.distsql.statement.ShowMaskRulesStatement;
import org.apache.shardingsphere.mask.rule.MaskRule;
Expand Down Expand Up @@ -57,7 +56,7 @@ private Collection<LocalDataQueryResultRow> buildColumnData(final MaskTableRuleC
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
tableRuleConfig.getColumns().forEach(each -> {
AlgorithmConfiguration maskAlgorithmConfig = algorithmMap.get(each.getMaskAlgorithm());
result.add(new LocalDataQueryResultRow(tableRuleConfig.getName(), each.getLogicColumn(), maskAlgorithmConfig.getType(), PropertiesConverter.convert(maskAlgorithmConfig.getProps())));
result.add(new LocalDataQueryResultRow(tableRuleConfig.getName(), each.getLogicColumn(), maskAlgorithmConfig.getType(), maskAlgorithmConfig.getProps()));
});
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants;
import org.apache.shardingsphere.mode.manager.ContextManager;
Expand Down Expand Up @@ -80,8 +79,8 @@ private LocalDataQueryResultRow buildDataItem(final Map<String, Map<String, Stri
getWriteDataSourceName(dataSourceRuleConfig, exportDataSources),
getReadDataSourceNames(dataSourceRuleConfig, exportDataSources),
dataSourceRuleConfig.getTransactionalReadQueryStrategy().name(),
loadBalancer.map(AlgorithmConfiguration::getType).orElse(""),
loadBalancer.map(each -> PropertiesConverter.convert(each.getProps())).orElse(""));
loadBalancer.map(AlgorithmConfiguration::getType).orElse(null),
loadBalancer.map(AlgorithmConfiguration::getProps).orElse(null));
}

private Map<String, AlgorithmConfiguration> getLoadBalancers(final ReadwriteSplittingRuleConfiguration ruleConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private List<String> deconstructString(final String str) {
}

private LocalDataQueryResultRow buildRow(final String resource, final StorageNodeDataSource storageNodeDataSource) {
return null == storageNodeDataSource ? new LocalDataQueryResultRow(resource, DataSourceState.ENABLED.name()) : new LocalDataQueryResultRow(resource, storageNodeDataSource.getStatus().name());
return null == storageNodeDataSource ? new LocalDataQueryResultRow(resource, DataSourceState.ENABLED) : new LocalDataQueryResultRow(resource, storageNodeDataSource.getStatus());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.shadow.distsql.statement.ShowDefaultShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
Expand All @@ -31,7 +30,6 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;

/**
Expand All @@ -53,15 +51,11 @@ public Collection<LocalDataQueryResultRow> getRows(final ShowDefaultShadowAlgori
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : rule.getConfiguration().getShadowAlgorithms().entrySet().stream()
.filter(each -> each.getKey().equals(defaultAlgorithm)).collect(Collectors.toMap(Entry::getKey, Entry::getValue)).entrySet()) {
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), convertToString(entry.getValue().getProps())));
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps()));
}
return result;
}

private String convertToString(final Properties props) {
return null == props ? "" : PropertiesConverter.convert(props);
}

@Override
public Class<ShadowRule> getRuleClass() {
return ShadowRule.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.shadow.distsql.statement.ShowShadowAlgorithmsStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;

import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
import java.util.stream.Collectors;

/**
Expand All @@ -48,15 +46,10 @@ public Collection<String> getColumnNames(final ShowShadowAlgorithmsStatement sql
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(),
convertToString(entry.getValue().getProps()), Boolean.toString(entry.getKey().equals(defaultAlgorithm))))
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps(), Boolean.toString(entry.getKey().equals(defaultAlgorithm))))
.collect(Collectors.toList());
}

private String convertToString(final Properties props) {
return null == props ? "" : PropertiesConverter.convert(props);
}

@Override
public Class<ShadowRule> getRuleClass() {
return ShadowRule.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
Expand Down Expand Up @@ -77,8 +76,8 @@ private Collection<LocalDataQueryResultRow> buildColumnData(final ShadowDataSour
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
dataSourceTable.forEach((key, value) -> value.getShadowAlgorithmNames().forEach(each -> {
AlgorithmConfiguration algorithmConfig = algorithmConfigs.get(each);
result.add(new LocalDataQueryResultRow(key, dataSourceConfig.getName(), dataSourceConfig.getProductionDataSourceName(), dataSourceConfig.getShadowDataSourceName(),
algorithmConfig.getType(), PropertiesConverter.convert(algorithmConfig.getProps())));
result.add(new LocalDataQueryResultRow(key,
dataSourceConfig.getName(), dataSourceConfig.getProductionDataSourceName(), dataSourceConfig.getShadowDataSourceName(), algorithmConfig.getType(), algorithmConfig.getProps()));
}));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAlgorithmsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;

import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
import java.util.stream.Collectors;

/**
Expand All @@ -47,11 +45,7 @@ public Collection<String> getColumnNames(final ShowShardingAlgorithmsStatement s
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowShardingAlgorithmsStatement sqlStatement, final ContextManager contextManager) {
return rule.getConfiguration().getShardingAlgorithms().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), buildProps(entry.getValue().getProps()))).collect(Collectors.toList());
}

private String buildProps(final Properties props) {
return null == props ? "" : PropertiesConverter.convert(props);
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps())).collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAuditorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
Expand All @@ -46,7 +45,7 @@ public Collection<String> getColumnNames(final ShowShardingAuditorsStatement sql
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowShardingAuditorsStatement sqlStatement, final ContextManager contextManager) {
return rule.getConfiguration().getAuditors().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps()))).collect(Collectors.toList());
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps())).collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingKeyGeneratorsStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
Expand All @@ -46,7 +45,7 @@ public Collection<String> getColumnNames(final ShowShardingKeyGeneratorsStatemen
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowShardingKeyGeneratorsStatement sqlStatement, final ContextManager contextManager) {
return rule.getConfiguration().getKeyGenerators().entrySet().stream()
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps()))).collect(Collectors.toList());
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps())).collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
Expand All @@ -35,7 +34,6 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Properties;

/**
* Show unused sharding algorithms executor.
Expand All @@ -57,7 +55,7 @@ public Collection<LocalDataQueryResultRow> getRows(final ShowUnusedShardingAlgor
Collection<String> inUsedAlgorithms = getUsedShardingAlgorithms(shardingRuleConfig);
for (Entry<String, AlgorithmConfiguration> entry : shardingRuleConfig.getShardingAlgorithms().entrySet()) {
if (!inUsedAlgorithms.contains(entry.getKey())) {
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), buildProps(entry.getValue().getProps())));
result.add(new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps()));
}
}
return result;
Expand Down Expand Up @@ -85,10 +83,6 @@ private Collection<String> getUsedShardingAlgorithms(final ShardingRuleConfigura
return result;
}

private String buildProps(final Properties props) {
return null == props ? "" : PropertiesConverter.convert(props);
}

@Override
public Class<ShardingRule> getRuleClass() {
return ShardingRule.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
Expand Down Expand Up @@ -51,7 +50,7 @@ public Collection<LocalDataQueryResultRow> getRows(final ShowUnusedShardingAudit
ShardingRuleConfiguration shardingRuleConfig = rule.getConfiguration();
Collection<String> inUsedAuditors = getUsedAuditors(shardingRuleConfig);
return shardingRuleConfig.getAuditors().entrySet().stream().filter(entry -> !inUsedAuditors.contains(entry.getKey()))
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), PropertiesConverter.convert(entry.getValue().getProps()))).collect(Collectors.toList());
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps())).collect(Collectors.toList());
}

private Collection<String> getUsedAuditors(final ShardingRuleConfiguration shardingRuleConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorRuleAware;
import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.props.PropertiesConverter;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
Expand All @@ -32,7 +31,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.stream.Collectors;

/**
Expand All @@ -52,7 +50,7 @@ public Collection<String> getColumnNames(final ShowUnusedShardingKeyGeneratorsSt
public Collection<LocalDataQueryResultRow> getRows(final ShowUnusedShardingKeyGeneratorsStatement sqlStatement, final ContextManager contextManager) {
Collection<String> inUsedKeyGenerators = getUsedKeyGenerators(rule.getConfiguration());
return rule.getConfiguration().getKeyGenerators().entrySet().stream().filter(entry -> !inUsedKeyGenerators.contains(entry.getKey()))
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), buildProps(entry.getValue().getProps()))).collect(Collectors.toList());
.map(entry -> new LocalDataQueryResultRow(entry.getKey(), entry.getValue().getType(), entry.getValue().getProps())).collect(Collectors.toList());
}

private Collection<String> getUsedKeyGenerators(final ShardingRuleConfiguration ruleConfig) {
Expand All @@ -66,10 +64,6 @@ private Collection<String> getUsedKeyGenerators(final ShardingRuleConfiguration
return result;
}

private String buildProps(final Properties props) {
return null == props ? "" : PropertiesConverter.convert(props);
}

@Override
public Class<ShardingRule> getRuleClass() {
return ShardingRule.class;
Expand Down
Loading

0 comments on commit 800e95d

Please sign in to comment.