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

chenjiahao 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 d49bc1499e3 For #28968, fix query for 
proxy_frontend_database_protocol_type (#28970)
d49bc1499e3 is described below

commit d49bc1499e3fc836ceb6088a66e8a4e2ab856e17
Author: Raigor <[email protected]>
AuthorDate: Tue Nov 7 16:47:25 2023 +0800

    For #28968, fix query for proxy_frontend_database_protocol_type (#28970)
    
    * For #28968, fix query for proxy_frontend_database_protocol_type
    
    * Use enum to replace string keys.
    
    * Reduce usage of equalsIgnoreCase
---
 .../distsql/ral/queryable/ShowDistVariableExecutor.java  | 12 ++++++++++--
 .../distsql/ral/queryable/ShowDistVariablesExecutor.java | 16 ++++++++++++----
 .../ral/queryable/ShowDistVariableExecutorTest.java      | 16 +++++++++++-----
 .../ral/queryable/ShowDistVariablesExecutorTest.java     |  7 +++----
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
index cafc1b18544..5489b504e22 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
@@ -22,6 +22,7 @@ import 
org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
 import org.apache.shardingsphere.logging.constant.LoggingConstants;
 import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
 import org.apache.shardingsphere.logging.util.LoggingUtils;
@@ -68,7 +69,7 @@ public final class ShowDistVariableExecutor implements 
ConnectionSessionRequired
         if 
(LoggingConstants.SQL_SHOW_VARIABLE_NAME.equalsIgnoreCase(variableName) || 
LoggingConstants.SQL_SIMPLE_VARIABLE_NAME.equalsIgnoreCase(variableName)) {
             return getLoggingPropsValue(metaData, variableName);
         }
-        return 
metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(variableName)).toString();
+        return 
getStringResult(metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(variableName)));
     }
     
     private String getLoggingPropsValue(final ShardingSphereMetaData metaData, 
final String variableName) {
@@ -85,7 +86,7 @@ public final class ShowDistVariableExecutor implements 
ConnectionSessionRequired
                 default:
             }
         }
-        return 
metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(variableName)).toString();
+        return 
getStringResult(metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(variableName)));
     }
     
     private boolean isTemporaryConfigurationKey(final String variableName) {
@@ -105,6 +106,13 @@ public final class ShowDistVariableExecutor implements 
ConnectionSessionRequired
         throw new UnsupportedVariableException(variableName);
     }
     
+    private String getStringResult(final Object value) {
+        if (null == value) {
+            return "";
+        }
+        return value instanceof TypedSPI ? ((TypedSPI) 
value).getType().toString() : value.toString();
+    }
+    
     @Override
     public Class<ShowDistVariableStatement> getType() {
         return ShowDistVariableStatement.class;
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
index bbb9f5c8849..f59674b9a4d 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
@@ -22,6 +22,7 @@ import 
org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
 import org.apache.shardingsphere.logging.constant.LoggingConstants;
 import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
 import org.apache.shardingsphere.logging.util.LoggingUtils;
@@ -50,11 +51,11 @@ public final class ShowDistVariablesExecutor implements 
ConnectionSessionRequire
     
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShardingSphereMetaData metaData, final ConnectionSession connectionSession, 
final ShowDistVariablesStatement sqlStatement) {
-        Collection<LocalDataQueryResultRow> result = 
ConfigurationPropertyKey.getKeyNames().stream().filter(each -> 
!"sql_show".equalsIgnoreCase(each) && !"sql_simple".equalsIgnoreCase(each)
-                && null != 
metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(each)))
-                .map(each -> new LocalDataQueryResultRow(each.toLowerCase(), 
metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(each)).toString())).collect(Collectors.toList());
+        Collection<LocalDataQueryResultRow> result = 
ConfigurationPropertyKey.getKeyNames().stream()
+                .filter(each -> 
!ConfigurationPropertyKey.SQL_SHOW.name().equals(each) && 
!ConfigurationPropertyKey.SQL_SIMPLE.name().equals(each))
+                .map(each -> new LocalDataQueryResultRow(each.toLowerCase(), 
getStringResult(metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(each))))).collect(Collectors.toList());
         result.addAll(TemporaryConfigurationPropertyKey.getKeyNames().stream()
-                .map(each -> new LocalDataQueryResultRow(each.toLowerCase(), 
metaData.getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.valueOf(each)).toString()))
+                .map(each -> new LocalDataQueryResultRow(each.toLowerCase(), 
getStringResult(metaData.getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.valueOf(each)))))
                 .collect(Collectors.toList()));
         result.add(new 
LocalDataQueryResultRow(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), 
connectionSession.getDatabaseConnectionManager().getConnectionSize()));
         addLoggingPropsRows(metaData, result);
