You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/11/21 07:56:41 UTC

(shardingsphere) branch master updated: Refactor usage of VariableSegment (#33755)

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

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new fbbbd855702 Refactor usage of VariableSegment (#33755)
fbbbd855702 is described below

commit fbbbd85570223dd76050a42726095a4bd7e414ec
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Nov 21 15:56:35 2024 +0800

    Refactor usage of VariableSegment (#33755)
---
 .../visitor/statement/type/DorisDALStatementVisitor.java     |  2 +-
 .../admin/executor/MySQLSetVariableAdminExecutorTest.java    |  3 +--
 .../admin/executor/MySQLSystemVariableQueryExecutorTest.java | 12 ++++--------
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java
index 05b2ae0c04b..b625e117f02 100644
--- a/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java
+++ b/parser/sql/dialect/doris/src/main/java/org/apache/shardingsphere/sql/parser/doris/visitor/statement/type/DorisDALStatementVisitor.java
@@ -982,7 +982,7 @@ public final class DorisDALStatementVisitor extends DorisStatementVisitor implem
         int stopIndex = null == ctx.CHARSET() ? ctx.SET(1).getSymbol().getStopIndex() : ctx.CHARSET().getSymbol().getStopIndex();
         // TODO Consider setting all three system variables: character_set_client, character_set_results, character_set_connection
         VariableSegment variable = new VariableSegment(startIndex, stopIndex, (null == ctx.CHARSET()) ? "character_set_client" : ctx.CHARSET().getText());
-        String assignValue = (null == ctx.DEFAULT()) ? ctx.charsetName().getText() : ctx.DEFAULT().getText();
+        String assignValue = null == ctx.DEFAULT() ? ctx.charsetName().getText() : ctx.DEFAULT().getText();
         VariableAssignSegment characterSet = new VariableAssignSegment(startIndex, stopIndex, variable, assignValue);
         DorisSetStatement result = new DorisSetStatement();
         result.getVariableAssigns().add(characterSet);
diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
index be10c6f74da..cd8b97463e1 100644
--- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
+++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
@@ -87,8 +87,7 @@ class MySQLSetVariableAdminExecutorTest {
     }
     
     private SetStatement prepareSetStatement() {
-        VariableSegment maxConnectionVariableSegment = new VariableSegment(0, 0, "max_connections");
-        maxConnectionVariableSegment.setScope("global");
+        VariableSegment maxConnectionVariableSegment = new VariableSegment(0, 0, "max_connections", "global");
         VariableAssignSegment setGlobalMaxConnectionAssignSegment = new VariableAssignSegment(0, 0, maxConnectionVariableSegment, "151");
         VariableSegment characterSetClientSegment = new VariableSegment(0, 0, "character_set_client");
         VariableAssignSegment setCharacterSetClientVariableSegment = new VariableAssignSegment(0, 0, characterSetClientSegment, "'utf8mb4'");
diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java
index 2924796579e..22bcd49130a 100644
--- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java
+++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java
@@ -47,8 +47,7 @@ class MySQLSystemVariableQueryExecutorTest {
     void assertTryGetSystemVariableQueryExecutorWithOtherExpressionProjection() {
         MySQLSelectStatement selectStatement = new MySQLSelectStatement();
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
-        VariableSegment variable = new VariableSegment(0, 0, "max_connections");
-        variable.setScope("session");
+        VariableSegment variable = new VariableSegment(0, 0, "max_connections", "session");
         selectStatement.getProjections().getProjections().add(new ExpressionProjectionSegment(0, 0, "@@session.max_connections", variable));
         selectStatement.getProjections().getProjections().add(new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("some_column"))));
         assertFalse(MySQLSystemVariableQueryExecutor.tryGetSystemVariableQueryExecutor(selectStatement).isPresent());
@@ -66,11 +65,9 @@ class MySQLSystemVariableQueryExecutorTest {
     void assertTryGetSystemVariableQueryExecutorAndExecuteWithCorrectScope() throws SQLException {
         MySQLSelectStatement selectStatement = new MySQLSelectStatement();
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
-        VariableSegment maxConnectionsVariable = new VariableSegment(0, 0, "max_connections");
-        maxConnectionsVariable.setScope("global");
+        VariableSegment maxConnectionsVariable = new VariableSegment(0, 0, "max_connections", "global");
         selectStatement.getProjections().getProjections().add(new ExpressionProjectionSegment(0, 0, "@@global.max_connections", maxConnectionsVariable));
-        VariableSegment warningCountVariable = new VariableSegment(0, 0, "warning_count");
-        warningCountVariable.setScope("session");
+        VariableSegment warningCountVariable = new VariableSegment(0, 0, "warning_count", "session");
         ExpressionProjectionSegment warningCountProjection = new ExpressionProjectionSegment(0, 0, "@@session.warning_count", warningCountVariable);
         warningCountProjection.setAlias(new AliasSegment(0, 0, new IdentifierValue("session_warning")));
         selectStatement.getProjections().getProjections().add(warningCountProjection);
@@ -96,8 +93,7 @@ class MySQLSystemVariableQueryExecutorTest {
     void assertExecuteWithIncorrectScope() {
         MySQLSelectStatement selectStatement = new MySQLSelectStatement();
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
-        VariableSegment variable = new VariableSegment(0, 0, "max_connections");
-        variable.setScope("session");
+        VariableSegment variable = new VariableSegment(0, 0, "max_connections", "session");
         selectStatement.getProjections().getProjections().add(new ExpressionProjectionSegment(0, 0, "@@session.max_connections", variable));
         Optional<DatabaseAdminExecutor> executor = MySQLSystemVariableQueryExecutor.tryGetSystemVariableQueryExecutor(selectStatement);
         assertTrue(executor.isPresent());