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 05:59:08 UTC

[shardingsphere] branch master updated: Replace `ShowMigrationCheckStatusResultSet` with `ShowMigrationCheckStatusExecutor` (#23989)

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 56eb2856053 Replace `ShowMigrationCheckStatusResultSet` with `ShowMigrationCheckStatusExecutor` (#23989)
56eb2856053 is described below

commit 56eb285605385e0bc0085ff28661a63fb205247d
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Sat Feb 4 18:58:55 2023 +1300

    Replace `ShowMigrationCheckStatusResultSet` with `ShowMigrationCheckStatusExecutor` (#23989)
---
 ....java => ShowMigrationCheckStatusExecutor.java} | 35 +++++------------
 ....distsql.handler.ral.query.QueryableRALExecutor |  1 +
 ...here.distsql.handler.resultset.DistSQLResultSet |  1 -
 .../ShowMigrationCheckStatusExecutorTest.java      | 45 ++++++++++++++++++++++
 4 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusResultSet.java b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
similarity index 66%
rename from kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusResultSet.java
rename to kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
index 34526da8754..54941510d76 100644
--- a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusResultSet.java
+++ b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusExecutor.java
@@ -19,41 +19,36 @@ package org.apache.shardingsphere.migration.distsql.handler.query;
 
 import org.apache.shardingsphere.data.pipeline.api.pojo.ConsistencyCheckJobItemInfo;
 import org.apache.shardingsphere.data.pipeline.scenario.consistencycheck.api.impl.ConsistencyCheckJobAPI;
-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.migration.distsql.statement.ShowMigrationCheckStatusStatement;
-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.LinkedList;
 import java.util.List;
 import java.util.Optional;
 
 /**
- * Result set for show migration check status.
+ * Show migration check status executor.
  */
-public final class ShowMigrationCheckStatusResultSet implements DatabaseDistSQLResultSet {
+public final class ShowMigrationCheckStatusExecutor implements QueryableRALExecutor<ShowMigrationCheckStatusStatement> {
     
     private final ConsistencyCheckJobAPI jobAPI = new ConsistencyCheckJobAPI();
     
-    private Iterator<Collection<Object>> data;
-    
     @Override
-    public void init(final ShardingSphereDatabase database, final SQLStatement sqlStatement) {
-        ShowMigrationCheckStatusStatement checkMigrationStatement = (ShowMigrationCheckStatusStatement) sqlStatement;
-        List<ConsistencyCheckJobItemInfo> infos = jobAPI.getJobItemInfos(checkMigrationStatement.getJobId());
-        Collection<Collection<Object>> result = new LinkedList<>();
+    public Collection<LocalDataQueryResultRow> getRows(final ShowMigrationCheckStatusStatement sqlStatement) {
+        List<ConsistencyCheckJobItemInfo> infos = jobAPI.getJobItemInfos(sqlStatement.getJobId());
+        Collection<LocalDataQueryResultRow> result = new LinkedList<>();
         for (ConsistencyCheckJobItemInfo each : infos) {
             result.add(convert(each));
         }
-        data = result.iterator();
+        return result;
     }
     
-    private Collection<Object> convert(final ConsistencyCheckJobItemInfo info) {
+    private LocalDataQueryResultRow convert(final ConsistencyCheckJobItemInfo info) {
         String checkResult = null == info.getCheckSuccess() ? "" : info.getCheckSuccess().toString();
-        return Arrays.asList(Optional.ofNullable(info.getTableNames()).orElse(""), checkResult,
+        return new LocalDataQueryResultRow(Optional.ofNullable(info.getTableNames()).orElse(""), checkResult,
                 String.valueOf(info.getFinishedPercentage()), info.getRemainingSeconds(),
                 Optional.ofNullable(info.getCheckBeginTime()).orElse(""), Optional.ofNullable(info.getCheckEndTime()).orElse(""),
                 info.getDurationSeconds(), Optional.ofNullable(info.getErrorMessage()).orElse(""));
@@ -64,16 +59,6 @@ public final class ShowMigrationCheckStatusResultSet implements DatabaseDistSQLR
         return Arrays.asList("tables", "result", "finished_percentage", "remaining_seconds", "check_begin_time", "check_end_time", "duration_seconds", "error_message");
     }
     
-    @Override
-    public boolean next() {
-        return data.hasNext();
-    }
-    
-    @Override
-    public Collection<Object> getRowData() {
-        return data.next();
-    }
-    
     @Override
     public String getType() {
         return ShowMigrationCheckStatusStatement.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 9370d7d3f7b..bbdc4a586fd 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
@@ -17,3 +17,4 @@
 
 org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationListExecutor
 org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationJobStatusExecutor
+org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckStatusExecutor
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
index 1054006ae9d..b5c6e76d61c 100644
--- 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
@@ -15,6 +15,5 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckStatusResultSet
 org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationCheckAlgorithmsResultSet
 org.apache.shardingsphere.migration.distsql.handler.query.ShowMigrationSourceStorageUnitsResultSet
diff --git a/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusExecutorTest.java b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusExecutorTest.java
new file mode 100644
index 00000000000..98be3eb3316
--- /dev/null
+++ b/kernel/data-pipeline/distsql/handler/src/test/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckStatusExecutorTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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 ShowMigrationCheckStatusExecutorTest {
+    
+    @Test
+    public void assertGetColumnNames() {
+        ShowMigrationCheckStatusExecutor executor = new ShowMigrationCheckStatusExecutor();
+        Collection<String> columns = executor.getColumnNames();
+        assertThat(columns.size(), is(8));
+        Iterator<String> iterator = columns.iterator();
+        assertThat(iterator.next(), is("tables"));
+        assertThat(iterator.next(), is("result"));
+        assertThat(iterator.next(), is("finished_percentage"));
+        assertThat(iterator.next(), is("remaining_seconds"));
+        assertThat(iterator.next(), is("check_begin_time"));
+        assertThat(iterator.next(), is("check_end_time"));
+        assertThat(iterator.next(), is("duration_seconds"));
+        assertThat(iterator.next(), is("error_message"));
+    }
+}