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

zhangliang 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 568dd1cdc86 Add protocolType on protocolType (#29880)
568dd1cdc86 is described below

commit 568dd1cdc865d4f8cc700eed2f97bbce90be0406
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 27 23:46:02 2024 +0800

    Add protocolType on protocolType (#29880)
---
 .../distsql/handler/type/DistSQLConnectionContext.java         |  3 +++
 .../distsql/handler/type/rul/RULExecuteEngine.java             |  7 -------
 .../handler/distsql/ral/QueryableRALBackendHandler.java        |  4 ++--
 .../proxy/backend/handler/distsql/rul/RULBackendHandler.java   | 10 ++--------
 .../backend/handler/distsql/rul/type/FormatSQLExecutor.java    |  9 +++++----
 .../backend/handler/distsql/rul/type/ParseDistSQLExecutor.java | 10 +++++-----
 .../distsql/ral/queryable/ShowDistVariableExecutorTest.java    |  4 +++-
 .../distsql/ral/queryable/ShowDistVariablesExecutorTest.java   |  7 +++++--
 8 files changed, 25 insertions(+), 29 deletions(-)

diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java
index b3f4d9853c9..fdb6117aaad 100644
--- 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.distsql.handler.type;
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager;
 import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
@@ -34,6 +35,8 @@ public final class DistSQLConnectionContext {
     
     private final int connectionSize;
     
+    private final DatabaseType protocolType;
+    
     @SuppressWarnings("rawtypes")
     private final DatabaseConnectionManager databaseConnectionManager;
     
diff --git 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
index 9a40e340799..2c23e5af2ff 100644
--- 
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
+++ 
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java
@@ -21,12 +21,10 @@ import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware;
 import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware;
-import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseProtocolTypeAware;
 import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
 import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor;
 import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils;
 import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -65,9 +63,6 @@ public abstract class RULExecuteEngine {
         if (executor instanceof DistSQLExecutorDatabaseAware) {
             ((DistSQLExecutorDatabaseAware) 
executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement,
 currentDatabaseName)));
         }
-        if (executor instanceof DistSQLExecutorDatabaseProtocolTypeAware) {
-            ((DistSQLExecutorDatabaseProtocolTypeAware) 
executor).setDatabaseProtocolType(getDatabaseProtocolType());
-        }
         if (executor instanceof DistSQLExecutorConnectionContextAware) {
             ((DistSQLExecutorConnectionContextAware) 
executor).setConnectionContext(getDistSQLConnectionContext());
         }
@@ -76,7 +71,5 @@ public abstract class RULExecuteEngine {
     
     protected abstract ShardingSphereDatabase getDatabase(String databaseName);
     
-    protected abstract DatabaseType getDatabaseProtocolType();
-    
     protected abstract DistSQLConnectionContext getDistSQLConnectionContext();
 }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
index 3aca63d245a..a65409e0586 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
@@ -88,7 +88,7 @@ public final class QueryableRALBackendHandler extends 
QueryableRALExecuteEngine
     
     @Override
     protected DistSQLConnectionContext getDistSQLConnectionContext() {
-        return new 
DistSQLConnectionContext(connectionSession.getConnectionContext(),
-                
connectionSession.getDatabaseConnectionManager().getConnectionSize(), 
connectionSession.getDatabaseConnectionManager(), 
connectionSession.getStatementManager());
+        return new 
DistSQLConnectionContext(connectionSession.getConnectionContext(), 
connectionSession.getDatabaseConnectionManager().getConnectionSize(),
+                connectionSession.getProtocolType(), 
connectionSession.getDatabaseConnectionManager(), 
connectionSession.getStatementManager());
     }
 }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
index e43dda5f401..82f8d590897 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.proxy.backend.handler.distsql.rul;
 import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
 import org.apache.shardingsphere.distsql.handler.type.rul.RULExecuteEngine;
 import org.apache.shardingsphere.distsql.statement.rul.RULStatement;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
@@ -92,14 +91,9 @@ public final class RULBackendHandler extends 
RULExecuteEngine implements DistSQL
         return ProxyContext.getInstance().getDatabase(databaseName);
     }
     
-    @Override
-    protected DatabaseType getDatabaseProtocolType() {
-        return connectionSession.getProtocolType();
-    }
-    
     @Override
     protected DistSQLConnectionContext getDistSQLConnectionContext() {
-        return new 
DistSQLConnectionContext(connectionSession.getConnectionContext(),
-                
connectionSession.getDatabaseConnectionManager().getConnectionSize(), 
connectionSession.getDatabaseConnectionManager(), 
connectionSession.getStatementManager());
+        return new 
DistSQLConnectionContext(connectionSession.getConnectionContext(), 
connectionSession.getDatabaseConnectionManager().getConnectionSize(),
+                connectionSession.getProtocolType(), 
connectionSession.getDatabaseConnectionManager(), 
connectionSession.getStatementManager());
     }
 }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/FormatSQLExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/FormatSQLExecutor.java
index e42ccedf4ec..228f0af55a2 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/FormatSQLExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/FormatSQLExecutor.java
@@ -18,7 +18,8 @@
 package org.apache.shardingsphere.proxy.backend.handler.distsql.rul.type;
 
 import lombok.Setter;
