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 2025/10/17 15:49:19 UTC

(shardingsphere) branch master updated: Add OpenGaussSelectAdminExecutorFactory (#36895)

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 a404f2b4004 Add OpenGaussSelectAdminExecutorFactory (#36895)
a404f2b4004 is described below

commit a404f2b400456c0c1248956de8bda10f7cbc6672
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Oct 17 23:49:13 2025 +0800

    Add OpenGaussSelectAdminExecutorFactory (#36895)
    
    * Add OpenGaussSelectAdminExecutorFactory
    
    * Add OpenGaussSelectAdminExecutorFactory
    
    * Add OpenGaussSelectAdminExecutorFactory
---
 .../admin/OpenGaussAdminExecutorCreator.java       | 13 +---
 .../OpenGaussSelectAdminExecutorFactory.java       | 49 +++++++++++++
 .../factory/OpenGaussAdminExecutorFactoryTest.java | 85 ----------------------
 3 files changed, 53 insertions(+), 94 deletions(-)

diff --git a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
index c1c2807e6e1..0a693b4f196 100644
--- a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
+++ b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
@@ -22,8 +22,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectS
 import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
 import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutorCreator;
 import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.executor.OpenGaussShowVariableExecutor;
-import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.factory.OpenGaussSystemFunctionQueryExecutorFactory;
-import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.factory.OpenGaussSystemTableQueryExecutorFactory;
+import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.factory.OpenGaussSelectAdminExecutorFactory;
 import org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLAdminExecutorCreator;
 import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ShowStatement;
 
@@ -40,13 +39,9 @@ public final class OpenGaussAdminExecutorCreator implements DatabaseAdminExecuto
     @Override
     public Optional<DatabaseAdminExecutor> create(final SQLStatementContext sqlStatementContext, final String sql, final String databaseName, final List<Object> parameters) {
         if (sqlStatementContext instanceof SelectStatementContext) {
-            Optional<DatabaseAdminExecutor> systemTableQueryExecutor = OpenGaussSystemTableQueryExecutorFactory.newInstance((SelectStatementContext) sqlStatementContext, sql, parameters);
-            if (systemTableQueryExecutor.isPresent()) {
-                return systemTableQueryExecutor;
-            }
-            Optional<DatabaseAdminExecutor> systemFunctionQueryExecutor = OpenGaussSystemFunctionQueryExecutorFactory.newInstance((SelectStatementContext) sqlStatementContext);
-            if (systemFunctionQueryExecutor.isPresent()) {
-                return systemFunctionQueryExecutor;
+            Optional<DatabaseAdminExecutor> selectAdminExecutor = OpenGaussSelectAdminExecutorFactory.newInstance((SelectStatementContext) sqlStatementContext, sql, parameters);
+            if (selectAdminExecutor.isPresent()) {
+                return selectAdminExecutor;
             }
         }
         if (sqlStatementContext.getSqlStatement() instanceof ShowStatement) {
diff --git a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSelectAdminExecutorFactory.java b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSelectAdminExecutorFactory.java
new file mode 100644
index 00000000000..f0fade2561c
--- /dev/null
+++ b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSelectAdminExecutorFactory.java
@@ -0,0 +1,49 @@
+/*
+ * 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.opengauss.handler.admin.factory;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
+import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Select admin executor factory for openGauss.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class OpenGaussSelectAdminExecutorFactory {
+    
+    /**
+     * Create new instance of database admin executor.
+     *
+     * @param selectStatementContext select statement
+     * @param sql SQL
+     * @param parameters SQL parameters
+     * @return created instance
+     */
+    public static Optional<DatabaseAdminExecutor> newInstance(final SelectStatementContext selectStatementContext, final String sql, final List<Object> parameters) {
+        Optional<DatabaseAdminExecutor> systemTableQueryExecutor = OpenGaussSystemTableQueryExecutorFactory.newInstance(selectStatementContext, sql, parameters);
+        if (systemTableQueryExecutor.isPresent()) {
+            return systemTableQueryExecutor;
+        }
+        return OpenGaussSystemFunctionQueryExecutorFactory.newInstance(selectStatementContext);
+    }
+}
diff --git a/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussAdminExecutorFactoryTest.java b/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussAdminExecutorFactoryTest.java
deleted file mode 100644
index 8031dc7c37a..00000000000
--- a/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussAdminExecutorFactoryTest.java
+++ /dev/null
@@ -1,85 +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.opengauss.handler.admin.factory;
-
-import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.metadata.statistics.collector.DialectDatabaseStatisticsCollector;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.OpenGaussAdminExecutorCreator;
-import org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLAdminExecutorCreator;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dal.ShowStatement;
-import org.apache.shardingsphere.test.infra.framework.mock.AutoMockExtension;
-import org.apache.shardingsphere.test.infra.framework.mock.StaticMockSettings;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.internal.configuration.plugins.Plugins;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(AutoMockExtension.class)
-@StaticMockSettings(DatabaseTypedSPILoader.class)
-class OpenGaussAdminExecutorFactoryTest {
-    
-    private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "openGauss");
-    
-    @Mock
-    private PostgreSQLAdminExecutorCreator postgresqlAdminExecutorFactory;
-    
-    private OpenGaussAdminExecutorCreator openGaussAdminExecutorFactory;
-    
-    @BeforeEach
-    void setup() throws ReflectiveOperationException {
-        openGaussAdminExecutorFactory = new OpenGaussAdminExecutorCreator();
-        Plugins.getMemberAccessor().set(OpenGaussAdminExecutorCreator.class.getDeclaredField("delegate"), openGaussAdminExecutorFactory, postgresqlAdminExecutorFactory);
-    }
-    
-    @Test
-    void assertNewInstanceWithSQLStatementContext() {
-        SQLStatementContext sqlStatementContext = new CommonSQLStatementContext(new ShowStatement(databaseType, "all"));
-        Optional<DatabaseAdminExecutor> actual = openGaussAdminExecutorFactory.create(sqlStatementContext, "SHOW ALL", null, Collections.emptyList());
-        assertTrue(actual.isPresent());
-    }
-    
-    @Test
-    void assertNewInstanceWithOtherSQL() {
-        DialectDatabaseStatisticsCollector statisticsCollector = mock(DialectDatabaseStatisticsCollector.class);
-        when(DatabaseTypedSPILoader.findService(DialectDatabaseStatisticsCollector.class, TypedSPILoader.getService(DatabaseType.class, "openGauss"))).thenReturn(Optional.of(statisticsCollector));
-        SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
-        when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.emptyList());
-        DatabaseAdminExecutor expected = mock(DatabaseAdminExecutor.class);
-        when(postgresqlAdminExecutorFactory.create(sqlStatementContext, "", "", Collections.emptyList())).thenReturn(Optional.of(expected));
-        Optional<DatabaseAdminExecutor> actual = openGaussAdminExecutorFactory.create(sqlStatementContext, "", "", Collections.emptyList());
-        assertTrue(actual.isPresent());
-        assertThat(actual.get(), is(expected));
-    }
-}