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 789f2dd0bc9 Replace `ShowTableMetaDataHandler` with 
`ShowTableMetaDataExecutor` (#23942)
789f2dd0bc9 is described below

commit 789f2dd0bc9cdccaff225e16c979ab7b82e3e861
Author: Zichao <[email protected]>
AuthorDate: Fri Feb 3 21:58:45 2023 +1300

    Replace `ShowTableMetaDataHandler` with `ShowTableMetaDataExecutor` (#23942)
    
    * Replace `ShowTableMetaDataHandler` with `ShowTableMetaDataExecutor`
    
    * Replace `ShowTableMetaDataHandler` with `ShowTableMetaDataExecutor`
---
 ...tTest.java => CountShadowRuleExecutorTest.java} |  2 +-
 ...xecutor.java => ShowAuthorityRuleExecutor.java} |  2 +-
 ....distsql.handler.ral.query.QueryableRALExecutor |  2 +-
 ...est.java => ShowAuthorityRuleExecutorTest.java} |  6 +--
 .../distsql/ral/RALBackendHandlerFactory.java      |  3 --
 ...Handler.java => ShowTableMetaDataExecutor.java} | 36 ++++++++--------
 ....distsql.handler.ral.query.QueryableRALExecutor |  1 +
 ...est.java => ShowTableMetaDataExecutorTest.java} | 49 +++++++++++++---------
 8 files changed, 54 insertions(+), 47 deletions(-)

diff --git 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleResultSetTest.java
 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