-import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseProtocolTypeAware;
+import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware;
+import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
 import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor;
 import org.apache.shardingsphere.distsql.statement.rul.sql.FormatStatement;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -35,9 +36,9 @@ import java.util.Properties;
  * Format SQL executor.
  */
 @Setter
-public final class FormatSQLExecutor implements 
DistSQLQueryExecutor<FormatStatement>, DistSQLExecutorDatabaseProtocolTypeAware 
{
+public final class FormatSQLExecutor implements 
DistSQLQueryExecutor<FormatStatement>, DistSQLExecutorConnectionContextAware {
     
-    private DatabaseType databaseProtocolType;
+    private DistSQLConnectionContext connectionContext;
     
     @Override
     public Collection<String> getColumnNames() {
@@ -46,7 +47,7 @@ public final class FormatSQLExecutor implements 
DistSQLQueryExecutor<FormatState
     
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final FormatStatement 
sqlStatement, final ContextManager contextManager) {
-        return Collections.singleton(new 
LocalDataQueryResultRow(formatSQL(sqlStatement.getSql(), 
databaseProtocolType)));
+        return Collections.singleton(new 
LocalDataQueryResultRow(formatSQL(sqlStatement.getSql(), 
connectionContext.getProtocolType())));
     }
     
     private Object formatSQL(final String sql, final DatabaseType 
databaseType) {
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/ParseDistSQLExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/ParseDistSQLExecutor.java
index dfb9718624f..c1bf3fb16c5 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/ParseDistSQLExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/ParseDistSQLExecutor.java
@@ -18,10 +18,10 @@
 package org.apache.shardingsphere.proxy.backend.handler.distsql.rul.type;
 
 import lombok.Setter;
-import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseProtocolTypeAware;
+import 
org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware;
+import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
 import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor;
 import org.apache.shardingsphere.distsql.statement.rul.sql.ParseStatement;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.util.json.JsonUtils;
@@ -37,9 +37,9 @@ import java.util.Collections;
  * Parse DistSQL executor.
  */
 @Setter
-public final class ParseDistSQLExecutor implements 
DistSQLQueryExecutor<ParseStatement>, DistSQLExecutorDatabaseProtocolTypeAware {
+public final class ParseDistSQLExecutor implements 
DistSQLQueryExecutor<ParseStatement>, DistSQLExecutorConnectionContextAware {
     
-    private DatabaseType databaseProtocolType;
+    private DistSQLConnectionContext connectionContext;
     
     @Override
     public Collection<String> getColumnNames() {
@@ -54,7 +54,7 @@ public final class ParseDistSQLExecutor implements 
DistSQLQueryExecutor<ParseSta
     
     private SQLStatement parseSQL(final ShardingSphereMetaData metaData, final 
ParseStatement sqlStatement) {
         SQLParserRule sqlParserRule = 
metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
-        return 
sqlParserRule.getSQLParserEngine(databaseProtocolType).parse(sqlStatement.getSql(),
 false);
+        return 
sqlParserRule.getSQLParserEngine(connectionContext.getProtocolType()).parse(sqlStatement.getSql(),
 false);
     }
     
     @Override
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
index 57186a09673..cf7770f552e 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
 import 
org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariableStatement;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
@@ -47,7 +48,8 @@ class ShowDistVariableExecutorTest {
     @Test
     void assertShowCachedConnections() {
         ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
-        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(ConnectionContext.class), 1, 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
+        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(ConnectionContext.class), 1,
+                mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariableStatement("CACHED_CONNECTIONS"), contextManager);
         assertThat(actual.size(), is(1));
         LocalDataQueryResultRow row = actual.iterator().next();
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
index 6ca20eaeed2..3b53910747e 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext;
 import 
org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariablesStatement;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
@@ -53,7 +54,8 @@ class ShowDistVariablesExecutorTest {
         
when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps())
                 .thenReturn(new 
TemporaryConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-meta-data-collector-enabled", Boolean.FALSE.toString()))));
         ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
-        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(ConnectionContext.class), 1, 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
+        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(ConnectionContext.class), 1,
+                mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
         Collection<LocalDataQueryResultRow> actual = 
executor.getRows(mock(ShowDistVariablesStatement.class), contextManager);
         assertThat(actual.size(), is(21));
         LocalDataQueryResultRow row = actual.iterator().next();
@@ -69,7 +71,8 @@ class ShowDistVariablesExecutorTest {
         
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData())
                 .thenReturn(new RuleMetaData(Collections.singleton(new 
LoggingRule(new DefaultLoggingRuleConfigurationBuilder().build()))));
         ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
-        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(ConnectionContext.class), 1, 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
+        executor.setConnectionContext(new 
DistSQLConnectionContext(mock(ConnectionContext.class), 1,
+                mock(DatabaseType.class), 
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
         Collection<LocalDataQueryResultRow> actual = executor.getRows(new 
ShowDistVariablesStatement("sql_%"), contextManager);
         assertThat(actual.size(), is(2));
         Iterator<LocalDataQueryResultRow> iterator = actual.iterator();

Reply via email to