Skip to content

Commit

Permalink
Merge MetaDataRequiredQueryableRALExecutor and QueryableRALExecutor (#…
Browse files Browse the repository at this point in the history
…29710)

* Merge MetaDataRequiredQueryableRALExecutor and QueryableRALExecutor

* Merge MetaDataRequiredQueryableRALExecutor and QueryableRALExecutor
  • Loading branch information
terrymanu authored Jan 12, 2024
1 parent 58c181d commit ea55203
Show file tree
Hide file tree
Showing 45 changed files with 102 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.encrypt.distsql.statement.ShowEncryptAlgorithmImplementationsStatement;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;

import java.util.Arrays;
Expand All @@ -38,7 +39,7 @@ public Collection<String> getColumnNames() {
}

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowEncryptAlgorithmImplementationsStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowEncryptAlgorithmImplementationsStatement sqlStatement, final ShardingSphereMetaData metaData) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<EncryptAlgorithm> encryptAlgorithms = ShardingSphereServiceLoader.getServiceInstances(EncryptAlgorithm.class);
for (EncryptAlgorithm each : encryptAlgorithms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.encrypt.distsql.statement.ShowEncryptAlgorithmImplementationsStatement;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.junit.jupiter.api.Test;

import java.util.Collection;
Expand All @@ -35,7 +36,7 @@ class ShowEncryptAlgorithmImplementationsExecutorTest {
@Test
void assertGetRowData() {
QueryableRALExecutor<ShowEncryptAlgorithmImplementationsStatement> executor = new ShowEncryptAlgorithmImplementationsExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowEncryptAlgorithmImplementationsStatement.class));
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowEncryptAlgorithmImplementationsStatement.class), mock(ShardingSphereMetaData.class));
assertFalse(actual.isEmpty());
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.mask.distsql.statement.ShowMaskAlgorithmImplementationsStatement;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
Expand All @@ -39,7 +40,7 @@ public Collection<String> getColumnNames() {

@SuppressWarnings("rawtypes")
@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowMaskAlgorithmImplementationsStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowMaskAlgorithmImplementationsStatement sqlStatement, final ShardingSphereMetaData metaData) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<MaskAlgorithm> maskAlgorithms = ShardingSphereServiceLoader.getServiceInstances(MaskAlgorithm.class);
for (MaskAlgorithm each : maskAlgorithms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.mask.distsql.statement.ShowMaskAlgorithmImplementationsStatement;
import org.junit.jupiter.api.Test;

Expand All @@ -35,7 +36,7 @@ class ShowMaskAlgorithmImplementationsExecutorTest {
@Test
void assertGetRowData() {
QueryableRALExecutor<ShowMaskAlgorithmImplementationsStatement> executor = new ShowMaskAlgorithmImplementationsExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowMaskAlgorithmImplementationsStatement.class));
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowMaskAlgorithmImplementationsStatement.class), mock(ShardingSphereMetaData.class));
assertFalse(actual.isEmpty());
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowReadQueryLoadBalanceAlgorithmImplementationsStatement;
import org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
Expand All @@ -38,7 +39,7 @@ public Collection<String> getColumnNames() {
}

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowReadQueryLoadBalanceAlgorithmImplementationsStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowReadQueryLoadBalanceAlgorithmImplementationsStatement sqlStatement, final ShardingSphereMetaData metaData) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<ReadQueryLoadBalanceAlgorithm> loadBalanceAlgorithms = ShardingSphereServiceLoader.getServiceInstances(ReadQueryLoadBalanceAlgorithm.class);
for (ReadQueryLoadBalanceAlgorithm each : loadBalanceAlgorithms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowReadQueryLoadBalanceAlgorithmImplementationsStatement;
import org.junit.jupiter.api.Test;

Expand All @@ -35,7 +36,7 @@ class ShowReadQueryLoadBalanceAlgorithmImplementationsExecutorTest {
@Test
void assertGetRowData() {
QueryableRALExecutor<ShowReadQueryLoadBalanceAlgorithmImplementationsStatement> executor = new ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowReadQueryLoadBalanceAlgorithmImplementationsStatement.class));
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowReadQueryLoadBalanceAlgorithmImplementationsStatement.class), mock(ShardingSphereMetaData.class));
assertFalse(actual.isEmpty());
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.shadow.distsql.statement.ShowShadowAlgorithmImplementationsStatement;
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
Expand All @@ -38,7 +39,7 @@ public Collection<String> getColumnNames() {
}

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowShadowAlgorithmImplementationsStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowShadowAlgorithmImplementationsStatement sqlStatement, final ShardingSphereMetaData metaData) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<ShadowAlgorithm> shadowAlgorithms = ShardingSphereServiceLoader.getServiceInstances(ShadowAlgorithm.class);
for (ShadowAlgorithm each : shadowAlgorithms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowAlgorithmImplementationsExecutor;
import org.apache.shardingsphere.shadow.distsql.statement.ShowShadowAlgorithmImplementationsStatement;
import org.junit.jupiter.api.Test;
Expand All @@ -36,7 +37,7 @@ class ShowShadowAlgorithmImplementationsExecutorTest {
@Test
void assertGetRowData() {
QueryableRALExecutor<ShowShadowAlgorithmImplementationsStatement> executor = new ShowShadowAlgorithmImplementationsExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShadowAlgorithmImplementationsStatement.class));
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShadowAlgorithmImplementationsStatement.class), mock(ShardingSphereMetaData.class));
assertFalse(actual.isEmpty());
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAlgorithmImplementationsStatement;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
Expand All @@ -38,7 +39,7 @@ public Collection<String> getColumnNames() {
}

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowShardingAlgorithmImplementationsStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowShardingAlgorithmImplementationsStatement sqlStatement, final ShardingSphereMetaData metaData) {
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<ShardingAlgorithm> shardingAlgorithms = ShardingSphereServiceLoader.getServiceInstances(ShardingAlgorithm.class);
for (ShardingAlgorithm each : shardingAlgorithms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingAlgorithmImplementationsExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingAlgorithmImplementationsStatement;
import org.junit.jupiter.api.Test;
Expand All @@ -36,7 +37,7 @@ class ShowShardingAlgorithmImplementationsExecutorTest {
@Test
void assertGetRowData() {
QueryableRALExecutor<ShowShardingAlgorithmImplementationsStatement> executor = new ShowShardingAlgorithmImplementationsExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingAlgorithmImplementationsStatement.class));
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowShardingAlgorithmImplementationsStatement.class), mock(ShardingSphereMetaData.class));
assertFalse(actual.isEmpty());
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.shardingsphere.distsql.statement.ral.QueryableRALStatement;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;