similarity index 98%
rename from 
features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleResultSetTest.java
rename to 
features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
index 927c28c4774..445b8db5350 100644
--- 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleResultSetTest.java
+++ 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class CountShadowRuleResultSetTest {
+public final class CountShadowRuleExecutorTest {
     
     @Test
     public void assertGetRowData() {
diff --git 
a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutor.java
 
b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
similarity index 95%
rename from 
kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutor.java
rename to 
kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
index baa52f152aa..f4de2a643b5 100644
--- 
a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutor.java
+++ 
b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutor.java
@@ -32,7 +32,7 @@ import java.util.stream.Collectors;
 /**
  * Show authority rule executor.
  */
-public final class AuthorityRuleExecutor implements 
MetaDataRequiredQueryableRALExecutor<ShowAuthorityRuleStatement> {
+public final class ShowAuthorityRuleExecutor implements 
MetaDataRequiredQueryableRALExecutor<ShowAuthorityRuleStatement> {
     
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShardingSphereMetaData metaData, final ShowAuthorityRuleStatement sqlStatement) 
{
diff --git 
a/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
 
b/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
index 6a5d6525750..1a0b901fc07 100644
--- 
a/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
+++ 
b/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.authority.distsql.handler.AuthorityRuleExecutor
+org.apache.shardingsphere.authority.distsql.handler.ShowAuthorityRuleExecutor
diff --git 
a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutorTest.java
 
b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutorTest.java
similarity index 94%
rename from 
kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutorTest.java
rename to 
kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutorTest.java
index eb53f79c37a..060f0b533d4 100644
--- 
a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutorTest.java
+++ 
b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/ShowAuthorityRuleExecutorTest.java
@@ -39,12 +39,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class AuthorityRuleExecutorTest {
+public final class ShowAuthorityRuleExecutorTest {
     
     @Test
     public void assertExecute() {
         ShardingSphereMetaData metaData = mockMetaData();
-        AuthorityRuleExecutor executor = new AuthorityRuleExecutor();
+        ShowAuthorityRuleExecutor executor = new ShowAuthorityRuleExecutor();
         Collection<LocalDataQueryResultRow> actual = 
executor.getRows(metaData, mock(ShowAuthorityRuleStatement.class));
         assertThat(actual.size(), is(1));
         Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
@@ -56,7 +56,7 @@ public final class AuthorityRuleExecutorTest {
     
     @Test
     public void assertGetColumnNames() {
-        AuthorityRuleExecutor executor = new AuthorityRuleExecutor();
+        ShowAuthorityRuleExecutor executor = new ShowAuthorityRuleExecutor();
         Collection<String> columns = executor.getColumnNames();
         assertThat(columns.size(), is(3));
         Iterator<String> iterator = columns.iterator();
diff --git 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
index a8953fb8b32..be45e07ef70 100644
--- 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
+++ 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
@@ -28,7 +28,6 @@ import 
org.apache.shardingsphere.distsql.parser.statement.ral.HintRALStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableGlobalRuleRALStatement;
 import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableGlobalRuleRALStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetaDataStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.QueryableScalingRALStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.UpdatableScalingRALStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ApplyDistSQLStatement;
@@ -49,7 +48,6 @@ import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.hint.HintRALB
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.migration.query.QueryableScalingRALBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.migration.update.UpdatableScalingRALBackendHandler;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowStatusFromReadwriteSplittingRulesHandler;
-import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowTableMetaDataHandler;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.AlterReadwriteSplittingStorageUnitStatusStatementHandler;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ApplyDistSQLHandler;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.DiscardDistSQLHandler;
@@ -89,7 +87,6 @@ public final class RALBackendHandlerFactory {
         HANDLERS.put(DiscardDistSQLStatement.class, 
DiscardDistSQLHandler.class);
         HANDLERS.put(ImportDatabaseConfigurationStatement.class, 
ImportDatabaseConfigurationHandler.class);
         HANDLERS.put(ShowStatusFromReadwriteSplittingRulesStatement.class, 
ShowStatusFromReadwriteSplittingRulesHandler.class);
-        HANDLERS.put(ShowTableMetaDataStatement.class, 
ShowTableMetaDataHandler.class);
     }
     
     /**
diff --git 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataHandler.java
 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
similarity index 73%
rename from 
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataHandler.java
rename to 
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
index 23cf228a4d2..31915bcce3b 100644
--- 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataHandler.java
+++ 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutor.java
@@ -23,11 +23,12 @@ import 
org.apache.shardingsphere.dialect.exception.syntax.database.UnknownDataba
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetaDataStatement;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereIndex;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
-import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.AbstractQueryableRALBackendHandler;
+import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.executor.ConnectionSessionRequiredQueryableRALExecutor;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -37,32 +38,24 @@ import java.util.stream.Collectors;
 /**
  * Show table metadata handler.
  */
-public final class ShowTableMetaDataHandler extends 
AbstractQueryableRALBackendHandler<ShowTableMetaDataStatement> {
-    
-    private static final String SCHEMA_NAME = "schema_name";
-    
-    private static final String TABLE_NAME = "table_name";
-    
-    private static final String TYPE = "type";
-    
-    private static final String NAME = "name";
+public final class ShowTableMetaDataExecutor implements 
ConnectionSessionRequiredQueryableRALExecutor<ShowTableMetaDataStatement> {
     
     @Override
-    protected Collection<String> getColumnNames() {
-        return Arrays.asList(SCHEMA_NAME, TABLE_NAME, TYPE, NAME);
+    public Collection<String> getColumnNames() {
+        return Arrays.asList("schema_name", "table_name", "type", "name");
     }
     
     @Override
-    protected Collection<LocalDataQueryResultRow> getRows(final ContextManager 
contextManager) {
-        String databaseName = getDatabaseName();
-        String defaultSchema = 
DatabaseTypeEngine.getDefaultSchemaName(getConnectionSession().getProtocolType(),
 getConnectionSession().getDatabaseName());
+    public Collection<LocalDataQueryResultRow> getRows(final 
ShardingSphereMetaData metaData, final ConnectionSession connectionSession, 
final ShowTableMetaDataStatement sqlStatement) {
+        String databaseName = getDatabaseName(connectionSession, sqlStatement);
+        String defaultSchema = 
DatabaseTypeEngine.getDefaultSchemaName(connectionSession.getProtocolType(), 
connectionSession.getDatabaseName());
         ShardingSphereSchema schema = 
ProxyContext.getInstance().getDatabase(databaseName).getSchema(defaultSchema);
-        return schema.getAllTableNames().stream().filter(each -> 
getSqlStatement().getTableNames().contains(each))
+        return schema.getAllTableNames().stream().filter(each -> 
sqlStatement.getTableNames().contains(each))
                 .map(each -> buildTableRows(databaseName, schema, 
each)).flatMap(Collection::stream).collect(Collectors.toList());
     }
     
-    private String getDatabaseName() {
-        String result = getSqlStatement().getDatabase().isPresent() ? 
getSqlStatement().getDatabase().get().getIdentifier().getValue() : 
getConnectionSession().getDatabaseName();
+    private String getDatabaseName(final ConnectionSession connectionSession, 
final ShowTableMetaDataStatement sqlStatement) {
+        String result = sqlStatement.getDatabase().isPresent() ? 
sqlStatement.getDatabase().get().getIdentifier().getValue() : 
connectionSession.getDatabaseName();
         if (Strings.isNullOrEmpty(result)) {
             throw new NoDatabaseSelectedException();
         }
@@ -85,4 +78,9 @@ public final class ShowTableMetaDataHandler extends 
AbstractQueryableRALBackendH
     private LocalDataQueryResultRow buildRow(final String databaseName, final 
String tableName, final String type, final String name) {
         return new LocalDataQueryResultRow(databaseName, tableName, type, 
name);
     }
+    
+    @Override
+    public String getType() {
+        return ShowTableMetaDataStatement.class.getName();
+    }
 }
diff --git 
a/proxy/backend/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
 
b/proxy/backend/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
index d3b5bc44025..822c1b2375b 100644
--- 
a/proxy/backend/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
+++ 
b/proxy/backend/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
@@ -22,3 +22,4 @@ 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ExportData
 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ConvertYamlConfigurationExecutor
 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowDistVariableExecutor
 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowDistVariablesExecutor
+org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowTableMetaDataExecutor
diff --git 
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataHandlerTest.java
 
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
similarity index 71%
rename from 
proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataHandlerTest.java
rename to 
proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
index fbca8a3e50c..9422016ef2b 100644
--- 
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataHandlerTest.java
+++ 
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetaDataExecutorTest.java
@@ -18,6 +18,8 @@
 package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
 
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetaDataStatement;
+import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereIndex;
@@ -35,7 +37,7 @@ import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
+import java.util.Iterator;
 import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -44,7 +46,7 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class ShowTableMetaDataHandlerTest extends ProxyContextRestorer {
+public final class ShowTableMetaDataExecutorTest extends ProxyContextRestorer {
     
     @Test
     public void assertExecute() throws SQLException {
@@ -57,23 +59,32 @@ public final class ShowTableMetaDataHandlerTest extends 
ProxyContextRestorer {
         ProxyContext.init(contextManager);
         ConnectionSession connectionSession = mock(ConnectionSession.class, 
RETURNS_DEEP_STUBS);
         when(connectionSession.getDatabaseName()).thenReturn("db_name");
-        ShowTableMetaDataHandler handler = new ShowTableMetaDataHandler();
-        handler.init(createSqlStatement(), connectionSession);
-        handler.execute();
-        handler.next();
-        List<Object> data = handler.getRowData().getData();
-        assertThat(data.size(), is(4));
-        assertThat(data.get(0), is("db_name"));
-        assertThat(data.get(1), is("t_order"));
-        assertThat(data.get(2), is("COLUMN"));
-        assertThat(data.get(3), is("order_id"));
-        handler.next();
-        data = handler.getRowData().getData();
-        assertThat(data.size(), is(4));
-        assertThat(data.get(0), is("db_name"));
-        assertThat(data.get(1), is("t_order"));
-        assertThat(data.get(2), is("INDEX"));
-        assertThat(data.get(3), is("primary"));
+        ShowTableMetaDataExecutor executor = new ShowTableMetaDataExecutor();
+        Collection<LocalDataQueryResultRow> actual = 
executor.getRows(mock(ShardingSphereMetaData.class), connectionSession, 
createSqlStatement());
+        assertThat(actual.size(), is(2));
+        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
+        LocalDataQueryResultRow row = iterator.next();
+        assertThat(row.getCell(1), is("db_name"));
+        assertThat(row.getCell(2), is("t_order"));
+        assertThat(row.getCell(3), is("COLUMN"));
+        assertThat(row.getCell(4), is("order_id"));
+        row = iterator.next();
+        assertThat(row.getCell(1), is("db_name"));
+        assertThat(row.getCell(2), is("t_order"));
+        assertThat(row.getCell(3), is("INDEX"));
+        assertThat(row.getCell(4), is("primary"));
+    }
+    
+    @Test
+    public void assertGetColumnNames() {
+        ShowTableMetaDataExecutor executor = new ShowTableMetaDataExecutor();
+        Collection<String> columns = executor.getColumnNames();
+        assertThat(columns.size(), is(4));
+        Iterator<String> iterator = columns.iterator();
+        assertThat(iterator.next(), is("schema_name"));
+        assertThat(iterator.next(), is("table_name"));
+        assertThat(iterator.next(), is("type"));
+        assertThat(iterator.next(), is("name"));
     }
     
     private Map<String, ShardingSphereTable> createTableMap() {

Reply via email to