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:39:12 UTC
(shardingsphere) branch master updated: Refactor OpenGaussSystemFunctionQueryExecutorFactory (#36894)
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 efaf8f85bf3 Refactor OpenGaussSystemFunctionQueryExecutorFactory (#36894)
efaf8f85bf3 is described below
commit efaf8f85bf38f0b79af86d6a823df716f127a68c
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Oct 17 23:39:06 2025 +0800
Refactor OpenGaussSystemFunctionQueryExecutorFactory (#36894)
---
.../admin/OpenGaussAdminExecutorCreator.java | 6 ++--
...penGaussSystemFunctionQueryExecutorFactory.java | 35 +++++++---------------
...aussSystemFunctionQueryExecutorFactoryTest.java | 12 ++------
3 files changed, 16 insertions(+), 37 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 b3ae0b4fccc..c1c2807e6e1 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
@@ -44,9 +44,9 @@ public final class OpenGaussAdminExecutorCreator implements DatabaseAdminExecuto
if (systemTableQueryExecutor.isPresent()) {
return systemTableQueryExecutor;
}
- OpenGaussSystemFunctionQueryExecutorFactory functionQueryExecutorCreator = new OpenGaussSystemFunctionQueryExecutorFactory((SelectStatementContext) sqlStatementContext);
- if (functionQueryExecutorCreator.accept()) {
- return functionQueryExecutorCreator.newInstance();
+ Optional<DatabaseAdminExecutor> systemFunctionQueryExecutor = OpenGaussSystemFunctionQueryExecutorFactory.newInstance((SelectStatementContext) sqlStatementContext);
+ if (systemFunctionQueryExecutor.isPresent()) {
+ return systemFunctionQueryExecutor;
}
}
if (sqlStatementContext.getSqlStatement() instanceof ShowStatement) {
diff --git a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactory.java b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactory.java
index 8b68b4a974a..8e5b89c7cf7 100644
--- a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactory.java
+++ b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactory.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.factory;
-import lombok.RequiredArgsConstructor;
+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 org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.executor.OpenGaussSelectPasswordDeadlineExecutor;
@@ -25,7 +26,6 @@ import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.executor.
import org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.executor.OpenGaussSelectVersionExecutor;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment;
-import org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
import java.util.Collection;
import java.util.Optional;
@@ -33,36 +33,21 @@ import java.util.Optional;
/**
* System function query executor factory for openGauss.
*/
-@RequiredArgsConstructor
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class OpenGaussSystemFunctionQueryExecutorFactory {
- private final SelectStatementContext sqlStatementContext;
-
- private String functionName;
-
- /**
- * Accept.
- *
- * @return true or false
- */
- public boolean accept() {
- SelectStatement selectStatement = sqlStatementContext.getSqlStatement();
- Collection<ProjectionSegment> projections = selectStatement.getProjections().getProjections();
- if (1 == projections.size() && projections.iterator().next() instanceof ExpressionProjectionSegment) {
- functionName = ((ExpressionProjectionSegment) projections.iterator().next()).getText();
- return OpenGaussSelectVersionExecutor.accept(functionName)
- || OpenGaussSelectPasswordDeadlineExecutor.accept(functionName)
- || OpenGaussSelectPasswordNotifyTimeExecutor.accept(functionName);
- }
- return false;
- }
-
/**
* Create new instance of system function query executor.
*
+ * @param sqlStatementContext select statement context
* @return created instance
*/
- public Optional<DatabaseAdminExecutor> newInstance() {
+ public static Optional<DatabaseAdminExecutor> newInstance(final SelectStatementContext sqlStatementContext) {
+ Collection<ProjectionSegment> projections = sqlStatementContext.getSqlStatement().getProjections().getProjections();
+ if (1 != projections.size() || !(projections.iterator().next() instanceof ExpressionProjectionSegment)) {
+ return Optional.empty();
+ }
+ String functionName = ((ExpressionProjectionSegment) projections.iterator().next()).getText();
if (OpenGaussSelectVersionExecutor.accept(functionName)) {
return Optional.of(new OpenGaussSelectVersionExecutor());
}
diff --git a/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactoryTest.java b/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactoryTest.java
index c3e2190ae56..9aaaee5f911 100644
--- a/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactoryTest.java
+++ b/proxy/backend/dialect/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/factory/OpenGaussSystemFunctionQueryExecutorFactoryTest.java
@@ -41,9 +41,7 @@ class OpenGaussSystemFunctionQueryExecutorFactoryTest {
@Test
void assertVersion() {
SelectStatementContext sqlStatementContext = mockSQLStatementContext("VERSION()");
- OpenGaussSystemFunctionQueryExecutorFactory creator = new OpenGaussSystemFunctionQueryExecutorFactory(sqlStatementContext);
- assertTrue(creator.accept());
- Optional<DatabaseAdminExecutor> actual = creator.newInstance();
+ Optional<DatabaseAdminExecutor> actual = OpenGaussSystemFunctionQueryExecutorFactory.newInstance(sqlStatementContext);
assertTrue(actual.isPresent());
assertThat(actual.get(), isA(OpenGaussSelectVersionExecutor.class));
}
@@ -51,9 +49,7 @@ class OpenGaussSystemFunctionQueryExecutorFactoryTest {
@Test
void assertGsPasswordDeadline() {
SelectStatementContext sqlStatementContext = mockSQLStatementContext("gs_password_deadline()");
- OpenGaussSystemFunctionQueryExecutorFactory creator = new OpenGaussSystemFunctionQueryExecutorFactory(sqlStatementContext);
- assertTrue(creator.accept());
- Optional<DatabaseAdminExecutor> actual = creator.newInstance();
+ Optional<DatabaseAdminExecutor> actual = OpenGaussSystemFunctionQueryExecutorFactory.newInstance(sqlStatementContext);
assertTrue(actual.isPresent());
assertThat(actual.get(), isA(OpenGaussSelectPasswordDeadlineExecutor.class));
}
@@ -61,9 +57,7 @@ class OpenGaussSystemFunctionQueryExecutorFactoryTest {
@Test
void assertGsPasswordNotifyTime() {
SelectStatementContext sqlStatementContext = mockSQLStatementContext("gs_password_notifytime()");
- OpenGaussSystemFunctionQueryExecutorFactory creator = new OpenGaussSystemFunctionQueryExecutorFactory(sqlStatementContext);
- assertTrue(creator.accept());
- Optional<DatabaseAdminExecutor> actual = creator.newInstance();
+ Optional<DatabaseAdminExecutor> actual = OpenGaussSystemFunctionQueryExecutorFactory.newInstance(sqlStatementContext);
assertTrue(actual.isPresent());
assertThat(actual.get(), isA(OpenGaussSelectPasswordNotifyTimeExecutor.class));
}