diff --git a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/type/SchemaMetaDataLoader.java b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/type/SchemaMetaDataLoader.java index f7f39abc5be8a..49e5de19cbc5e 100644 --- a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/type/SchemaMetaDataLoader.java +++ b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/type/SchemaMetaDataLoader.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData; import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.schema.DialectSchemaOption; import org.apache.shardingsphere.database.connector.core.metadata.database.system.SystemDatabase; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableEngine; import org.apache.shardingsphere.database.connector.core.type.DatabaseType; import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry; @@ -115,15 +116,11 @@ private Collection loadTableNames(final Connection connection, final Str try (ResultSet resultSet = connection.getMetaData().getTables(connection.getCatalog(), schemaName, null, tableTypes)) { while (resultSet.next()) { String table = resultSet.getString(TABLE_NAME); - if (!isSystemTable(table) && !excludedTables.contains(table)) { + if (!SystemTableEngine.isSystemTable(databaseType, table) && !excludedTables.contains(table)) { result.add(table); } } } return result; } - - private boolean isSystemTable(final String table) { - return table.contains("$") || table.contains("/") || table.contains("##"); - } } diff --git a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/DialectSystemTableRule.java b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/DialectSystemTableRule.java new file mode 100644 index 0000000000000..3841bf1023a3d --- /dev/null +++ b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/DialectSystemTableRule.java @@ -0,0 +1,34 @@ +/* + * 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.database.connector.core.metadata.detector; + +import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPI; + +/** + * Rule to judge whether table is system table for specific database type. + */ +public interface DialectSystemTableRule extends DatabaseTypedSPI { + + /** + * Judge whether the table is a system table. + * + * @param tableName table name + * @return {@code true} if the table is a system table; otherwise {@code false} + */ + boolean isSystemTable(String tableName); +} diff --git a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableDetector.java b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableDetector.java new file mode 100644 index 0000000000000..293346739330f --- /dev/null +++ b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableDetector.java @@ -0,0 +1,101 @@ +/* + * 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.database.connector.core.metadata.detector; + +import com.cedarsoftware.util.CaseInsensitiveMap; +import com.cedarsoftware.util.CaseInsensitiveSet; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.apache.shardingsphere.infra.util.directory.ClasspathResourceDirectoryReader; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * System table detector. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SystemTableDetector { + + private static final Map>> DATABASE_TYPE_SCHEMA_TABLE_MAP; + + private static final String COMMON = "common"; + + static { + try (Stream resourceNameStream = ClasspathResourceDirectoryReader.read("schema")) { + DATABASE_TYPE_SCHEMA_TABLE_MAP = resourceNameStream.filter(each -> each.endsWith(".yaml")) + .map(resourceName -> resourceName.split("/")) + .filter(path -> 4 == path.length) + .collect(Collectors.groupingBy(path -> path[1], CaseInsensitiveMap::new, + Collectors.groupingBy(path -> path[2], CaseInsensitiveMap::new, + Collectors.mapping(path -> StringUtils.removeEnd(path[3], ".yaml"), + Collectors.toCollection(CaseInsensitiveSet::new))))); + } + } + + /** + * Judge whether the given database type contains system tables. + * + * @param databaseType database type + * @return {@code true} if the given database type contains system tables, otherwise {@code false} + */ + public static boolean hasSystemTables(final String databaseType) { + return !DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(databaseType, Collections.emptyMap()).isEmpty(); + } + + /** + * Judge whether current table is system table or not. + * + * @param databaseType database type + * @param schema schema + * @param tableName table name + * @return whether current table is system table or not + */ + public static boolean isSystemTable(final String databaseType, final String schema, final String tableName) { + Map> schemaTableMap = DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(databaseType, Collections.emptyMap()); + Map> commonTableMap = DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(COMMON, Collections.emptyMap()); + if (null == schema) { + return schemaTableMap.values().stream().anyMatch(each -> each.contains(tableName)) || commonTableMap.values().stream().anyMatch(each -> each.contains(tableName)); + } + return schemaTableMap.getOrDefault(schema, Collections.emptyList()).contains(tableName) || commonTableMap.getOrDefault(schema, Collections.emptyList()).contains(tableName); + } + + /** + * Judge whether current table is system table or not. + * + * @param databaseType database type + * @param schema schema + * @param tableNames table names + * @return whether current table is system table or not + */ + public static boolean isSystemTable(final String databaseType, final String schema, final Collection tableNames) { + Collection databaseTypeTables = Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(databaseType)).map(schemas -> schemas.get(schema)).orElse(Collections.emptyList()); + Collection commonTables = Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(COMMON)).map(schemas -> schemas.get(schema)).orElse(Collections.emptyList()); + for (String each : tableNames) { + if (!databaseTypeTables.contains(each) && !commonTables.contains(each)) { + return false; + } + } + return true; + } +} diff --git a/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableEngine.java b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableEngine.java new file mode 100644 index 0000000000000..dba3058ce7516 --- /dev/null +++ b/database/connector/core/src/main/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableEngine.java @@ -0,0 +1,42 @@ +/* + * 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.database.connector.core.metadata.detector; + +import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader; +import org.apache.shardingsphere.database.connector.core.type.DatabaseType; + +/** + * System table engine. + */ +public final class SystemTableEngine { + + /** + * Judge whether the table is system table or not. + * + * @param databaseType database type + * @param tableName table name + * @return whether the table is system table or not + */ + public static boolean isSystemTable(final DatabaseType databaseType, final String tableName) { + return DatabaseTypedSPILoader.findService(DialectSystemTableRule.class, databaseType) + .map(rule -> rule.isSystemTable(tableName)) + .orElseGet(() -> SystemTableDetector.hasSystemTables(databaseType.getType()) + ? SystemTableDetector.isSystemTable(databaseType.getType(), null, tableName) + : tableName.contains("$") || tableName.contains("/") || tableName.contains("##")); + } +} diff --git a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableDetectorTest.java b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableDetectorTest.java new file mode 100644 index 0000000000000..78daf746ebf43 --- /dev/null +++ b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableDetectorTest.java @@ -0,0 +1,44 @@ +/* + * 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.database.connector.core.metadata.detector; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SystemTableDetectorTest { + + @Test + void assertIsSystemTable() { + assertTrue(SystemTableDetector.isSystemTable("PostgreSQL", "pg_catalog", "pg_aggregate")); + assertTrue(SystemTableDetector.isSystemTable("PostgreSQL", "information_schema", "domain_udt_usage")); + assertFalse(SystemTableDetector.isSystemTable("PostgreSQL", "public", "t_order")); + assertTrue(SystemTableDetector.isSystemTable("MySQL", "information_schema", "applicable_roles")); + assertTrue(SystemTableDetector.isSystemTable("MySQL", "performance_schema", "accounts")); + assertTrue(SystemTableDetector.isSystemTable("MySQL", "mysql", "columns_priv")); + assertTrue(SystemTableDetector.isSystemTable("MySQL", "sys", "host_summary_by_stages")); + assertFalse(SystemTableDetector.isSystemTable("MySQL", "app", "t_order")); + assertTrue(SystemTableDetector.isSystemTable("openGauss", "pg_catalog", "get_global_prepared_xacts")); + assertTrue(SystemTableDetector.isSystemTable("openGauss", "information_schema", "_pg_foreign_data_wrappers")); + assertFalse(SystemTableDetector.isSystemTable("openGauss", "public", "t_order")); + assertTrue(SystemTableDetector.isSystemTable("PostgreSQL", "shardingsphere", "cluster_information")); + assertTrue(SystemTableDetector.isSystemTable("Firebird", "system_tables", "mon$attachments")); + assertFalse(SystemTableDetector.isSystemTable("Firebird", "system_tables", "nonexistent")); + } +} diff --git a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableEngineTest.java b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableEngineTest.java new file mode 100644 index 0000000000000..4a8112d1dddd1 --- /dev/null +++ b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/detector/SystemTableEngineTest.java @@ -0,0 +1,36 @@ +/* + * 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.database.connector.core.metadata.detector; + +import org.junit.jupiter.api.Test; +import org.apache.shardingsphere.database.connector.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SystemTableEngineTest { + + private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); + + @Test + void assertIsSystemTable() { + assertTrue(SystemTableEngine.isSystemTable(databaseType, "pg$foo")); + assertFalse(SystemTableEngine.isSystemTable(databaseType, "t_order")); + } +} diff --git a/database/connector/core/src/test/resources/schema/firebird/system_tables/mon$attachments.yaml b/database/connector/core/src/test/resources/schema/firebird/system_tables/mon$attachments.yaml new file mode 100644 index 0000000000000..be6aca8edeba6 --- /dev/null +++ b/database/connector/core/src/test/resources/schema/firebird/system_tables/mon$attachments.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: MON$ATTACHMENTS diff --git a/database/connector/core/src/test/resources/schema/mysql/information_schema/applicable_roles.yaml b/database/connector/core/src/test/resources/schema/mysql/information_schema/applicable_roles.yaml new file mode 100644 index 0000000000000..6f3d60e7d98d9 --- /dev/null +++ b/database/connector/core/src/test/resources/schema/mysql/information_schema/applicable_roles.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: APPLICABLE_ROLES diff --git a/database/connector/core/src/test/resources/schema/mysql/mysql/columns_priv.yaml b/database/connector/core/src/test/resources/schema/mysql/mysql/columns_priv.yaml new file mode 100644 index 0000000000000..cc63223e1b1ab --- /dev/null +++ b/database/connector/core/src/test/resources/schema/mysql/mysql/columns_priv.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: columns_priv diff --git a/database/connector/core/src/test/resources/schema/mysql/performance_schema/accounts.yaml b/database/connector/core/src/test/resources/schema/mysql/performance_schema/accounts.yaml new file mode 100644 index 0000000000000..bf7d085d0d028 --- /dev/null +++ b/database/connector/core/src/test/resources/schema/mysql/performance_schema/accounts.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: accounts diff --git a/database/connector/core/src/test/resources/schema/mysql/sys/host_summary_by_stages.yaml b/database/connector/core/src/test/resources/schema/mysql/sys/host_summary_by_stages.yaml new file mode 100644 index 0000000000000..e6942d1fd478c --- /dev/null +++ b/database/connector/core/src/test/resources/schema/mysql/sys/host_summary_by_stages.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: host_summary_by_stages diff --git a/database/connector/core/src/test/resources/schema/opengauss/information_schema/_pg_foreign_data_wrappers.yaml b/database/connector/core/src/test/resources/schema/opengauss/information_schema/_pg_foreign_data_wrappers.yaml new file mode 100644 index 0000000000000..bb265f33b4a11 --- /dev/null +++ b/database/connector/core/src/test/resources/schema/opengauss/information_schema/_pg_foreign_data_wrappers.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: _pg_foreign_data_wrappers diff --git a/database/connector/core/src/test/resources/schema/opengauss/pg_catalog/get_global_prepared_xacts.yaml b/database/connector/core/src/test/resources/schema/opengauss/pg_catalog/get_global_prepared_xacts.yaml new file mode 100644 index 0000000000000..97a7a3aa6abfb --- /dev/null +++ b/database/connector/core/src/test/resources/schema/opengauss/pg_catalog/get_global_prepared_xacts.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: get_global_prepared_xacts diff --git a/database/connector/core/src/test/resources/schema/postgresql/information_schema/domain_udt_usage.yaml b/database/connector/core/src/test/resources/schema/postgresql/information_schema/domain_udt_usage.yaml new file mode 100644 index 0000000000000..575c6ab6a20fb --- /dev/null +++ b/database/connector/core/src/test/resources/schema/postgresql/information_schema/domain_udt_usage.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: domain_udt_usage diff --git a/database/connector/core/src/test/resources/schema/postgresql/pg_catalog/pg_aggregate.yaml b/database/connector/core/src/test/resources/schema/postgresql/pg_catalog/pg_aggregate.yaml new file mode 100644 index 0000000000000..25e4120f1da2f --- /dev/null +++ b/database/connector/core/src/test/resources/schema/postgresql/pg_catalog/pg_aggregate.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +name: pg_aggregate diff --git a/database/connector/dialect/firebird/src/test/java/org/apache/shardingsphere/database/connector/firebird/metadata/data/loader/FirebirdSchemaMetaDataLoaderTest.java b/database/connector/dialect/firebird/src/test/java/org/apache/shardingsphere/database/connector/firebird/metadata/data/loader/FirebirdSchemaMetaDataLoaderTest.java index 7409578160973..a3332d2cb17da 100644 --- a/database/connector/dialect/firebird/src/test/java/org/apache/shardingsphere/database/connector/firebird/metadata/data/loader/FirebirdSchemaMetaDataLoaderTest.java +++ b/database/connector/dialect/firebird/src/test/java/org/apache/shardingsphere/database/connector/firebird/metadata/data/loader/FirebirdSchemaMetaDataLoaderTest.java @@ -66,7 +66,7 @@ void setUp() throws SQLException { private ResultSet mockTableResultSet() throws SQLException { ResultSet result = mock(ResultSet.class); - when(result.next()).thenReturn(true, true, true, true, true, false); + when(result.next()).thenReturn(true, true, true, true, true, true, true, true, false); when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "RDB$RELATIONS", "RDB$REL", "RDB_Relations", "rdb$functions"); return result; } @@ -80,7 +80,8 @@ private ResultSet mockSchemaResultSet() throws SQLException { @Test void assertLoadSchemaTableNames() throws SQLException { - Map> schemaTableNames = Collections.singletonMap("foo_db", new CaseInsensitiveSet<>(Arrays.asList("tbl", "partitioned_tbl"))); + Map> schemaTableNames = + Collections.singletonMap("foo_db", new CaseInsensitiveSet<>(Arrays.asList("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "RDB$REL", "RDB_Relations"))); assertThat(new SchemaMetaDataLoader(databaseType).loadSchemaTableNames("foo_db", dataSource, Collections.emptyList()), is(schemaTableNames)); } diff --git a/database/connector/dialect/mysql/src/test/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java b/database/connector/dialect/mysql/src/test/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java index 755a901436f9a..6718ed93ec9ed 100644 --- a/database/connector/dialect/mysql/src/test/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java +++ b/database/connector/dialect/mysql/src/test/java/org/apache/shardingsphere/database/connector/mysql/metadata/data/loader/MySQLSchemaMetaDataLoaderTest.java @@ -66,8 +66,8 @@ void setUp() throws SQLException { private ResultSet mockTableResultSet() throws SQLException { ResultSet result = mock(ResultSet.class); - when(result.next()).thenReturn(true, true, true, true, true, false); - when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl"); + when(result.next()).thenReturn(true, true, true, true, true, true, true, true, false); + when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "host_summary", "accounts", "db_one"); return result; } @@ -80,7 +80,7 @@ private ResultSet mockSchemaResultSet() throws SQLException { @Test void assertLoadSchemaTableNames() throws SQLException { - Map> schemaTableNames = Collections.singletonMap("foo_db", new CaseInsensitiveSet<>(Arrays.asList("tbl", "partitioned_tbl"))); + Map> schemaTableNames = Collections.singletonMap("foo_db", new CaseInsensitiveSet<>(Arrays.asList("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "db_one"))); assertThat(new SchemaMetaDataLoader(databaseType).loadSchemaTableNames("foo_db", dataSource, Collections.emptyList()), is(schemaTableNames)); } diff --git a/database/connector/dialect/opengauss/src/test/java/org/apache/shardingsphere/database/connector/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java b/database/connector/dialect/opengauss/src/test/java/org/apache/shardingsphere/database/connector/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java index 979a09de307b3..fedb572dd76cc 100644 --- a/database/connector/dialect/opengauss/src/test/java/org/apache/shardingsphere/database/connector/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java +++ b/database/connector/dialect/opengauss/src/test/java/org/apache/shardingsphere/database/connector/opengauss/metadata/data/loader/OpenGaussSchemaMetaDataLoaderTest.java @@ -67,8 +67,8 @@ void setUp() throws SQLException { private ResultSet mockTableResultSet() throws SQLException { ResultSet result = mock(ResultSet.class); - when(result.next()).thenReturn(true, true, true, true, true, false); - when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl"); + when(result.next()).thenReturn(true, true, true, true, true, true, true, true, false); + when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "gs_db_privilege", "applicable_roles", "app_roles"); return result; } @@ -86,7 +86,7 @@ void assertLoadSchemaTableNames() throws SQLException { private Map> createSchemaTableNames() { Map> result = new LinkedHashMap<>(3, 1F); - result.put("public", new CaseInsensitiveSet<>(Arrays.asList("tbl", "partitioned_tbl"))); + result.put("public", new CaseInsensitiveSet<>(Arrays.asList("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "app_roles"))); result.put("schema_1", Collections.emptySet()); result.put("schema_2", Collections.emptySet()); return result; diff --git a/database/connector/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/connector/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java b/database/connector/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/connector/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java index a936458e52d3b..323df9c97cbbf 100644 --- a/database/connector/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/connector/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java +++ b/database/connector/dialect/postgresql/src/test/java/org/apache/shardingsphere/database/connector/postgresql/metadata/data/loader/PostgreSQLSchemaMetaDataLoaderTest.java @@ -67,8 +67,8 @@ void setUp() throws SQLException { private ResultSet mockTableResultSet() throws SQLException { ResultSet result = mock(ResultSet.class); - when(result.next()).thenReturn(true, true, true, true, true, false); - when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl"); + when(result.next()).thenReturn(true, true, true, true, true, true, true, true, true, false); + when(result.getString("TABLE_NAME")).thenReturn("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "pg_aggregate", "pg_naming", "pg_am", "collations"); return result; } @@ -86,7 +86,7 @@ void assertLoadSchemaTableNames() throws SQLException { private Map> createSchemaTableNames() { Map> result = new CaseInsensitiveMap<>(); - result.put("public", new CaseInsensitiveSet<>(Arrays.asList("tbl", "partitioned_tbl"))); + result.put("public", new CaseInsensitiveSet<>(Arrays.asList("tbl", "$tbl", "/tbl", "##tbl", "partitioned_tbl", "pg_naming"))); result.put("schema_1", Collections.emptySet()); result.put("schema_2", Collections.emptySet()); return result; diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/from/type/SimpleTableSegmentBinder.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/from/type/SimpleTableSegmentBinder.java index 18d559455535b..f0c8ed69a3cca 100644 --- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/from/type/SimpleTableSegmentBinder.java +++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/from/type/SimpleTableSegmentBinder.java @@ -23,6 +23,7 @@ import lombok.NoArgsConstructor; import org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter; import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; import org.apache.shardingsphere.database.connector.core.type.DatabaseType; import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.database.exception.core.exception.syntax.database.NoDatabaseSelectedException; @@ -38,7 +39,6 @@ import org.apache.shardingsphere.infra.exception.kernel.metadata.IndexNotFoundException; import org.apache.shardingsphere.infra.exception.kernel.metadata.SchemaNotFoundException; import org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; @@ -127,7 +127,7 @@ private static IdentifierValue getSchemaName(final SimpleTableSegment segment, f DatabaseType databaseType = binderContext.getSqlStatement().getDatabaseType(); DatabaseTypeRegistry databaseTypeRegistry = new DatabaseTypeRegistry(databaseType); Optional defaultSystemSchema = databaseTypeRegistry.getDialectDatabaseMetaData().getSchemaOption().getDefaultSystemSchema(); - return defaultSystemSchema.isPresent() && SystemSchemaManager.isSystemTable(databaseType.getType(), defaultSystemSchema.get(), segment.getTableName().getIdentifier().getValue()) + return defaultSystemSchema.isPresent() && SystemTableDetector.isSystemTable(databaseType.getType(), defaultSystemSchema.get(), segment.getTableName().getIdentifier().getValue()) ? new IdentifierValue(defaultSystemSchema.get()) : new IdentifierValue(databaseTypeRegistry.getDefaultSchemaName(binderContext.getCurrentDatabaseName())); } @@ -167,7 +167,8 @@ private static void checkTableExists(final SQLStatementBinderContext binderConte if ("DUAL".equalsIgnoreCase(tableName)) { return; } - if (SystemSchemaManager.isSystemTable(schemaName, tableName)) { + if (SystemTableDetector.isSystemTable(binderContext.getSqlStatement().getDatabaseType().getType(), + schemaName, tableName)) { return; } if (binderContext.getExternalTableBinderContexts().containsKey(new CaseInsensitiveString(tableName))) { diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java index 9dcb830da82c2..3a0a47857c601 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManager.java @@ -21,7 +21,6 @@ import com.cedarsoftware.util.CaseInsensitiveSet; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.commons.lang3.StringUtils; import org.apache.shardingsphere.infra.util.directory.ClasspathResourceDirectoryReader; import java.io.InputStream; @@ -30,8 +29,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -41,8 +38,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class SystemSchemaManager { - private static final Map>> DATABASE_TYPE_SCHEMA_TABLE_MAP; - private static final Map>> DATABASE_TYPE_SCHEMA_RESOURCE_MAP; private static final String COMMON = "common"; @@ -52,80 +47,11 @@ public final class SystemSchemaManager { try (Stream resourceNameStream = ClasspathResourceDirectoryReader.read("schema")) { resourceNames = resourceNameStream.filter(each -> each.endsWith(".yaml")).collect(Collectors.toList()); } - DATABASE_TYPE_SCHEMA_TABLE_MAP = resourceNames.stream().map(resourceName -> resourceName.split("/")).filter(each -> each.length == 4) - .collect(Collectors.groupingBy(path -> path[1], CaseInsensitiveMap::new, Collectors.groupingBy(path -> path[2], CaseInsensitiveMap::new, - Collectors.mapping(path -> StringUtils.removeEnd(path[3], ".yaml"), Collectors.toCollection(CaseInsensitiveSet::new))))); DATABASE_TYPE_SCHEMA_RESOURCE_MAP = resourceNames.stream().map(resourceName -> resourceName.split("/")).filter(each -> each.length == 4) .collect(Collectors.groupingBy(path -> path[1], CaseInsensitiveMap::new, Collectors.groupingBy(path -> path[2], CaseInsensitiveMap::new, Collectors.mapping(path -> String.join("/", path), Collectors.toCollection(CaseInsensitiveSet::new))))); } - /** - * Judge whether current table is system table or not. - * - * @param schema schema - * @param tableName table name - * @return whether current table is system table or not - */ - public static boolean isSystemTable(final String schema, final String tableName) { - for (Entry>> entry : DATABASE_TYPE_SCHEMA_TABLE_MAP.entrySet()) { - if (Optional.ofNullable(entry.getValue().get(schema)).map(tables -> tables.contains(tableName)).orElse(false)) { - return true; - } - } - return false; - } - - /** - * Judge whether current table is system table or not. - * - * @param databaseType database type - * @param schema schema - * @param tableName table name - * @return whether current table is system table or not - */ - public static boolean isSystemTable(final String databaseType, final String schema, final String tableName) { - Map> schemaTableMap = DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(databaseType, Collections.emptyMap()); - Map> commonTableMap = DATABASE_TYPE_SCHEMA_TABLE_MAP.getOrDefault(COMMON, Collections.emptyMap()); - if (null == schema) { - return schemaTableMap.values().stream().anyMatch(each -> each.contains(tableName)) || commonTableMap.values().stream().anyMatch(each -> each.contains(tableName)); - } - return schemaTableMap.getOrDefault(schema, Collections.emptyList()).contains(tableName) || commonTableMap.getOrDefault(schema, Collections.emptyList()).contains(tableName); - } - - /** - * Judge whether current table is system table or not. - * - * @param databaseType database type - * @param schema schema - * @param tableNames table names - * @return whether current table is system table or not - */ - public static boolean isSystemTable(final String databaseType, final String schema, final Collection tableNames) { - Collection databaseTypeTables = Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(databaseType)).map(schemas -> schemas.get(schema)).orElse(Collections.emptyList()); - Collection commonTables = Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(COMMON)).map(schemas -> schemas.get(schema)).orElse(Collections.emptyList()); - for (String each : tableNames) { - if (!databaseTypeTables.contains(each) && !commonTables.contains(each)) { - return false; - } - } - return true; - } - - /** - * Get tables. - * - * @param databaseType database type - * @param schema schema - * @return optional tables - */ - public static Collection getTables(final String databaseType, final String schema) { - Collection result = new LinkedList<>(); - Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(databaseType)).map(schemas -> schemas.get(schema)).ifPresent(result::addAll); - Optional.ofNullable(DATABASE_TYPE_SCHEMA_TABLE_MAP.get(COMMON)).map(schemas -> schemas.get(schema)).ifPresent(result::addAll); - return result; - } - /** * Get all input streams. * diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java index a88453a05a59c..19e50301f1514 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/manager/SystemSchemaManagerTest.java @@ -20,67 +20,32 @@ import org.junit.jupiter.api.Test; import java.util.Collection; +import java.io.InputStream; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; class SystemSchemaManagerTest { @Test - void assertValueOfSchemaPathSuccess() { - Collection actualInformationSchema = SystemSchemaManager.getTables("MySQL", "information_schema"); + void assertGetAllInputStreams() { + Collection actualInformationSchema = SystemSchemaManager.getAllInputStreams("MySQL", "information_schema"); assertThat(actualInformationSchema.size(), is(95)); - Collection actualMySQLSchema = SystemSchemaManager.getTables("MySQL", "mysql"); + Collection actualMySQLSchema = SystemSchemaManager.getAllInputStreams("MySQL", "mysql"); assertThat(actualMySQLSchema.size(), is(40)); - Collection actualPerformanceSchema = SystemSchemaManager.getTables("MySQL", "performance_schema"); + Collection actualPerformanceSchema = SystemSchemaManager.getAllInputStreams("MySQL", "performance_schema"); assertThat(actualPerformanceSchema.size(), is(114)); - Collection actualSysSchema = SystemSchemaManager.getTables("MySQL", "sys"); + Collection actualSysSchema = SystemSchemaManager.getAllInputStreams("MySQL", "sys"); assertThat(actualSysSchema.size(), is(53)); - Collection actualShardingSphereSchema = SystemSchemaManager.getTables("MySQL", "shardingsphere"); + Collection actualShardingSphereSchema = SystemSchemaManager.getAllInputStreams("MySQL", "shardingsphere"); assertThat(actualShardingSphereSchema.size(), is(1)); - Collection actualPgInformationSchema = SystemSchemaManager.getTables("PostgreSQL", "information_schema"); + Collection actualPgInformationSchema = SystemSchemaManager.getAllInputStreams("PostgreSQL", "information_schema"); assertThat(actualPgInformationSchema.size(), is(69)); - Collection actualPgCatalog = SystemSchemaManager.getTables("PostgreSQL", "pg_catalog"); + Collection actualPgCatalog = SystemSchemaManager.getAllInputStreams("PostgreSQL", "pg_catalog"); assertThat(actualPgCatalog.size(), is(134)); - Collection actualOgInformationSchema = SystemSchemaManager.getTables("openGauss", "information_schema"); + Collection actualOgInformationSchema = SystemSchemaManager.getAllInputStreams("openGauss", "information_schema"); assertThat(actualOgInformationSchema.size(), is(66)); - Collection actualOgPgCatalog = SystemSchemaManager.getTables("openGauss", "pg_catalog"); + Collection actualOgPgCatalog = SystemSchemaManager.getAllInputStreams("openGauss", "pg_catalog"); assertThat(actualOgPgCatalog.size(), is(240)); } - - @Test - void assertIsisSystemTable() { - assertTrue(SystemSchemaManager.isSystemTable("information_schema", "columns")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_database")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_tables")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_aggregate")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_am")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_amop")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_amproc")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_attrdef")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_attribute")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_auth_members")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_authid")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_available_extension_versions")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_available_extensions")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_backend_memory_contexts")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_cast")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_range")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_replication_origin")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_rewrite")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_seclabel")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_sequence")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_roles")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_user_mapping")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_stat_database_conflicts")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_stat_gssapi")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_stat_progress_analyze")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_stat_progress_basebackup")); - assertTrue(SystemSchemaManager.isSystemTable("pg_catalog", "pg_stat_progress_cluster")); - assertFalse(SystemSchemaManager.isSystemTable("sharding_db", "t_order")); - assertTrue(SystemSchemaManager.isSystemTable("shardingsphere", "cluster_information")); - assertFalse(SystemSchemaManager.isSystemTable("shardingsphere", "nonexistent")); - } } diff --git a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java index d6f0ed04e3d2f..e9eab24ab556d 100644 --- a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java +++ b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLInformationSchemaExecutorFactory.java @@ -19,8 +19,8 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor; import org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.information.SelectInformationSchemataExecutor; @@ -55,7 +55,7 @@ public static Optional newInstance(final SelectStatementC if (SCHEMATA_TABLE.equalsIgnoreCase(tableName)) { return Optional.of(new SelectInformationSchemataExecutor(sqlStatement, sql, parameters)); } - if (SystemSchemaManager.isSystemTable("mysql", "information_schema", tableName)) { + if (SystemTableDetector.isSystemTable("mysql", "information_schema", tableName)) { return Optional.of(new DefaultDatabaseMetaDataExecutor(sql, parameters)); } return Optional.empty(); diff --git a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java index b78fc3f3007eb..326c6d9f7a4b3 100644 --- a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java +++ b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLMySQLSchemaExecutorFactory.java @@ -19,8 +19,8 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; @@ -49,7 +49,7 @@ public static Optional newInstance(final SelectStatementC return Optional.empty(); } String tableName = ((SimpleTableSegment) sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue(); - if (SystemSchemaManager.isSystemTable("mysql", "mysql", tableName)) { + if (SystemTableDetector.isSystemTable("mysql", "mysql", tableName)) { return Optional.of(new DefaultDatabaseMetaDataExecutor(sql, parameters)); } return Optional.empty(); diff --git a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java index f3818906812b6..3c93cbed1f724 100644 --- a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java +++ b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLPerformanceSchemaExecutorFactory.java @@ -20,7 +20,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; @@ -49,7 +49,7 @@ public static Optional newInstance(final SelectStatementC return Optional.empty(); } String tableName = ((SimpleTableSegment) sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue(); - if (SystemSchemaManager.isSystemTable("mysql", "performance_schema", tableName)) { + if (SystemTableDetector.isSystemTable("mysql", "performance_schema", tableName)) { return Optional.of(new DefaultDatabaseMetaDataExecutor(sql, parameters)); } return Optional.empty(); diff --git a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java index 9bded304dcc67..54ea3edf16fcb 100644 --- a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java +++ b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSysSchemaExecutorFactory.java @@ -19,8 +19,8 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; import org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; @@ -49,7 +49,7 @@ public static Optional newInstance(final SelectStatementC return Optional.empty(); } String tableName = ((SimpleTableSegment) sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue(); - if (SystemSchemaManager.isSystemTable("mysql", "sys", tableName)) { + if (SystemTableDetector.isSystemTable("mysql", "sys", tableName)) { return Optional.of(new DefaultDatabaseMetaDataExecutor(sql, parameters)); } return Optional.empty(); diff --git a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemTableQueryExecutorCreator.java b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemTableQueryExecutorCreator.java index 4d195160ae2db..8d8158380a71b 100644 --- a/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemTableQueryExecutorCreator.java +++ b/proxy/backend/dialect/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemTableQueryExecutorCreator.java @@ -20,6 +20,7 @@ import com.cedarsoftware.util.CaseInsensitiveMap; import com.cedarsoftware.util.CaseInsensitiveSet; import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; 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.segment.select.projection.Projection; @@ -27,7 +28,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; 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.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; @@ -153,7 +153,7 @@ private boolean isSelectSystemTable(final Map> select return false; } for (Entry> each : selectedSchemaTables.entrySet()) { - if (!SystemSchemaManager.isSystemTable("openGauss", each.getKey(), each.getValue())) { + if (!SystemTableDetector.isSystemTable("openGauss", each.getKey(), each.getValue())) { return false; } } diff --git a/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java b/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java index 43e35f2884d5e..094505b7ec5be 100644 --- a/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java +++ b/proxy/backend/dialect/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java @@ -21,8 +21,8 @@ import com.cedarsoftware.util.CaseInsensitiveSet; import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader; import org.apache.shardingsphere.database.connector.core.type.DatabaseType; +import org.apache.shardingsphere.database.connector.core.metadata.detector.SystemTableDetector; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager; 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.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor; @@ -142,7 +142,7 @@ private boolean isSelectSystemTable(final Map> select return false; } for (Entry> each : selectedSchemaTables.entrySet()) { - if (!SystemSchemaManager.isSystemTable("postgresql", each.getKey(), each.getValue())) { + if (!SystemTableDetector.isSystemTable("postgresql", each.getKey(), each.getValue())) { return false; } }