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

panjuan 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 5baf887847e Add AlgorithmMetaDataQueryResultRows (#29087)
5baf887847e is described below

commit 5baf887847e4ac07fb57cff1e388c1d2acdee773
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Nov 20 07:27:01 2023 +0800

    Add AlgorithmMetaDataQueryResultRows (#29087)
---
 .../core/spi/DatabaseSupportedTypedSPI.java        | 24 ++++----
 .../algorithm/AlgorithmMetaDataQueryResultRow.java | 68 ++++++++++++++++++++++
 .../AlgorithmMetaDataQueryResultRows.java          | 60 +++++++++++++++++++
 .../DataConsistencyCheckAlgorithmInfoRegistry.java | 61 -------------------
 .../table/TableDataConsistencyChecker.java         | 13 +----
 .../ShowMigrationCheckAlgorithmsExecutor.java      | 15 ++---
 6 files changed, 146 insertions(+), 95 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/pojo/DataConsistencyCheckAlgorithmInfo.java
 
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/spi/DatabaseSupportedTypedSPI.java
similarity index 67%
rename from 
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/pojo/DataConsistencyCheckAlgorithmInfo.java
rename to 
infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/spi/DatabaseSupportedTypedSPI.java
index 4517de99e72..b314219326f 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/pojo/DataConsistencyCheckAlgorithmInfo.java
+++ 
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/spi/DatabaseSupportedTypedSPI.java
@@ -15,26 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.data.pipeline.common.pojo;
+package org.apache.shardingsphere.infra.database.core.spi;
 
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
 
 import java.util.Collection;
 
 /**
- * Data consistency check algorithm info.
+ * Database supported SPI.
  */
-@RequiredArgsConstructor
-@Getter
-public final class DataConsistencyCheckAlgorithmInfo {
+public interface DatabaseSupportedTypedSPI extends TypedSPI {
     
-    private final String type;
-    
-    private final String typeAliases;
-    
-    private final Collection<DatabaseType> supportedDatabaseTypes;
-    
-    private final String description;
+    /**
+     * Get supported database types.
+     *
+     * @return supported database types
+     */
+    Collection<DatabaseType> getSupportedDatabaseTypes();
 }
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/algorithm/AlgorithmMetaDataQueryResultRow.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/algorithm/AlgorithmMetaDataQueryResultRow.java
new file mode 100644
index 00000000000..f654cfe04d7
--- /dev/null
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/algorithm/AlgorithmMetaDataQueryResultRow.java
@@ -0,0 +1,68 @@
+/*
+ * 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.distsql.handler.ral.query.algorithm;
+
+import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithm;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseSupportedTypedSPI;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.annotation.SPIDescription;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * Algorithm meta data query result row.
+ */
+public final class AlgorithmMetaDataQueryResultRow {
+    
+    private final boolean containsDatabaseTypes;
+    
+    private final String type;
+    
+    private final String typeAliases;
+    
+    private final String supportedDatabaseTypes;
+    
+    private final String description;
+    
+    public AlgorithmMetaDataQueryResultRow(final ShardingSphereAlgorithm 
algorithm) {
+        containsDatabaseTypes = algorithm instanceof DatabaseSupportedTypedSPI;
+        type = String.valueOf(algorithm.getType());
+        typeAliases = 
algorithm.getTypeAliases().stream().map(Object::toString).collect(Collectors.joining(","));
+        supportedDatabaseTypes = containsDatabaseTypes
+                ? getSupportedDatabaseTypes(((DatabaseSupportedTypedSPI) 
algorithm).getSupportedDatabaseTypes()).stream().map(DatabaseType::getType).collect(Collectors.joining(","))
+                : "";
+        SPIDescription description = 
algorithm.getClass().getAnnotation(SPIDescription.class);
+        this.description = null == description ? "" : description.value();
+    }
+    
+    private Collection<DatabaseType> getSupportedDatabaseTypes(final 
Collection<DatabaseType> supportedDatabaseTypes) {
+        return supportedDatabaseTypes.isEmpty() ? 
ShardingSphereServiceLoader.getServiceInstances(DatabaseType.class) : 
supportedDatabaseTypes;
+    }
+    
+    /**
+     * To local data query result row.
+     * 
+     * @return local data query result row
+     */
+    public LocalDataQueryResultRow toLocalDataQueryResultRow() {
+        return containsDatabaseTypes ? new LocalDataQueryResultRow(type, 
typeAliases, supportedDatabaseTypes, description) : new 
LocalDataQueryResultRow(type, typeAliases, description);
+    }
+}
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/algorithm/AlgorithmMetaDataQueryResultRows.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/algorithm/AlgorithmMetaDataQueryResultRows.java
new file mode 100644
index 00000000000..a53b023c30b
--- /dev/null
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/algorithm/AlgorithmMetaDataQueryResultRows.java
@@ -0,0 +1,60 @@
+/*
+ * 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.distsql.handler.ral.query.algorithm;
+
+import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithm;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseSupportedTypedSPI;
+import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * Algorithm meta data query result rows.
+ */
+public final class AlgorithmMetaDataQueryResultRows {
+    
+    private final boolean containsDatabaseTypes;
+    
+    private final Collection<AlgorithmMetaDataQueryResultRow> rows;
+    
+    public AlgorithmMetaDataQueryResultRows(final Class<? extends 
ShardingSphereAlgorithm> algorithmClass) {
+        containsDatabaseTypes = 
DatabaseSupportedTypedSPI.class.isAssignableFrom(algorithmClass);
+        rows = 
ShardingSphereServiceLoader.getServiceInstances(algorithmClass).stream().map(AlgorithmMetaDataQueryResultRow::new).collect(Collectors.toList());
+    }
+    
+    /**
+     * Get rows.
+     * 
+     * @return rows
+     */
+    public Collection<LocalDataQueryResultRow> getRows() {
+        return 
rows.stream().map(AlgorithmMetaDataQueryResultRow::toLocalDataQueryResultRow).collect(Collectors.toList());
+    }
+    
+    /**
+     * Get column names.
+     * 
+     * @return column names
+     */
+    public Collection<String> getColumnNames() {
+        return containsDatabaseTypes ? Arrays.asList("type", "type_aliases", 
"supported_database_types", "description") : Arrays.asList("type", 
"type_aliases", "description");
+    }
+}
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/pojo/DataConsistencyCheckAlgorithmInfoRegistry.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/pojo/DataConsistencyCheckAlgorithmInfoRegistry.java
deleted file mode 100644
index efde834078d..00000000000
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/common/pojo/DataConsistencyCheckAlgorithmInfoRegistry.java
+++ /dev/null
@@ -1,61 +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.
- */
-
-package org.apache.shardingsphere.data.pipeline.common.pojo;
-
-import lombok.NoArgsConstructor;
-import 
org.apache.shardingsphere.data.pipeline.core.consistencycheck.table.TableDataConsistencyChecker;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.annotation.SPIDescription;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.stream.Collectors;
-
-/**
- * Data consistency check algorithm info registry.
- */
-@NoArgsConstructor
-public final class DataConsistencyCheckAlgorithmInfoRegistry {
-    
-    private static final Collection<DataConsistencyCheckAlgorithmInfo> 
ALGORITHM_INFOS = loadAllAlgorithms();
-    
-    private static Collection<DataConsistencyCheckAlgorithmInfo> 
loadAllAlgorithms() {
-        Collection<DataConsistencyCheckAlgorithmInfo> result = new 
LinkedList<>();
-        for (TableDataConsistencyChecker each : 
ShardingSphereServiceLoader.getServiceInstances(TableDataConsistencyChecker.class))
 {
-            SPIDescription description = 
each.getClass().getAnnotation(SPIDescription.class);
-            String typeAliases = 
each.getTypeAliases().stream().map(Object::toString).collect(Collectors.joining(","));
-            result.add(
-                    new DataConsistencyCheckAlgorithmInfo(each.getType(), 
typeAliases, getSupportedDatabaseTypes(each.getSupportedDatabaseTypes()), null 
== description ? "" : description.value()));
-        }
-        return result;
-    }
-    
-    private static Collection<DatabaseType> getSupportedDatabaseTypes(final 
Collection<DatabaseType> supportedDatabaseTypes) {
-        return supportedDatabaseTypes.isEmpty() ? 
ShardingSphereServiceLoader.getServiceInstances(DatabaseType.class) : 
supportedDatabaseTypes;
-    }
-    
-    /**
-     * Get all data consistency check algorithm infos.
-     * 
-     * @return all data consistency check algorithm infos
-     */
-    public static Collection<DataConsistencyCheckAlgorithmInfo> 
getAllAlgorithmInfos() {
-        return ALGORITHM_INFOS;
-    }
-}
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyChecker.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyChecker.java
index 010e504f66d..ddd078b4601 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyChecker.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/consistencycheck/table/TableDataConsistencyChecker.java
@@ -18,14 +18,12 @@
 package org.apache.shardingsphere.data.pipeline.core.consistencycheck.table;
 
 import org.apache.shardingsphere.infra.algorithm.ShardingSphereAlgorithm;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-
-import java.util.Collection;
+import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseSupportedTypedSPI;
 
 /**
  * Table data consistency checker.
  */
-public interface TableDataConsistencyChecker extends ShardingSphereAlgorithm, 
AutoCloseable {
+public interface TableDataConsistencyChecker extends ShardingSphereAlgorithm, 
DatabaseSupportedTypedSPI, AutoCloseable {
     
     /**
      * Build table inventory checker.
@@ -44,13 +42,6 @@ public interface TableDataConsistencyChecker extends 
ShardingSphereAlgorithm, Au
         return true;
     }
     
-    /**
-     * Get supported database types.
-     *
-     * @return supported database types
-     */
-    Collection<DatabaseType> getSupportedDatabaseTypes();
-    
     @Override
     void close();
 }
diff --git 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
index 23ac3a43c7e..dcc64f1c91e 100644
--- 
a/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
+++ 
b/kernel/data-pipeline/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/query/ShowMigrationCheckAlgorithmsExecutor.java
@@ -17,32 +17,29 @@
 
 package org.apache.shardingsphere.migration.distsql.handler.query;
 
-import 
org.apache.shardingsphere.data.pipeline.common.pojo.DataConsistencyCheckAlgorithmInfoRegistry;
+import 
org.apache.shardingsphere.data.pipeline.core.consistencycheck.table.TableDataConsistencyChecker;
 import 
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import 
org.apache.shardingsphere.distsql.handler.ral.query.algorithm.AlgorithmMetaDataQueryResultRows;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import 
org.apache.shardingsphere.migration.distsql.statement.ShowMigrationCheckAlgorithmsStatement;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.stream.Collectors;
 
 /**
  * Show migration check algorithms' executor.
  */
 public final class ShowMigrationCheckAlgorithmsExecutor implements 
QueryableRALExecutor<ShowMigrationCheckAlgorithmsStatement> {
     
+    private final AlgorithmMetaDataQueryResultRows 
algorithmMetaDataQueryResultRows = new 
AlgorithmMetaDataQueryResultRows(TableDataConsistencyChecker.class);
+    
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowMigrationCheckAlgorithmsStatement sqlStatement) {
-        return 
DataConsistencyCheckAlgorithmInfoRegistry.getAllAlgorithmInfos().stream().map(
-                each -> new LocalDataQueryResultRow(each.getType(), 
each.getTypeAliases(),
-                        
each.getSupportedDatabaseTypes().stream().map(DatabaseType::getType).collect(Collectors.joining(",")),
 each.getDescription()))
-                .collect(Collectors.toList());
+        return algorithmMetaDataQueryResultRows.getRows();
     }
     
     @Override
     public Collection<String> getColumnNames() {
-        return Arrays.asList("type", "type_aliases", 
"supported_database_types", "description");
+        return algorithmMetaDataQueryResultRows.getColumnNames();
     }
     
     @Override

Reply via email to