This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 f9b475ec27f Fix using federation to select from system schema. (#22181)
f9b475ec27f is described below

commit f9b475ec27f6ee066581d4094bae4dd7226d0dfc
Author: Chuxin Chen <[email protected]>
AuthorDate: Tue Nov 15 17:00:20 2022 +0800

    Fix using federation to select from system schema. (#22181)
---
 .../metadata/database/schema/util/SystemSchemaUtil.java     |  4 +++-
 .../metadata/database/schema/util/SystemSchemaUtilTest.java | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtil.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtil.java
index 4c8844263a2..0af66576739 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtil.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtil.java
@@ -20,6 +20,8 @@ package 
org.apache.shardingsphere.infra.metadata.database.schema.util;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 
 import java.util.Collection;
@@ -39,7 +41,7 @@ public class SystemSchemaUtil {
      * @return whether sql statement contains system schema or not
      */
     public static boolean containsSystemSchema(final DatabaseType 
databaseType, final Collection<String> schemaNames, final 
ShardingSphereDatabase database) {
-        if (database.isComplete()) {
+        if (database.isComplete() && !(databaseType instanceof 
PostgreSQLDatabaseType || databaseType instanceof OpenGaussDatabaseType)) {
             return false;
         }
         for (String each : schemaNames) {
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtilTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtilTest.java
index 8354ece50ea..e9544ab9523 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtilTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SystemSchemaUtilTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.infra.metadata.database.schema.util;
 
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
 import 
org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.junit.Test;
@@ -39,7 +40,17 @@ public final class SystemSchemaUtilTest {
         ShardingSphereDatabase shardingSchemaDatabase = 
mockShardingSphereDatabase("sharding_db", false);
         assertFalse(SystemSchemaUtil.containsSystemSchema(new 
PostgreSQLDatabaseType(), Collections.singletonList("sharding_db"), 
shardingSchemaDatabase));
         ShardingSphereDatabase customizedInformationSchemaDatabase = 
mockShardingSphereDatabase("information_schema", true);
-        assertFalse(SystemSchemaUtil.containsSystemSchema(new 
PostgreSQLDatabaseType(), Arrays.asList("information_schema", "pg_catalog"), 
customizedInformationSchemaDatabase));
+        assertTrue(SystemSchemaUtil.containsSystemSchema(new 
PostgreSQLDatabaseType(), Arrays.asList("information_schema", "pg_catalog"), 
customizedInformationSchemaDatabase));
+    }
+    
+    @Test
+    public void assertContainsSystemSchemaForOpenGaussSQL() {
+        ShardingSphereDatabase informationSchemaDatabase = 
mockShardingSphereDatabase("information_schema", false);
+        assertTrue(SystemSchemaUtil.containsSystemSchema(new 
OpenGaussDatabaseType(), Arrays.asList("information_schema", "pg_catalog"), 
informationSchemaDatabase));
+        ShardingSphereDatabase shardingSchemaDatabase = 
mockShardingSphereDatabase("sharding_db", false);
+        assertFalse(SystemSchemaUtil.containsSystemSchema(new 
OpenGaussDatabaseType(), Collections.singletonList("sharding_db"), 
shardingSchemaDatabase));
+        ShardingSphereDatabase customizedInformationSchemaDatabase = 
mockShardingSphereDatabase("information_schema", true);
+        assertTrue(SystemSchemaUtil.containsSystemSchema(new 
OpenGaussDatabaseType(), Arrays.asList("information_schema", "pg_catalog"), 
customizedInformationSchemaDatabase));
     }
     
     @Test

Reply via email to