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 494164ce900 Refactor ShowDistVariableExecutor and 
ShowDistVariablesExecutor (#38015)
494164ce900 is described below

commit 494164ce900b593979c70adaa6f08908bfab1b13
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 12 11:38:02 2026 +0800

    Refactor ShowDistVariableExecutor and ShowDistVariablesExecutor (#38015)
    
    * Refactor ShowDistVariableExecutor
    
    * Refactor ShowDistVariableExecutor and ShowDistVariablesExecutor
---
 .../distsql/ral/common/DistSQLVariable.java        | 19 +----------
 .../variable/ShowDistVariableExecutor.java         | 16 ++++++---
 .../variable/ShowDistVariablesExecutor.java        |  4 ---
 .../distsql/ral/common/DistSQLVariableTest.java    | 38 ----------------------
 .../variable/ShowDistVariableExecutorTest.java     | 11 +++++++
 5 files changed, 23 insertions(+), 65 deletions(-)

diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariable.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariable.java
index c39bda375b3..b9a65cd0d0c 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariable.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariable.java
@@ -17,27 +17,10 @@
 
 package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common;
 
-import 
org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException;
-
 /**
  * DistSQL variable.
  */
 public enum DistSQLVariable {
     
-    CACHED_CONNECTIONS;
-    
-    /**
-     * Returns the variable constant of the specified variable name.
-     *
-     * @param variableName variable name
-     * @return variable constant
-     * @throws UnsupportedVariableException unsupported variable exception
-     */
-    public static DistSQLVariable getValueOf(final String variableName) {
-        try {
-            return valueOf(variableName.toUpperCase());
-        } catch (final IllegalArgumentException ignored) {
-            throw new UnsupportedVariableException(variableName);
-        }
-    }
+    CACHED_CONNECTIONS
 }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutor.java
index 711dda1efc6..8abcff831ac 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutor.java
@@ -32,7 +32,6 @@ import 
org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.DistSQLVariable;
 
-import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -80,17 +79,24 @@ public final class ShowDistVariableExecutor implements 
DistSQLQueryExecutor<Show
     }
     
     private String getConnectionSize(final String variableName) {
-        
ShardingSpherePreconditions.checkState(DistSQLVariable.CACHED_CONNECTIONS == 
DistSQLVariable.getValueOf(variableName), () -> new 
UnsupportedVariableException(variableName));
+        checkVariableName(variableName);
         return String.valueOf(connectionContext.getConnectionSize());
     }
     
+    private void checkVariableName(final String variableName) {
+        DistSQLVariable distSQLVariable;
+        try {
+            distSQLVariable = 
DistSQLVariable.valueOf(variableName.toUpperCase());
+        } catch (final IllegalArgumentException ignored) {
+            throw new UnsupportedVariableException(variableName);
+        }
+        
ShardingSpherePreconditions.checkState(DistSQLVariable.CACHED_CONNECTIONS == 
distSQLVariable, () -> new UnsupportedVariableException(variableName));
+    }
+    
     private String getStringResult(final Object value) {
         if (null == value) {
             return "";
         }
-        if (value instanceof Float || value instanceof Double) {
-            return new BigDecimal(String.valueOf(value)).toPlainString();
-        }
         return value instanceof TypedSPI ? ((TypedSPI) 
value).getType().toString() : value.toString();
     }
     
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 3440edb6808..4eca8d84507 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
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.infra.util.regex.RegexUtils;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.DistSQLVariable;
 
-import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
@@ -76,9 +75,6 @@ public final class ShowDistVariablesExecutor implements 
DistSQLQueryExecutor<Sho
         if (null == value) {
             return "";
         }
-        if (value instanceof Float || value instanceof Double) {
-            return new BigDecimal(String.valueOf(value)).toPlainString();
-        }
         return value instanceof TypedSPI ? ((TypedSPI) 
value).getType().toString() : value.toString();
     }
     
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariableTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariableTest.java
deleted file mode 100644
index 9f6d2d6410a..00000000000
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/DistSQLVariableTest.java
+++ /dev/null
@@ -1,38 +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.common;
-
-import 
org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedVariableException;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class DistSQLVariableTest {
-    
-    @Test
-    void assertGetValueOfExistingVariable() {
-        assertThat(DistSQLVariable.getValueOf("cached_connections"), 
is(DistSQLVariable.CACHED_CONNECTIONS));
-    }
-    
-    @Test
-    void assertGetValueOfUnsupportedVariable() {
-        assertThrows(UnsupportedVariableException.class, () -> 
DistSQLVariable.getValueOf("unsupported"));
-    }
-}
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
index afc34624cae..1f914d7ccd7 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/variable/ShowDistVariableExecutorTest.java
@@ -32,7 +32,9 @@ import 
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
 import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
 import org.apache.shardingsphere.mode.manager.ContextManager;
+import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.DistSQLVariable;
 import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
 
 import java.util.Collection;
 import java.util.Iterator;
@@ -43,6 +45,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
 import static org.mockito.Mockito.when;
 
 class ShowDistVariableExecutorTest {
@@ -117,4 +120,12 @@ class ShowDistVariableExecutorTest {
     void assertExecuteWithInvalidVariableName() {
         assertThrows(UnsupportedVariableException.class, () -> 
executor.getRows(new ShowDistVariableStatement("wrong_name"), contextManager));
     }
+    
+    @Test
+    void assertExecuteWithUnsupportedDistSQLVariable() {
+        try (MockedStatic<DistSQLVariable> mockedStatic = 
mockStatic(DistSQLVariable.class)) {
+            mockedStatic.when(() -> 
DistSQLVariable.valueOf("CACHED_CONNECTIONS")).thenReturn(null);
+            assertThrows(UnsupportedVariableException.class, () -> 
executor.getRows(new ShowDistVariableStatement("CACHED_CONNECTIONS"), 
contextManager));
+        }
+    }
 }

Reply via email to