This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 929bcfa13fc Refactor ShowDistVariableHandler &
ShowDistVariablesHandler. (#23900)
929bcfa13fc is described below
commit 929bcfa13fca17d681fcba12fec82a377b5b06f9
Author: Raigor <[email protected]>
AuthorDate: Wed Feb 1 20:16:01 2023 +0800
Refactor ShowDistVariableHandler & ShowDistVariablesHandler. (#23900)
* Refactor ShowDistVariableHandler & ShowDistVariablesHandler.
* Refactor ConvertYamlConfigurationExecutor.
* Refactor ConvertYamlConfigurationExecutor.
---
.../DatabaseRequiredQueryableRALExecutor.java | 2 +-
...nstanceContextRequiredQueryableRALExecutor.java | 2 +-
.../MetaDataRequiredQueryableRALExecutor.java | 2 +-
.../handler/ral/query/QueryableRALExecutor.java | 15 ++-
.../distsql/ral/QueryableRALBackendHandler.java | 23 +++-
.../distsql/ral/RALBackendHandlerFactory.java | 6 -
.../ConvertYamlConfigurationExecutor.java | 20 ++--
...eHandler.java => ShowDistVariableExecutor.java} | 48 ++++----
...Handler.java => ShowDistVariablesExecutor.java} | 32 ++---
...nectionSessionRequiredQueryableRALExecutor.java | 11 +-
....distsql.handler.ral.query.QueryableRALExecutor | 2 +
.../handler/ProxyBackendHandlerFactoryTest.java | 7 +-
.../ConvertYamlConfigurationExecutorTest.java | 6 +-
.../ShowDistVariableBackendHandlerTest.java | 131 ---------------------
.../queryable/ShowDistVariableExecutorTest.java | 107 +++++++++++++++++
.../queryable/ShowDistVariablesExecutorTest.java | 66 +++++++++++
.../queryable/ShowDistVariablesHandlerTest.java | 77 ------------
17 files changed, 273 insertions(+), 284 deletions(-)
diff --git
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/DatabaseRequiredQueryableRALExecutor.java
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/DatabaseRequiredQueryableRALExecutor.java
index 536feb32c11..2773966bda6 100644
---
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/DatabaseRequiredQueryableRALExecutor.java
+++
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/DatabaseRequiredQueryableRALExecutor.java
@@ -26,7 +26,7 @@ import java.util.Collection;
/**
* Database required queryable RAL executor.
*/
-public interface DatabaseRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor {
+public interface DatabaseRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor<T> {
/**
* Get query result rows.
diff --git
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/InstanceContextRequiredQueryableRALExecutor.java
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/InstanceContextRequiredQueryableRALExecutor.java
index 66fdbb643f3..cdc2d3c197b 100644
---
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/InstanceContextRequiredQueryableRALExecutor.java
+++
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/InstanceContextRequiredQueryableRALExecutor.java
@@ -26,7 +26,7 @@ import java.util.Collection;
/**
* Instance context required queryable RAL executor.
*/
-public interface InstanceContextRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor {
+public interface InstanceContextRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor<T> {
/**
* Get query result rows.
diff --git
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
index 9d75207f530..b834830f12e 100644
---
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
+++
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
@@ -26,7 +26,7 @@ import java.util.Collection;
/**
* Meta data required queryable RAL executor.
*/
-public interface MetaDataRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor {
+public interface MetaDataRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor<T> {
/**
* Get query result rows.
diff --git
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/QueryableRALExecutor.java
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/QueryableRALExecutor.java
index b8e79adf160..b056156df5d 100644
---
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/QueryableRALExecutor.java
+++
b/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/QueryableRALExecutor.java
@@ -17,16 +17,19 @@
package org.apache.shardingsphere.distsql.handler.ral.query;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
import java.util.Collection;
+import java.util.Collections;
/**
* Queryable RAL executor.
*/
@SingletonSPI
-public interface QueryableRALExecutor extends TypedSPI {
+public interface QueryableRALExecutor<T extends QueryableRALStatement> extends
TypedSPI {
/**
* Get column names.
@@ -34,4 +37,14 @@ public interface QueryableRALExecutor extends TypedSPI {
* @return column names
*/
Collection<String> getColumnNames();
+
+ /**
+ * Get query result rows.
+ *
+ * @param sqlStatement SQL statement
+ * @return query result rows
+ */
+ default Collection<LocalDataQueryResultRow> getRows(T sqlStatement) {
+ return Collections.emptyList();
+ }
}
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
index 862746f1b29..de2f36590ae 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java
@@ -31,6 +31,7 @@ import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryRes
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.executor.ConnectionSessionRequiredQueryableRALExecutor;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -67,18 +68,26 @@ public final class QueryableRALBackendHandler<T extends
QueryableRALStatement> e
@SuppressWarnings("unchecked")
@Override
public ResponseHeader execute() {
- QueryableRALExecutor executor =
TypedSPILoader.getService(QueryableRALExecutor.class,
getSqlStatement().getClass().getName());
+ QueryableRALExecutor<T> executor =
TypedSPILoader.getService(QueryableRALExecutor.class,
getSqlStatement().getClass().getName());
queryHeaders = createQueryHeader(executor.getColumnNames());
+ mergedResult = getMergedResult(executor);
+ return new QueryResponseHeader(queryHeaders);
+ }
+
+ private MergedResult getMergedResult(final QueryableRALExecutor<T>
executor) {
if (executor instanceof InstanceContextRequiredQueryableRALExecutor) {
- mergedResult =
getMergedResultByInstanceContextRequiredExecutor((InstanceContextRequiredQueryableRALExecutor<T>)
executor);
+ return
getMergedResultByInstanceContextRequiredExecutor((InstanceContextRequiredQueryableRALExecutor<T>)
executor);
}
if (executor instanceof MetaDataRequiredQueryableRALExecutor) {
- mergedResult =
getMergedResultByMetaDataRequiredExecutor((MetaDataRequiredQueryableRALExecutor<T>)
executor);
+ return
getMergedResultByMetaDataRequiredExecutor((MetaDataRequiredQueryableRALExecutor<T>)
executor);
}
if (executor instanceof DatabaseRequiredQueryableRALExecutor) {
- mergedResult =
getMergedResultByDatabaseRequiredExecutor((DatabaseRequiredQueryableRALExecutor<T>)
executor);
+ return
getMergedResultByDatabaseRequiredExecutor((DatabaseRequiredQueryableRALExecutor<T>)
executor);
}
- return new QueryResponseHeader(queryHeaders);
+ if (executor instanceof ConnectionSessionRequiredQueryableRALExecutor)
{
+ return
getMergedResultByConnectionSessionRequiredExecutor((ConnectionSessionRequiredQueryableRALExecutor<T>)
executor);
+ }
+ return createMergedResult(executor.getRows(getSqlStatement()));
}
private MergedResult
getMergedResultByInstanceContextRequiredExecutor(final
InstanceContextRequiredQueryableRALExecutor<T> executor) {
@@ -95,6 +104,10 @@ public final class QueryableRALBackendHandler<T extends
QueryableRALStatement> e
return
createMergedResult(executor.getRows(ProxyContext.getInstance().getDatabase(databaseName),
getSqlStatement()));
}
+ private MergedResult
getMergedResultByConnectionSessionRequiredExecutor(final
ConnectionSessionRequiredQueryableRALExecutor<T> executor) {
+ return
createMergedResult(executor.getRows(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
getConnectionSession(), getSqlStatement()));
+ }
+
private List<QueryHeader> createQueryHeader(final Collection<String>
columnNames) {
return columnNames.stream().map(each -> new QueryHeader("", "", each,
each, Types.CHAR, "CHAR", 255, 0, false, false, false,
false)).collect(Collectors.toList());
}
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 1adf356be8b..099376d1535 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
@@ -29,8 +29,6 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableGlobalRul
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.ExportDatabaseConfigurationStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariableStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariablesStatement;
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;
@@ -52,8 +50,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.ExportDatabaseConfigurationHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowDistVariableHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowDistVariablesHandler;
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;
@@ -94,8 +90,6 @@ public final class RALBackendHandlerFactory {
HANDLERS.put(ApplyDistSQLStatement.class, ApplyDistSQLHandler.class);
HANDLERS.put(DiscardDistSQLStatement.class,
DiscardDistSQLHandler.class);
HANDLERS.put(ImportDatabaseConfigurationStatement.class,
ImportDatabaseConfigurationHandler.class);
- HANDLERS.put(ShowDistVariableStatement.class,
ShowDistVariableHandler.class);
- HANDLERS.put(ShowDistVariablesStatement.class,
ShowDistVariablesHandler.class);
HANDLERS.put(ShowStatusFromReadwriteSplittingRulesStatement.class,
ShowStatusFromReadwriteSplittingRulesHandler.class);
HANDLERS.put(ShowTableMetaDataStatement.class,
ShowTableMetaDataHandler.class);
HANDLERS.put(ExportDatabaseConfigurationStatement.class,
ExportDatabaseConfigurationHandler.class);
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
index c46f2f01230..c5648f336ee 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
@@ -25,7 +25,7 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
import
org.apache.shardingsphere.dbdiscovery.yaml.config.YamlDatabaseDiscoveryRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.yaml.swapper.YamlDatabaseDiscoveryRuleConfigurationSwapper;
-import
org.apache.shardingsphere.distsql.handler.ral.query.InstanceContextRequiredQueryableRALExecutor;
+import
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
@@ -38,7 +38,6 @@ import
org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
import
org.apache.shardingsphere.infra.datasource.props.custom.CustomDataSourceProperties;
import
org.apache.shardingsphere.infra.datasource.props.synonym.PoolPropertySynonyms;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
@@ -88,17 +87,17 @@ import java.util.TreeMap;
/**
* Convert YAML configuration executor.
*/
-public final class ConvertYamlConfigurationExecutor implements
InstanceContextRequiredQueryableRALExecutor<ConvertYamlConfigurationStatement> {
+public final class ConvertYamlConfigurationExecutor implements
QueryableRALExecutor<ConvertYamlConfigurationStatement> {
private final YamlProxyDataSourceConfigurationSwapper
dataSourceConfigSwapper = new YamlProxyDataSourceConfigurationSwapper();
@Override
public Collection<String> getColumnNames() {
- return Collections.singleton("distsql");
+ return Collections.singleton("dist_sql");
}
@Override
- public Collection<LocalDataQueryResultRow> getRows(final InstanceContext
instanceContext, final ConvertYamlConfigurationStatement sqlStatement) {
+ public Collection<LocalDataQueryResultRow> getRows(final
ConvertYamlConfigurationStatement sqlStatement) {
File file = new File(sqlStatement.getFilePath());
YamlProxyDatabaseConfiguration yamlConfig;
try {
@@ -111,11 +110,6 @@ public final class ConvertYamlConfigurationExecutor
implements InstanceContextRe
return Collections.singleton(new
LocalDataQueryResultRow(generateDistSQL(yamlConfig)));
}
- @Override
- public String getType() {
- return ConvertYamlConfigurationStatement.class.getName();
- }
-
private String generateDistSQL(final YamlProxyDatabaseConfiguration
yamlConfig) {
StringBuilder result = new StringBuilder();
appendResourceDistSQL(yamlConfig, result);
@@ -628,6 +622,7 @@ public final class ConvertYamlConfigurationExecutor
implements InstanceContextRe
return result.toString();
}
+ @SuppressWarnings({"unchecked", "rawtypes"})
private String getAlgorithmProperties(final Properties props) {
StringBuilder result = new StringBuilder();
Iterator<String> iterator = new TreeMap(props).keySet().iterator();
@@ -644,4 +639,9 @@ public final class ConvertYamlConfigurationExecutor
implements InstanceContextRe
}
return result.toString();
}
+
+ @Override
+ public String getType() {
+ return ConvertYamlConfigurationStatement.class.getName();
+ }
}
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableHandler.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
similarity index 56%
rename from
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableHandler.java
rename to
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
index 1b3241ef1e9..c1875250420 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableHandler.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
@@ -20,10 +20,11 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariableStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.AbstractQueryableRALBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.executor.ConnectionSessionRequiredQueryableRALExecutor;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.api.TransactionType;
@@ -32,51 +33,52 @@ import java.util.Collection;
import java.util.Collections;
/**
- * Show dist variable handler.
+ * Show dist variable executor.
*/
-public final class ShowDistVariableHandler extends
AbstractQueryableRALBackendHandler<ShowDistVariableStatement> {
-
- private static final String VARIABLE_NAME = "variable_name";
-
- private static final String VARIABLE_VALUE = "variable_value";
+public final class ShowDistVariableExecutor implements
ConnectionSessionRequiredQueryableRALExecutor<ShowDistVariableStatement> {
@Override
- protected Collection<String> getColumnNames() {
- return Arrays.asList(VARIABLE_NAME, VARIABLE_VALUE);
+ public Collection<String> getColumnNames() {
+ return Arrays.asList("variable_name", "variable_value");
}
@Override
- protected Collection<LocalDataQueryResultRow> getRows(final ContextManager
contextManager) {
- return buildSpecifiedRow(contextManager, getSqlStatement().getName());
+ public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereMetaData metaData, final ConnectionSession connectionSession,
final ShowDistVariableStatement sqlStatement) {
+ return buildSpecifiedRow(metaData, connectionSession,
sqlStatement.getName());
}
- private Collection<LocalDataQueryResultRow> buildSpecifiedRow(final
ContextManager contextManager, final String key) {
- return isConfigurationKey(key)
- ? Collections.singletonList(new
LocalDataQueryResultRow(key.toLowerCase(),
getConfigurationValue(contextManager, key)))
- : Collections.singletonList(new
LocalDataQueryResultRow(key.toLowerCase(), getSpecialValue(key)));
+ private Collection<LocalDataQueryResultRow> buildSpecifiedRow(final
ShardingSphereMetaData metaData, final ConnectionSession connectionSession,
final String variableName) {
+ return isConfigurationKey(variableName)
+ ? Collections.singletonList(new
LocalDataQueryResultRow(variableName.toLowerCase(),
getConfigurationValue(metaData, variableName)))
+ : Collections.singletonList(new
LocalDataQueryResultRow(variableName.toLowerCase(),
getSpecialValue(connectionSession, variableName)));
}
private boolean isConfigurationKey(final String key) {
return ConfigurationPropertyKey.getKeyNames().contains(key);
}
- private String getConfigurationValue(final ContextManager contextManager,
final String key) {
- return
contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.valueOf(key)).toString();
+ private String getConfigurationValue(final ShardingSphereMetaData
metaData, final String variableName) {
+ return
metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(variableName)).toString();
}
- private String getSpecialValue(final String key) {
- VariableEnum variable = VariableEnum.getValueOf(key);
+ private String getSpecialValue(final ConnectionSession connectionSession,
final String variableName) {
+ VariableEnum variable = VariableEnum.getValueOf(variableName);
switch (variable) {
case AGENT_PLUGINS_ENABLED:
return SystemPropertyUtil.getSystemProperty(variable.name(),
Boolean.TRUE.toString());
case CACHED_CONNECTIONS:
- int connectionSize =
getConnectionSession().getBackendConnection().getConnectionSize();
+ int connectionSize =
connectionSession.getBackendConnection().getConnectionSize();
return String.valueOf(connectionSize);
case TRANSACTION_TYPE:
- TransactionType transactionType =
getConnectionSession().getTransactionStatus().getTransactionType();
+ TransactionType transactionType =
connectionSession.getTransactionStatus().getTransactionType();
return transactionType.name();
default:
}
- throw new UnsupportedVariableException(key);
+ throw new UnsupportedVariableException(variableName);
+ }
+
+ @Override
+ public String getType() {
+ return ShowDistVariableStatement.class.getName();
}
}
diff --git
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandler.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
similarity index 65%
rename from
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandler.java
rename to
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
index 2e3eac44c96..cda0281e7a0 100644
---
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandler.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
@@ -18,12 +18,12 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariablesStatement;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.AbstractQueryableRALBackendHandler;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.executor.ConnectionSessionRequiredQueryableRALExecutor;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import java.util.Arrays;
@@ -31,28 +31,28 @@ import java.util.Collection;
import java.util.stream.Collectors;
/**
- * Show dist variables handler.
+ * Show dist variables executor.
*/
-public final class ShowDistVariablesHandler extends
AbstractQueryableRALBackendHandler<ShowDistVariablesStatement> {
-
- private static final String VARIABLE_NAME = "variable_name";
-
- private static final String VARIABLE_VALUE = "variable_value";
+public final class ShowDistVariablesExecutor implements
ConnectionSessionRequiredQueryableRALExecutor<ShowDistVariablesStatement> {
@Override
- protected Collection<String> getColumnNames() {
- return Arrays.asList(VARIABLE_NAME, VARIABLE_VALUE);
+ public Collection<String> getColumnNames() {
+ return Arrays.asList("variable_name", "variable_value");
}
@Override
- protected Collection<LocalDataQueryResultRow> getRows(final ContextManager
contextManager) {
- ConfigurationProperties props =
contextManager.getMetaDataContexts().getMetaData().getProps();
+ public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereMetaData metaData, final ConnectionSession connectionSession,
final ShowDistVariablesStatement sqlStatement) {
Collection<LocalDataQueryResultRow> result =
ConfigurationPropertyKey.getKeyNames().stream()
- .map(each -> new LocalDataQueryResultRow(each.toLowerCase(),
props.getValue(ConfigurationPropertyKey.valueOf(each)).toString())).collect(Collectors.toList());
+ .map(each -> new LocalDataQueryResultRow(each.toLowerCase(),
metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(each)).toString())).collect(Collectors.toList());
result.add(new LocalDataQueryResultRow(
VariableEnum.AGENT_PLUGINS_ENABLED.name().toLowerCase(),
SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(),
Boolean.TRUE.toString())));
- result.add(new
LocalDataQueryResultRow(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(),
getConnectionSession().getBackendConnection().getConnectionSize()));
- result.add(new
LocalDataQueryResultRow(VariableEnum.TRANSACTION_TYPE.name().toLowerCase(),
getConnectionSession().getTransactionStatus().getTransactionType().name()));
+ result.add(new
LocalDataQueryResultRow(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(),
connectionSession.getBackendConnection().getConnectionSize()));
+ result.add(new
LocalDataQueryResultRow(VariableEnum.TRANSACTION_TYPE.name().toLowerCase(),
connectionSession.getTransactionStatus().getTransactionType().name()));
return result;
}
+
+ @Override
+ public String getType() {
+ return ShowDistVariablesStatement.class.getName();
+ }
}
diff --git
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/executor/ConnectionSessionRequiredQueryableRALExecutor.java
similarity index 70%
copy from
distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
copy to
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/executor/ConnectionSessionRequiredQueryableRALExecutor.java
index 9d75207f530..69cdb2bae36 100644
---
a/distsql/handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/MetaDataRequiredQueryableRALExecutor.java
+++
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/executor/ConnectionSessionRequiredQueryableRALExecutor.java
@@ -15,25 +15,28 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.handler.ral.query;
+package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.executor;
+import
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import java.util.Collection;
/**
- * Meta data required queryable RAL executor.
+ * Connection session required queryable RAL executor.
*/
-public interface MetaDataRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor {
+public interface ConnectionSessionRequiredQueryableRALExecutor<T extends
QueryableRALStatement> extends QueryableRALExecutor<T> {
/**
* Get query result rows.
*
* @param metaData ShardingSphere meta data
+ * @param connectionSession connectionSession connection session
* @param sqlStatement SQL statement
* @return query result rows
*/
- Collection<LocalDataQueryResultRow> getRows(ShardingSphereMetaData
metaData, T sqlStatement);
+ Collection<LocalDataQueryResultRow> getRows(ShardingSphereMetaData
metaData, ConnectionSession connectionSession, T sqlStatement);
}
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 80782419144..743044a4df3 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
@@ -18,4 +18,6 @@
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowComputeNodesExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowComputeNodeInfoExecutor
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowComputeNodeModeExecutor
+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.ConvertYamlConfigurationExecutor
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
index 3c5df7ffe09..b0eb9332308 100644
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
@@ -37,9 +37,8 @@ import
org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminQueryB
import
org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminUpdateBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.data.impl.UnicastDatabaseBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.QueryableGlobalRuleRALBackendHandler;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.QueryableRALBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.hint.HintRALBackendHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowDistVariableHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowDistVariablesHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.SetDistVariableHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.RQLBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.rul.SQLRULBackendHandler;
@@ -117,10 +116,10 @@ public final class ProxyBackendHandlerFactoryTest extends
ProxyContextRestorer {
assertThat(actual, instanceOf(SetDistVariableHandler.class));
sql = "show dist variable where name = transaction_type";
actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql,
connectionSession);
- assertThat(actual, instanceOf(ShowDistVariableHandler.class));
+ assertThat(actual, instanceOf(QueryableRALBackendHandler.class));
sql = "show dist variables";
actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql,
connectionSession);
- assertThat(actual, instanceOf(ShowDistVariablesHandler.class));
+ assertThat(actual, instanceOf(QueryableRALBackendHandler.class));
sql = "set sharding hint database_value=1";
actual = ProxyBackendHandlerFactory.newInstance(databaseType, sql,
connectionSession);
assertThat(actual, instanceOf(HintRALBackendHandler.class));
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutorTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutorTest.java
index 8d9a66ed629..0a3bde4f9ed 100644
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutorTest.java
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutorTest.java
@@ -22,7 +22,6 @@ import com.google.common.base.Strings;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import
org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
@@ -39,7 +38,6 @@ import java.util.Objects;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
public final class ConvertYamlConfigurationExecutorTest {
@@ -86,12 +84,12 @@ public final class ConvertYamlConfigurationExecutorTest {
Collection<String> columns = executor.getColumnNames();
assertThat(columns.size(), is(1));
Iterator<String> iterator = columns.iterator();
- assertThat(iterator.next(), is("distsql"));
+ assertThat(iterator.next(), is("dist_sql"));
}
public void assertExecute(final String configFilePath, final String
expectedFilePath) throws SQLException {
ConvertYamlConfigurationExecutor executor = new
ConvertYamlConfigurationExecutor();
- Collection<LocalDataQueryResultRow> actual =
executor.getRows(mock(InstanceContext.class),
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(
new
ConvertYamlConfigurationStatement(Objects.requireNonNull(ConvertYamlConfigurationExecutorTest.class.getResource(configFilePath)).getPath()));
assertRowData(actual, expectedFilePath);
}
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java
deleted file mode 100644
index f80b81d5349..00000000000
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableBackendHandlerTest.java
+++ /dev/null
@@ -1,131 +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.proxy.backend.handler.distsql.ral.queryable;
-
-import io.netty.util.DefaultAttributeMap;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariableStatement;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
-import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.apache.shardingsphere.transaction.api.TransactionType;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShowDistVariableBackendHandlerTest extends
ProxyContextRestorer {
-
- private ConnectionSession connectionSession;
-
- @Before
- public void setup() {
- ProxyContext.init(mock(ContextManager.class, RETURNS_DEEP_STUBS));
-
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE)).thenReturn("OLAP");
- connectionSession = new
ConnectionSession(mock(MySQLDatabaseType.class), TransactionType.LOCAL, new
DefaultAttributeMap());
- }
-
- @Test
- public void assertShowTransactionType() throws SQLException {
- connectionSession.setCurrentDatabase("db");
- ShowDistVariableHandler backendHandler = new ShowDistVariableHandler();
- backendHandler.init(new ShowDistVariableStatement("transaction_type"),
connectionSession);
- ResponseHeader actual = backendHandler.execute();
- assertThat(actual, instanceOf(QueryResponseHeader.class));
- assertThat(((QueryResponseHeader) actual).getQueryHeaders().size(),
is(2));
- backendHandler.next();
- List<Object> rowData = backendHandler.getRowData().getData();
- assertThat(rowData.get(0), is("transaction_type"));
- assertThat(rowData.get(1), is("LOCAL"));
- }
-
- @Test
- public void assertShowCachedConnections() throws SQLException {
- connectionSession.setCurrentDatabase("db");
- ShowDistVariableHandler backendHandler = new ShowDistVariableHandler();
- backendHandler.init(new
ShowDistVariableStatement("cached_connections"), connectionSession);
- ResponseHeader actual = backendHandler.execute();
- assertThat(actual, instanceOf(QueryResponseHeader.class));
- assertThat(((QueryResponseHeader) actual).getQueryHeaders().size(),
is(2));
- backendHandler.next();
- List<Object> rowData = backendHandler.getRowData().getData();
- assertThat(rowData.get(0), is("cached_connections"));
- assertThat(rowData.get(1), is("0"));
- }
-
- @Test(expected = UnsupportedVariableException.class)
- public void assertShowCachedConnectionFailed() {
- connectionSession.setCurrentDatabase("db");
- ShowDistVariableHandler backendHandler = new ShowDistVariableHandler();
- backendHandler.init(new
ShowDistVariableStatement("cached_connectionss"), connectionSession);
- backendHandler.execute();
- }
-
- @Test
- public void assertShowAgentPluginsEnabled() throws SQLException {
-
SystemPropertyUtil.setSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(),
Boolean.TRUE.toString());
- connectionSession.setCurrentDatabase("db");
- ShowDistVariableHandler backendHandler = new ShowDistVariableHandler();
- backendHandler.init(new
ShowDistVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name()),
connectionSession);
- ResponseHeader actual = backendHandler.execute();
- assertThat(actual, instanceOf(QueryResponseHeader.class));
- assertThat(((QueryResponseHeader) actual).getQueryHeaders().size(),
is(2));
- backendHandler.next();
- List<Object> rowData = backendHandler.getRowData().getData();
- assertThat(rowData.get(0), is("agent_plugins_enabled"));
- assertThat(rowData.get(1), is(Boolean.TRUE.toString()));
- }
-
- @Test
- public void assertShowPropsVariable() throws SQLException {
- connectionSession.setCurrentDatabase("db");
- ContextManager contextManager = mock(ContextManager.class);
- ProxyContext.init(contextManager);
- MetaDataContexts metaDataContexts = mock(MetaDataContexts.class,
RETURNS_DEEP_STUBS);
-
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- when(metaDataContexts.getMetaData().getProps()).thenReturn(new
ConfigurationProperties(PropertiesBuilder.build(new Property("sql-show",
Boolean.TRUE.toString()))));
- ShowDistVariableHandler backendHandler = new ShowDistVariableHandler();
- backendHandler.init(new ShowDistVariableStatement("SQL_SHOW"),
connectionSession);
- ResponseHeader actual = backendHandler.execute();
- assertThat(actual, instanceOf(QueryResponseHeader.class));
- assertThat(((QueryResponseHeader) actual).getQueryHeaders().size(),
is(2));
- backendHandler.next();
- List<Object> rowData = backendHandler.getRowData().getData();
- assertThat(rowData.get(0), is("sql_show"));
- assertThat(rowData.get(1), is(Boolean.TRUE.toString()));
- }
-}
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
new file mode 100644
index 00000000000..89a899b619a
--- /dev/null
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.proxy.backend.handler.distsql.ral.queryable;
+
+import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariableStatement;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import
org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.enums.VariableEnum;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
+import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.apache.shardingsphere.transaction.api.TransactionType;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShowDistVariableExecutorTest extends ProxyContextRestorer {
+
+ private final ShardingSphereMetaData metaData =
mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+
+ private final ConnectionSession connectionSession =
mock(ConnectionSession.class, RETURNS_DEEP_STUBS);
+
+ @Test
+ public void assertGetColumns() {
+ ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
+ Collection<String> columns = executor.getColumnNames();
+ assertThat(columns.size(), is(2));
+ Iterator<String> iterator = columns.iterator();
+ assertThat(iterator.next(), is("variable_name"));
+ assertThat(iterator.next(), is("variable_value"));
+ }
+
+ @Test
+ public void assertShowTransactionType() {
+
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
+ ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(metaData, connectionSession, new
ShowDistVariableStatement("TRANSACTION_TYPE"));
+ assertThat(actual.size(), is(1));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("transaction_type"));
+ assertThat(row.getCell(2), is("LOCAL"));
+ }
+
+ @Test
+ public void assertShowCachedConnections() {
+
when(connectionSession.getBackendConnection().getConnectionSize()).thenReturn(1);
+ ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(metaData, connectionSession, new
ShowDistVariableStatement("CACHED_CONNECTIONS"));
+ assertThat(actual.size(), is(1));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("cached_connections"));
+ assertThat(row.getCell(2), is("1"));
+ }
+
+ @Test
+ public void assertShowAgentPluginsEnabled() {
+
SystemPropertyUtil.setSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(),
Boolean.FALSE.toString());
+ ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(metaData, connectionSession, new
ShowDistVariableStatement("AGENT_PLUGINS_ENABLED"));
+ assertThat(actual.size(), is(1));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("agent_plugins_enabled"));
+ assertThat(row.getCell(2), is("false"));
+ }
+
+ @Test
+ public void assertShowPropsVariable() {
+ when(metaData.getProps()).thenReturn(new
ConfigurationProperties(PropertiesBuilder.build(new Property("sql-show",
Boolean.TRUE.toString()))));
+ ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(metaData, connectionSession, new
ShowDistVariableStatement("SQL_SHOW"));
+ assertThat(actual.size(), is(1));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("sql_show"));
+ assertThat(row.getCell(2), is("true"));
+ }
+
+ @Test(expected = UnsupportedVariableException.class)
+ public void assertExecuteWithInvalidVariableName() {
+ new ShowDistVariableExecutor().getRows(metaData, connectionSession,
new ShowDistVariableStatement("wrong_name"));
+ }
+}
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
new file mode 100644
index 00000000000..e84e96d946f
--- /dev/null
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.proxy.backend.handler.distsql.ral.queryable;
+
+import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariablesStatement;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShowDistVariablesExecutorTest extends ProxyContextRestorer {
+
+ private final ShardingSphereMetaData metaData =
mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+
+ private final ConnectionSession connectionSession =
mock(ConnectionSession.class, RETURNS_DEEP_STUBS);
+
+ @Test
+ public void assertGetColumns() {
+ ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
+ Collection<String> columns = executor.getColumnNames();
+ assertThat(columns.size(), is(2));
+ Iterator<String> iterator = columns.iterator();
+ assertThat(iterator.next(), is("variable_name"));
+ assertThat(iterator.next(), is("variable_value"));
+ }
+
+ @Test
+ public void assertExecute() throws SQLException {
+ when(metaData.getProps()).thenReturn(new
ConfigurationProperties(PropertiesBuilder.build(new
Property("system_log_level", "INFO"))));
+ ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(metaData, connectionSession,
mock(ShowDistVariablesStatement.class));
+ assertThat(actual.size(), is(21));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("system_log_level"));
+ assertThat(row.getCell(2), is("INFO"));
+ }
+}
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java
deleted file mode 100644
index c4ac6ce6600..00000000000
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesHandlerTest.java
+++ /dev/null
@@ -1,77 +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.proxy.backend.handler.distsql.ral.queryable;
-
-import io.netty.util.DefaultAttributeMap;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowDistVariablesStatement;
-import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.apache.shardingsphere.transaction.api.TransactionType;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public final class ShowDistVariablesHandlerTest extends ProxyContextRestorer {
-
- @Before
- public void setup() {
- ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
- MetaDataContexts metaDataContexts = mockMetaDataContexts();
-
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- ProxyContext.init(contextManager);
- }
-
- private MetaDataContexts mockMetaDataContexts() {
- MetaDataContexts result = mock(MetaDataContexts.class,
RETURNS_DEEP_STUBS);
- when(result.getMetaData().getProps()).thenReturn(
- new ConfigurationProperties(PropertiesBuilder.build(new
Property(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE.getKey(),
"OLAP"))));
- return result;
- }
-
- @Test
- public void assertExecute() throws SQLException {
- ConnectionSession connectionSession = new
ConnectionSession(mock(MySQLDatabaseType.class), TransactionType.LOCAL, new
DefaultAttributeMap());
- connectionSession.setCurrentDatabase("foo_db");
- ShowDistVariablesHandler handler = new ShowDistVariablesHandler();
- handler.init(new ShowDistVariablesStatement(), connectionSession);
- ResponseHeader actual = handler.execute();
- assertThat(((QueryResponseHeader) actual).getQueryHeaders().size(),
is(2));
- handler.next();
- List<Object> rowData = handler.getRowData().getData();
- assertThat(rowData.get(0), is("system_log_level"));
- assertThat(rowData.get(1), is("INFO"));
- }
-}