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 71165b8fb3a Enhance system table option handling by adding
isSystemTable method and refactoring related logic (#35283)
71165b8fb3a is described below
commit 71165b8fb3a7224d84b7fdac9014908cba8c7cbe
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Apr 28 19:08:03 2025 +0800
Enhance system table option handling by adding isSystemTable method and
refactoring related logic (#35283)
* Enhance system table option handling by adding isSystemTable method and
refactoring related logic
* Enhance system table option handling by adding isSystemTable method and
refactoring related logic
---
.../option/table/DefaultSystemTableOption.java | 7 +++-
.../option/table/DialectSystemTableOption.java | 8 +++++
.../option/OpenGaussSystemTableOption.java | 15 ++++----
.../executor/constant/EnumerableConstants.java | 42 ----------------------
.../enumerable/EnumerableScanExecutor.java | 6 ++--
.../executor/utils/StatisticsAssembleUtils.java | 17 ++++++---
6 files changed, 38 insertions(+), 57 deletions(-)
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DefaultSystemTableOption.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DefaultSystemTableOption.java
index 5d87ce1bea1..6f55f31079c 100644
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DefaultSystemTableOption.java
+++
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DefaultSystemTableOption.java
@@ -18,7 +18,7 @@
package
org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.table;
/**
- * Dialect system table option.
+ * Default system table option.
*/
public final class DefaultSystemTableOption implements
DialectSystemTableOption {
@@ -31,4 +31,9 @@ public final class DefaultSystemTableOption implements
DialectSystemTableOption
public boolean isSystemCatalogQueryExpressions(final String
projectionExpression) {
return false;
}
+
+ @Override
+ public boolean isSystemTable(final String tableName) {
+ return false;
+ }
}
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DialectSystemTableOption.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DialectSystemTableOption.java
index 795d7c7e53b..205d5b4ce83 100644
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DialectSystemTableOption.java
+++
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/metadata/database/metadata/option/table/DialectSystemTableOption.java
@@ -36,4 +36,12 @@ public interface DialectSystemTableOption {
* @return is query expressions or not
*/
boolean isSystemCatalogQueryExpressions(String projectionExpression);
+
+ /**
+ * Whether system table.
+ *
+ * @param tableName table name
+ * @return is system table or not
+ */
+ boolean isSystemTable(String tableName);
}
diff --git
a/infra/database/type/opengauss/src/main/java/org/apache/shardingsphere/infra/database/opengauss/metadata/database/option/OpenGaussSystemTableOption.java
b/infra/database/type/opengauss/src/main/java/org/apache/shardingsphere/infra/database/opengauss/metadata/database/option/OpenGaussSystemTableOption.java
index 5a3094c0bcc..d88c87c15e0 100644
---
a/infra/database/type/opengauss/src/main/java/org/apache/shardingsphere/infra/database/opengauss/metadata/database/option/OpenGaussSystemTableOption.java
+++
b/infra/database/type/opengauss/src/main/java/org/apache/shardingsphere/infra/database/opengauss/metadata/database/option/OpenGaussSystemTableOption.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.infra.database.opengauss.metadata.database.opt
import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.table.DialectSystemTableOption;
+import java.util.Arrays;
import java.util.Collection;
/**
@@ -27,13 +28,10 @@ import java.util.Collection;
*/
public final class OpenGaussSystemTableOption implements
DialectSystemTableOption {
- private static final Collection<String> SYSTEM_CATALOG_QUERY_EXPRESSIONS =
new CaseInsensitiveSet<>(3, 1F);
+ private static final Collection<String> SYSTEM_CATALOG_QUERY_EXPRESSIONS =
new CaseInsensitiveSet<>(
+ Arrays.asList("version()",
"intervaltonum(gs_password_deadline())", "gs_password_notifytime()"));
- static {
- SYSTEM_CATALOG_QUERY_EXPRESSIONS.add("version()");
-
SYSTEM_CATALOG_QUERY_EXPRESSIONS.add("intervaltonum(gs_password_deadline())");
- SYSTEM_CATALOG_QUERY_EXPRESSIONS.add("gs_password_notifytime()");
- }
+ private static final Collection<String> SYSTEM_CATALOG_TABLES = new
CaseInsensitiveSet<>(Arrays.asList("pg_database", "pg_tables", "pg_roles"));
@Override
public boolean isDriverQuerySystemCatalog() {
@@ -44,4 +42,9 @@ public final class OpenGaussSystemTableOption implements
DialectSystemTableOptio
public boolean isSystemCatalogQueryExpressions(final String
projectionExpression) {
return SYSTEM_CATALOG_QUERY_EXPRESSIONS.contains(projectionExpression);
}
+
+ @Override
+ public boolean isSystemTable(final String tableName) {
+ return SYSTEM_CATALOG_TABLES.contains(tableName);
+ }
}
diff --git
a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/constant/EnumerableConstants.java
b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/constant/EnumerableConstants.java
deleted file mode 100644
index 9da972e8354..00000000000
---
a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/constant/EnumerableConstants.java
+++ /dev/null
@@ -1,42 +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.sqlfederation.executor.constant;
-
-import com.cedarsoftware.util.CaseInsensitiveSet;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-/**
- * Enumerable constants.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class EnumerableConstants {
-
- public static final String DAT_COMPATIBILITY = "PG";
-
- public static final String PG_DATABASE = "pg_database";
-
- public static final String PG_TABLES = "pg_tables";
-
- public static final String PG_ROLES = "pg_roles";
-
- public static final Collection<String> SYSTEM_CATALOG_TABLES = new
CaseInsensitiveSet<>(Arrays.asList(PG_DATABASE, PG_TABLES, PG_ROLES));
-}
diff --git
a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
index df623646c1f..542ac90d7a9 100644
---
a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
+++
b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java
@@ -25,6 +25,7 @@ import org.apache.calcite.linq4j.Enumerator;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.connection.kernel.KernelProcessor;
+import
org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.table.DialectSystemTableOption;
import
org.apache.shardingsphere.infra.database.core.metadata.database.system.SystemDatabase;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -54,7 +55,6 @@ import
org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatist
import org.apache.shardingsphere.infra.metadata.statistics.TableStatistics;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import
org.apache.shardingsphere.sqlfederation.executor.constant.EnumerableConstants;
import
org.apache.shardingsphere.sqlfederation.executor.context.SQLFederationContext;
import
org.apache.shardingsphere.sqlfederation.executor.context.SQLFederationExecutorContext;
import
org.apache.shardingsphere.sqlfederation.executor.enumerator.JDBCRowEnumerator;
@@ -153,8 +153,8 @@ public final class EnumerableScanExecutor implements
ScanExecutor {
}
private Enumerable<Object> createMemoryEnumerable(final String
databaseName, final String schemaName, final ShardingSphereTable table, final
DatabaseType databaseType) {
- if (new
DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().getSystemTableOption().isDriverQuerySystemCatalog()
- &&
EnumerableConstants.SYSTEM_CATALOG_TABLES.contains(table.getName())) {
+ DialectSystemTableOption systemTableOption = new
DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().getSystemTableOption();
+ if (systemTableOption.isDriverQuerySystemCatalog() &&
systemTableOption.isSystemTable(table.getName())) {
return
createMemoryEnumerator(StatisticsAssembleUtils.assembleTableStatistics(table,
federationContext.getMetaData()), table, databaseType);
}
Optional<TableStatistics> tableStatistics =
Optional.ofNullable(statistics.getDatabaseStatistics(databaseName))
diff --git
a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java
b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java
index 1be63f4a0c6..867e9595b04 100644
---
a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java
+++
b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/utils/StatisticsAssembleUtils.java
@@ -27,7 +27,6 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
import org.apache.shardingsphere.infra.metadata.statistics.RowStatistics;
import org.apache.shardingsphere.infra.metadata.statistics.TableStatistics;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import
org.apache.shardingsphere.sqlfederation.executor.constant.EnumerableConstants;
import java.util.Arrays;
import java.util.Collection;
@@ -38,6 +37,14 @@ import java.util.Collection;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class StatisticsAssembleUtils {
+ private static final String DAT_COMPATIBILITY = "PG";
+
+ private static final String PG_DATABASE = "pg_database";
+
+ private static final String PG_TABLES = "pg_tables";
+
+ private static final String PG_ROLES = "pg_roles";
+
/**
* Assemble table statistics.
*
@@ -47,13 +54,13 @@ public final class StatisticsAssembleUtils {
*/
public static TableStatistics assembleTableStatistics(final
ShardingSphereTable table, final ShardingSphereMetaData metaData) {
TableStatistics result = new TableStatistics(table.getName());
- if (EnumerableConstants.PG_DATABASE.equalsIgnoreCase(table.getName()))
{
+ if (PG_DATABASE.equalsIgnoreCase(table.getName())) {
assembleOpenGaussDatabaseData(result, metaData.getAllDatabases());
- } else if
(EnumerableConstants.PG_TABLES.equalsIgnoreCase(table.getName())) {
+ } else if (PG_TABLES.equalsIgnoreCase(table.getName())) {
for (ShardingSphereDatabase each : metaData.getAllDatabases()) {
assembleOpenGaussTableData(result, each.getAllSchemas());
}
- } else if
(EnumerableConstants.PG_ROLES.equalsIgnoreCase(table.getName())) {
+ } else if (PG_ROLES.equalsIgnoreCase(table.getName())) {
assembleOpenGaussRoleData(result, metaData);
}
return result;
@@ -63,7 +70,7 @@ public final class StatisticsAssembleUtils {
for (ShardingSphereDatabase each : databases) {
Object[] rows = new Object[15];
rows[0] = each.getName();
- rows[11] = EnumerableConstants.DAT_COMPATIBILITY;
+ rows[11] = DAT_COMPATIBILITY;
tableStatistics.getRows().add(new
RowStatistics(Arrays.asList(rows)));
}
}