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/04/27 15:47:51 UTC
(shardingsphere) branch master updated: Refactor SQLFederationEngine and SystemSchemaUtils for improved schema handling (#35275)
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 594d3405b2e Refactor SQLFederationEngine and SystemSchemaUtils for improved schema handling (#35275)
594d3405b2e is described below
commit 594d3405b2e5976c30c2eb271f418cb0b6a4576d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Apr 27 23:47:45 2025 +0800
Refactor SQLFederationEngine and SystemSchemaUtils for improved schema handling (#35275)
---
.../database/schema/util/SystemSchemaUtils.java | 37 ++++++++++------------
.../sqlfederation/engine/SQLFederationEngine.java | 3 +-
2 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
index af8370b80c0..ff8baee5c69 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtils.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.infra.metadata.database.schema.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
+import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.schema.DialectSchemaOption;
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;
@@ -37,16 +37,16 @@ import java.util.Collection;
public final class SystemSchemaUtils {
/**
- * Judge whether SQL statement contains system schema or not.
+ * Judge whether SQL statement contains system schema.
*
* @param databaseType database type
* @param schemaNames schema names
* @param database database
- * @return whether SQL statement contains system schema or not
+ * @return contains system schema or not
*/
public static boolean containsSystemSchema(final DatabaseType databaseType, final Collection<String> schemaNames, final ShardingSphereDatabase database) {
- DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData();
- if (database.isComplete() && !dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().isPresent()) {
+ DialectSchemaOption schemaOption = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().getSchemaOption();
+ if (database.isComplete() && !schemaOption.getDefaultSchema().isPresent()) {
return false;
}
SystemDatabase systemDatabase = new SystemDatabase(databaseType);
@@ -55,7 +55,18 @@ public final class SystemSchemaUtils {
return true;
}
}
- return !dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().isPresent() && systemDatabase.getSystemSchemas().contains(database.getName());
+ return !schemaOption.getDefaultSchema().isPresent() && systemDatabase.getSystemSchemas().contains(database.getName());
+ }
+
+ /**
+ * Judge whether schema is system schema.
+ *
+ * @param database database
+ * @return is system schema or not
+ */
+ public static boolean isSystemSchema(final ShardingSphereDatabase database) {
+ DialectSchemaOption schemaOption = new DatabaseTypeRegistry(database.getProtocolType()).getDialectDatabaseMetaData().getSchemaOption();
+ return (!database.isComplete() || schemaOption.getDefaultSchema().isPresent()) && new SystemDatabase(database.getProtocolType()).getSystemSchemas().contains(database.getName());
}
/**
@@ -71,18 +82,4 @@ public final class SystemSchemaUtils {
&& 1 == projections.size() && projections.iterator().next() instanceof ExpressionProjectionSegment
&& systemTableOption.isSystemCatalogQueryExpressions(((ExpressionProjectionSegment) projections.iterator().next()).getText());
}
-
- /**
- * Judge schema is system schema or not.
- *
- * @param database database
- * @return whether schema is system schema or not
- */
- public static boolean isSystemSchema(final ShardingSphereDatabase database) {
- DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(database.getProtocolType()).getDialectDatabaseMetaData();
- if (database.isComplete() && !dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().isPresent()) {
- return false;
- }
- return new SystemDatabase(database.getProtocolType()).getSystemSchemas().contains(database.getName());
- }
}
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
index 69e9329572c..4a153528d0a 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
@@ -136,8 +136,7 @@ public final class SQLFederationEngine implements AutoCloseable {
return true;
}
SQLStatementContext sqlStatementContext = queryContext.getSqlStatementContext();
- boolean sqlFederationEnabled = sqlFederationRule.getConfiguration().isSqlFederationEnabled();
- if (!sqlFederationEnabled || !(sqlStatementContext instanceof SelectStatementContext)) {
+ if (!sqlFederationRule.getConfiguration().isSqlFederationEnabled() || !(sqlStatementContext instanceof SelectStatementContext)) {
return false;
}
boolean allQueryUseSQLFederation = sqlFederationRule.getConfiguration().isAllQueryUseSQLFederation();