You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/02/04 12:27:41 UTC
[shardingsphere] branch master updated: Refactor `ShowMigrationCheckAlgorithmsResultSet` (#23999)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 f1fe6983380 Refactor `ShowMigrationCheckAlgorithmsResultSet` (#23999)
f1fe6983380 is described below
commit f1fe698338036b39d8f1cd4af787aafa503107bf
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Sun Feb 5 01:27:34 2023 +1300
Refactor `ShowMigrationCheckAlgorithmsResultSet` (#23999)
* Replace `ShowMigrationCheckAlgorithmsResultSet` with `ShowMigrationCheckAlgorithmsExecutor`
* Replace `ShowMigrationCheckAlgorithmsResultSet` with `ShowMigrationCheckAlgorithmsExecutor`
---
...a => ShowMigrationCheckAlgorithmsExecutor.java} | 28 ++++-----------
....distsql.handler.ral.query.QueryableRALExecutor | 1 +
...here.distsql.handler.resultset.DistSQLResultSet | 18 ----------
.../ShowMigrationCheckAlgorithmsExecutorTest.java | 40 ++++++++++++++++++++++
4 files changed, 48 insertions(+), 39 deletions(-)
diff --git a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsResultSet.java b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
similarity index 63%
rename from kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsResultSet.java
rename to kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
index 0ed4d1520f0..3a2954cbf34 100644
--- a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsResultSet.java
+++ b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
@@ -19,29 +19,25 @@ package org.apache.shardingsphere.migration.distsql.handler.query;
import org.apache.shardingsphere.data.pipeline.core.api.InventoryIncrementalJobAPI;
import org.apache.shardingsphere.data.pipeline.core.api.PipelineJobAPI;
-import org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
-import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
+import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.migration.distsql.statement.ShowMigrationCheckAlgorithmsStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
import java.util.stream.Collectors;
/**
- * Result set for show migration check algorithms.
+ * Show migration check algorithms executor.
*/
-public final class ShowMigrationCheckAlgorithmsResultSet implements DatabaseDistSQLResultSet {
-
- private Iterator<Collection<Object>> data;
+public final class ShowMigrationCheckAlgorithmsExecutor implements QueryableRALExecutor<ShowMigrationCheckAlgorithmsStatement> {
@Override
- public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) {
+ public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationCheckAlgorithmsStatement sqlStatement) {
InventoryIncrementalJobAPI jobAPI = (InventoryIncrementalJobAPI) TypedSPILoader.getService(PipelineJobAPI.class, "MIGRATION");
- data = jobAPI.listDataConsistencyCheckAlgorithms().stream().map(
- each -> (Collection<Object>) Arrays.<Object>asList(each.getType(), String.join(",", each.getSupportedDatabaseTypes()), each.getDescription())).collect(Collectors.toList()).iterator();
+ return jobAPI.listDataConsistencyCheckAlgorithms().stream().map(
+ each -> new LocalDataQueryResultRow(each.getType(), String.join(",", each.getSupportedDatabaseTypes()), each.getDescription())).collect(Collectors.toList());
}
@Override
@@ -49,16 +45,6 @@ public final class ShowMigrationCheckAlgorithmsResultSet implements DatabaseDist
return Arrays.asList("type", "supported_database_types", "description");
}
- @Override
- public boolean next() {
- return data.hasNext();
- }
-
- @Override
- public Collection<Object> getRowData() {
- return data.next();
- }
-
@Override
public String getType() {
return ShowMigrationCheckAlgorithmsStatement.class.getName();
diff --git a/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor b/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
index 90246227283..d8fbcfbc3aa 100644
--- a/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
+++ b/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
@@ -19,3 +19,4 @@ org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationListExecu
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationJobStatusExecutor
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckStatusExecutor
org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationSourceStorageUnitsExecutor
+org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckAlgorithmsExecutor
diff --git a/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet b/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
deleted file mode 100644
index 08bcc9f1e6d..00000000000
--- a/kernel/data-pipeline/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckAlgorithmsResultSet
diff --git a/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutorTest.java b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutorTest.java
new file mode 100644
index 00000000000..1899fb80906
--- /dev/null
+++ b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutorTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.migration.distsql.handler.query;
+
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public final class ShowMigrationCheckAlgorithmsExecutorTest {
+
+ @Test
+ public void assertGetColumnNames() {
+ ShowMigrationCheckAlgorithmsExecutor executor = new ShowMigrationCheckAlgorithmsExecutor();
+ Collection<String> columns = executor.getColumnNames();
+ assertThat(columns.size(), is(3));
+ Iterator<String> iterator = columns.iterator();
+ assertThat(iterator.next(), is("type"));
+ assertThat(iterator.next(), is("supported_database_types"));
+ assertThat(iterator.next(), is("description"));
+ }
+}