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 cafc1b18544f9..5489b504e2290 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.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 @@ private String getConfigurationValue(final ShardingSphereMetaData metaData, fina 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 @@ private String getLoggingPropsValue(final ShardingSphereMetaData metaData, final 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 @@ private String getSpecialValue(final ConnectionSession connectionSession, final 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 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 bbb9f5c884908..961984a0b899e 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.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,10 @@ public Collection getColumnNames() { @Override public Collection getRows(final ShardingSphereMetaData metaData, final ConnectionSession connectionSession, final ShowDistVariablesStatement sqlStatement) { - Collection 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 result = ConfigurationPropertyKey.getKeyNames().stream().filter(each -> !"sql_show".equalsIgnoreCase(each) && !"sql_simple".equalsIgnoreCase(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 +65,13 @@ public Collection getRows(final ShardingSphereMetaData 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 result) { Optional 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 ffb2a59d98bd2..8461b92f8648b 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.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.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 @@ void assertShowCachedConnections() { @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 actual = executor.getRows(metaData, connectionSession, new ShowDistVariableStatement("SQL_SHOW")); assertThat(actual.size(), is(1)); @@ -81,6 +76,17 @@ void assertShowPropsVariable() { 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 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 7985433036644..76e6636cb3ae9 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 @@ void assertGetColumns() { @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 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 @@ void assertExecute() { @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();