@@ -65,6 +66,13 @@ public final class ShowDistVariablesExecutor implements 
ConnectionSessionRequire
         return result.stream().sorted(Comparator.comparing(each -> 
each.getCell(1).toString())).collect(Collectors.toList());
     }
     
+    private String getStringResult(final Object value) {
+        if (null == value) {
+            return "";
+        }
+        return value instanceof TypedSPI ? ((TypedSPI) 
value).getType().toString() : value.toString();
+    }
+    
     private void addLoggingPropsRows(final ShardingSphereMetaData metaData, 
final Collection<LocalDataQueryResultRow> result) {
         Optional<ShardingSphereLogger> sqlLogger = 
LoggingUtils.getSQLLogger(metaData.getGlobalRuleMetaData());
         if (sqlLogger.isPresent()) {
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 ffb2a59d98b..8461b92f864 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
@@ -22,9 +22,6 @@ import 
org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.logging.rule.LoggingRule;
-import 
org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
 import 
org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -32,7 +29,6 @@ import 
org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -72,7 +68,6 @@ class ShowDistVariableExecutorTest {
     @Test
     void assertShowPropsVariable() {
         when(metaData.getProps()).thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new Property("sql-show", 
Boolean.TRUE.toString()))));
-        when(metaData.getGlobalRuleMetaData()).thenReturn(new 
RuleMetaData(Collections.singleton(new LoggingRule(new 
DefaultLoggingRuleConfigurationBuilder().build()))));
         ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
         Collection<LocalDataQueryResultRow> actual = 
executor.getRows(metaData, connectionSession, new 
ShowDistVariableStatement("SQL_SHOW"));
         assertThat(actual.size(), is(1));
@@ -81,6 +76,17 @@ class ShowDistVariableExecutorTest {
         assertThat(row.getCell(2), is("true"));
     }
     
+    @Test
+    void assertShowPropsVariableForTypedSPI() {
+        when(metaData.getProps()).thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-frontend-database-protocol-type", "MySQL"))));
+        ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
+        Collection<LocalDataQueryResultRow> actual = 
executor.getRows(metaData, connectionSession, new 
ShowDistVariableStatement("PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE"));
+        assertThat(actual.size(), is(1));
+        LocalDataQueryResultRow row = actual.iterator().next();
+        assertThat(row.getCell(1), 
is("proxy_frontend_database_protocol_type"));
+        assertThat(row.getCell(2), is("MySQL"));
+    }
+    
     @Test
     void assertShowTemporaryPropsVariable() {
         when(metaData.getTemporaryProps()).thenReturn(new 
TemporaryConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-meta-data-collector-enabled", Boolean.FALSE.toString()))));
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 79854330366..76e6636cb3a 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
@@ -58,12 +58,11 @@ class ShowDistVariablesExecutorTest {
     
     @Test
     void assertExecute() {
-        when(metaData.getProps()).thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("system_log_level", "INFO"))));
+        when(metaData.getProps()).thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("system-log-level", "INFO"))));
         when(metaData.getTemporaryProps()).thenReturn(new 
TemporaryConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-meta-data-collector-enabled", Boolean.FALSE.toString()))));
-        when(metaData.getGlobalRuleMetaData()).thenReturn(new 
RuleMetaData(Collections.singleton(new LoggingRule(new 
DefaultLoggingRuleConfigurationBuilder().build()))));
         ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
         Collection<LocalDataQueryResultRow> actual = 
executor.getRows(metaData, connectionSession, 
mock(ShowDistVariablesStatement.class));
-        assertThat(actual.size(), is(20));
+        assertThat(actual.size(), is(21));
         LocalDataQueryResultRow row = actual.iterator().next();
         assertThat(row.getCell(1), is("agent_plugins_enabled"));
         assertThat(row.getCell(2), is("true"));
@@ -71,7 +70,7 @@ class ShowDistVariablesExecutorTest {
     
     @Test
     void assertExecuteWithLike() {
-        when(metaData.getProps()).thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("system_log_level", "INFO"))));
+        when(metaData.getProps()).thenReturn(new 
ConfigurationProperties(PropertiesBuilder.build(new 
Property("system-log-level", "INFO"))));
         when(metaData.getTemporaryProps()).thenReturn(new 
TemporaryConfigurationProperties(PropertiesBuilder.build(new 
Property("proxy-meta-data-collector-enabled", Boolean.FALSE.toString()))));
         when(metaData.getGlobalRuleMetaData()).thenReturn(new 
RuleMetaData(Collections.singleton(new LoggingRule(new 
DefaultLoggingRuleConfigurationBuilder().build()))));
         ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();

Reply via email to