Expand All @@ -44,9 +45,10 @@ public interface QueryableRALExecutor<T extends QueryableRALStatement> extends T
* Get query result rows.
*
* @param sqlStatement SQL statement
* @param metaData ShardingSphere meta data
* @return query result rows
*/
default Collection<LocalDataQueryResultRow> getRows(final T sqlStatement) {
default Collection<LocalDataQueryResultRow> getRows(final T sqlStatement, final ShardingSphereMetaData metaData) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import org.apache.shardingsphere.authority.distsql.statement.ShowAuthorityRuleStatement;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.distsql.handler.ral.query.MetaDataRequiredQueryableRALExecutor;
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;

Expand All @@ -32,10 +32,10 @@
/**
* Show authority rule executor.
*/
public final class ShowAuthorityRuleExecutor implements MetaDataRequiredQueryableRALExecutor<ShowAuthorityRuleStatement> {
public final class ShowAuthorityRuleExecutor implements QueryableRALExecutor<ShowAuthorityRuleStatement> {

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShardingSphereMetaData metaData, final ShowAuthorityRuleStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowAuthorityRuleStatement sqlStatement, final ShardingSphereMetaData metaData) {
AuthorityRule rule = metaData.getGlobalRuleMetaData().getSingleRule(AuthorityRule.class);
AuthorityRuleConfiguration ruleConfig = rule.getConfiguration();
return Collections.singleton(new LocalDataQueryResultRow(ruleConfig.getUsers().stream().map(each -> each.getGrantee().toString()).collect(Collectors.joining("; ")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ShowAuthorityRuleExecutorTest {
void assertExecute() {
ShardingSphereMetaData metaData = mockMetaData();
ShowAuthorityRuleExecutor executor = new ShowAuthorityRuleExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(metaData, mock(ShowAuthorityRuleStatement.class));
Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowAuthorityRuleStatement.class), metaData);
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
LocalDataQueryResultRow row = iterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.shardingsphere.data.pipeline.core.pojo.TransmissionJobItemInfo;
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;

import java.util.Arrays;
Expand All @@ -40,7 +41,7 @@ public final class ShowStreamingJobStatusExecutor implements QueryableRALExecuto
private final CDCJobAPI jobAPI = (CDCJobAPI) TypedSPILoader.getService(TransmissionJobAPI.class, "STREAMING");

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingStatusStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingStatusStatement sqlStatement, final ShardingSphereMetaData metaData) {
Collection<CDCJobItemInfo> jobItemInfos = jobAPI.getJobItemInfos(sqlStatement.getJobId());
long currentTimeMillis = System.currentTimeMillis();
return jobItemInfos.stream().map(each -> getRow(each, currentTimeMillis)).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -38,7 +39,7 @@ public final class ShowStreamingListExecutor implements QueryableRALExecutor<Sho
private final PipelineJobManager pipelineJobManager = new PipelineJobManager(new CDCJobType());

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingListStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingListStatement sqlStatement, final ShardingSphereMetaData metaData) {
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.data.pipeline.distsql.ShowTransmissionRuleQueryResult;
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;

import java.util.Collection;

Expand All @@ -37,7 +38,7 @@ public Collection<String> getColumnNames() {
}

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingRuleStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowStreamingRuleStatement sqlStatement, final ShardingSphereMetaData metaData) {
return queryResult.getRows();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.shardingsphere.distsql.handler.ral.query.algorithm.AlgorithmMetaDataQueryResultRows;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.data.pipeline.migration.distsql.statement.ShowMigrationCheckAlgorithmsStatement;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;

import java.util.Collection;

Expand All @@ -33,7 +34,7 @@ public final class ShowMigrationCheckAlgorithmsExecutor implements QueryableRALE
private final AlgorithmMetaDataQueryResultRows algorithmMetaDataQueryResultRows = new AlgorithmMetaDataQueryResultRows(TableDataConsistencyChecker.class);

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationCheckAlgorithmsStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationCheckAlgorithmsStatement sqlStatement, final ShardingSphereMetaData metaData) {
return algorithmMetaDataQueryResultRows.getRows();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.data.pipeline.migration.distsql.statement.ShowMigrationCheckStatusStatement;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -38,7 +39,7 @@ public final class ShowMigrationCheckStatusExecutor implements QueryableRALExecu
private final ConsistencyCheckJobAPI jobAPI = new ConsistencyCheckJobAPI(new ConsistencyCheckJobType());

@Override
public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationCheckStatusStatement sqlStatement) {
public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationCheckStatusStatement sqlStatement, final ShardingSphereMetaData metaData) {
List<ConsistencyCheckJobItemInfo> infos = jobAPI.getJobItemInfos(sqlStatement.getJobId());
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
for (ConsistencyCheckJobItemInfo each : infos) {
Expand Down
Loading

0 comments on commit ea55203

Please sign in to comment.