This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 ed4bc5e2022 Hide temporary properties by default for 'show dist
variables' (#36592)
ed4bc5e2022 is described below
commit ed4bc5e2022091c800db4ad54fee8f79289701e6
Author: Raigor <[email protected]>
AuthorDate: Wed Sep 17 10:08:56 2025 +0800
Hide temporary properties by default for 'show dist variables' (#36592)
* Hide temporary properties by default for 'show dist variables'
* Update RAL e2e
* Update RAL e2e
---
.../engine/src/main/antlr4/imports/Keyword.g4 | 4 ++++
.../engine/src/main/antlr4/imports/RALStatement.g4 | 2 +-
.../core/kernel/KernelDistSQLStatementVisitor.java | 2 +-
.../queryable/show/ShowDistVariablesStatement.java | 4 ++++
.../variable/ShowDistVariablesExecutor.java | 17 ++++++++-----
.../variable/ShowDistVariablesExecutorTest.java | 28 ++++++++++++++++++++--
.../dataset/empty_rules/show_dist_variables.xml | 3 ---
7 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
b/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
index d369824714b..abf97b440a5 100644
--- a/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
+++ b/parser/distsql/engine/src/main/antlr4/imports/Keyword.g4
@@ -346,3 +346,7 @@ CHECK_PRIVILEGES
TIMEOUT
: T I M E O U T
;
+
+TEMP
+ : T E M P
+ ;
diff --git a/parser/distsql/engine/src/main/antlr4/imports/RALStatement.g4
b/parser/distsql/engine/src/main/antlr4/imports/RALStatement.g4
index 3960092952c..9eff44ac377 100644
--- a/parser/distsql/engine/src/main/antlr4/imports/RALStatement.g4
+++ b/parser/distsql/engine/src/main/antlr4/imports/RALStatement.g4
@@ -28,7 +28,7 @@ showDistVariable
;
showDistVariables
- : SHOW DIST VARIABLES showLike?
+ : SHOW TEMP? DIST VARIABLES showLike?
;
alterComputeNode
diff --git
a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
index c9753b4f53a..b9c7239c8e2 100644
---
a/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
+++
b/parser/distsql/engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
@@ -249,7 +249,7 @@ public final class KernelDistSQLStatementVisitor extends
KernelDistSQLStatementB
@Override
public ASTNode visitShowDistVariables(final ShowDistVariablesContext ctx) {
- return new ShowDistVariablesStatement(null == ctx.showLike() ? null :
IdentifierValueUtils.getValue(ctx.showLike().likePattern()));
+ return new ShowDistVariablesStatement(null != ctx.TEMP(), null ==
ctx.showLike() ? null :
IdentifierValueUtils.getValue(ctx.showLike().likePattern()));
}
@Override
diff --git
a/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/queryable/show/ShowDistVariablesStatement.java
b/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/queryable/show/ShowDistVariablesStatement.java
index fffcfc28158..71a7d14af2e 100644
---
a/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/queryable/show/ShowDistVariablesStatement.java
+++
b/parser/distsql/statement/src/main/java/org/apache/shardingsphere/distsql/statement/type/ral/queryable/show/ShowDistVariablesStatement.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.distsql.statement.type.ral.queryable.show;
+import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.distsql.statement.type.ral.queryable.QueryableRALStatement;
@@ -28,6 +29,9 @@ import java.util.Optional;
@RequiredArgsConstructor
public final class ShowDistVariablesStatement extends QueryableRALStatement {
+ @Getter
+ private final boolean showTemporary;
+
private final String likePattern;
/**
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutor.java
index 5b21df95132..3440edb6808 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutor.java
@@ -35,6 +35,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
+import java.util.LinkedList;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -54,12 +55,16 @@ public final class ShowDistVariablesExecutor implements
DistSQLQueryExecutor<Sho
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowDistVariablesStatement sqlStatement, final ContextManager contextManager) {
ShardingSphereMetaData metaData =
contextManager.getMetaDataContexts().getMetaData();
- Collection<LocalDataQueryResultRow> result =
ConfigurationPropertyKey.getKeyNames().stream()
- .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(),
getStringResult(metaData.getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.valueOf(each)))))
- .collect(Collectors.toList()));
- result.add(new
LocalDataQueryResultRow(DistSQLVariable.CACHED_CONNECTIONS.name().toLowerCase(),
connectionContext.getConnectionSize()));
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+ if (sqlStatement.isShowTemporary()) {
+
result.addAll(TemporaryConfigurationPropertyKey.getKeyNames().stream()
+ .map(each -> new
LocalDataQueryResultRow(each.toLowerCase(),
getStringResult(metaData.getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.valueOf(each)))))
+ .collect(Collectors.toList()));
+ } else {
+ result.addAll(ConfigurationPropertyKey.getKeyNames().stream()
+ .map(each -> new
LocalDataQueryResultRow(each.toLowerCase(),
getStringResult(metaData.getProps().getValue(ConfigurationPropertyKey.valueOf(each))))).collect(Collectors.toList()));
+ result.add(new
LocalDataQueryResultRow(DistSQLVariable.CACHED_CONNECTIONS.name().toLowerCase(),
connectionContext.getConnectionSize()));
+ }
if (sqlStatement.getLikePattern().isPresent()) {
String pattern =
RegexUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get());
result = result.stream().filter(each -> Pattern.compile(pattern,
Pattern.CASE_INSENSITIVE).matcher((String)
each.getCell(1)).matches()).collect(Collectors.toList());
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
index bf7829d5978..23f4b3fef68 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariablesExecutorTest.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import
org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
import
org.apache.shardingsphere.distsql.statement.type.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.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;
@@ -32,6 +33,7 @@ import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -50,7 +52,7 @@ class ShowDistVariablesExecutorTest {
executor.setConnectionContext(new
DistSQLConnectionContext(mock(QueryContext.class), 1,
mock(DatabaseType.class),
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
Collection<LocalDataQueryResultRow> actual =
executor.getRows(mock(ShowDistVariablesStatement.class), contextManager);
- assertThat(actual.size(), is(23));
+ assertThat(actual.size(), is(20));
LocalDataQueryResultRow row = actual.iterator().next();
assertThat(row.getCell(1), is("agent_plugins_enabled"));
assertThat(row.getCell(2), is("false"));
@@ -61,10 +63,32 @@ class ShowDistVariablesExecutorTest {
ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
executor.setConnectionContext(new
DistSQLConnectionContext(mock(QueryContext.class), 1,
mock(DatabaseType.class),
mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class)));
- Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowDistVariablesStatement("sql_%"), contextManager);
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowDistVariablesStatement(false, "sql_%"), contextManager);
assertThat(actual.size(), is(2));
Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
assertThat(iterator.next().getCell(1), is("sql_show"));
assertThat(iterator.next().getCell(1), is("sql_simple"));
}
+
+ @Test
+ void assertExecuteTemporary() {
+
when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps()).thenReturn(new
TemporaryConfigurationProperties(new Properties()));
+ ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
+ ShowDistVariablesStatement sqlStatement = new
ShowDistVariablesStatement(true, null);
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(sqlStatement, contextManager);
+ assertThat(actual.size(), is(3));
+ LocalDataQueryResultRow row = actual.iterator().next();
+ assertThat(row.getCell(1), is("proxy_meta_data_collector_cron"));
+ assertThat(row.getCell(2), is("0 0/1 * * * ?"));
+ }
+
+ @Test
+ void assertExecuteTemporaryWithLike() {
+ ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor();
+ Collection<LocalDataQueryResultRow> actual = executor.getRows(new
ShowDistVariablesStatement(true, "proxy_%"), contextManager);
+ assertThat(actual.size(), is(2));
+ Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
+ assertThat(iterator.next().getCell(1),
is("proxy_meta_data_collector_cron"));
+ assertThat(iterator.next().getCell(1),
is("proxy_meta_data_collector_enabled"));
+ }
}
diff --git
a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/show_dist_variables.xml
b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/show_dist_variables.xml
index b57e9750e9f..682269d0eca 100644
---
a/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/show_dist_variables.xml
+++
b/test/e2e/sql/src/test/resources/cases/ral/dataset/empty_rules/show_dist_variables.xml
@@ -37,10 +37,7 @@
<row values="proxy_frontend_ssl_cipher| " />
<row values="proxy_frontend_ssl_enabled| true" />
<row values="proxy_frontend_ssl_version| TLSv1.2,TLSv1.3" />
- <row values="proxy_meta_data_collector_cron| 0 0/1 * * * ?" />
- <row values="proxy_meta_data_collector_enabled| true" />
<row values="proxy_netty_backlog| 1024" />
<row values="sql_show| false" />
<row values="sql_simple| false" />
- <row values="system_schema_metadata_assembly_enabled| true" />
</dataset>