!197 隐藏PG,GP数据库分区表的子表

* 代码调整
* 隐藏PG,GP数据库分区表的子表
* SQLServer,Postgres系统schema过滤
This commit is contained in:
Donaghy
2024-07-31 13:21:18 +00:00
committed by inrgihc
parent 7f7e17bc17
commit 86cd6b7847
4 changed files with 33 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
public class GreenplumMetadataQueryProvider extends PostgresMetadataQueryProvider {
static {
systemSchemas.add("pg_aoseg");
systemSchemas.add("gp_toolkit");
}

View File

@@ -40,13 +40,18 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
+ "where pg_namespace.nspname='%s' and pg_class.relname ='%s'),true) ";
private static final String SHOW_CREATE_VIEW_SQL_2 =
"select pg_get_viewdef('\"%s\".\"%s\"', true)";
private static final String SHOW_SUB_PARTITIONED_TABLE = "SELECT c.relname AS table_name \n"
+ "FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace JOIN pg_inherits i ON c.oid = i.inhrelid \n"
+ "WHERE n.nspname = '%s'";
static {
systemSchemas.add("pg_temp");
systemSchemas.add("pg_aoseg");
systemSchemas.add("information_schema");
systemSchemas.add("pg_catalog");
systemSchemas.add("pg_bitmapindex");
systemSchemas.add("pg_toast");
systemSchemas.add("partman");
systemSchemas.add("repack");
}
public PostgresMetadataQueryProvider(ProductFactoryProvider factoryProvider) {
@@ -61,6 +66,15 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
.collect(Collectors.toList());
}
@Override
public List<TableDescription> queryTableList(Connection connection, String schemaName) {
List<TableDescription> tableList = super.queryTableList(connection, schemaName);
Set<String> partitionedTable = getPartitionedTable(connection, schemaName,
SHOW_SUB_PARTITIONED_TABLE);
return tableList.stream().filter(t -> !partitionedTable.contains(t.getTableName()))
.collect(Collectors.toList());
}
@Override
public String getTableDDL(Connection connection, String schemaName, String tableName) {
String sql = PostgresqlConst.CREATE_TABLE_SQL_TPL
@@ -263,4 +277,18 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
return results;
}
protected Set<String> getPartitionedTable(Connection connection, String schemaName, String sql) {
String query = String.format(sql, schemaName);
Set<String> partitionedTable = new HashSet<>();
try (Statement st = connection.createStatement()) {
ResultSet resultSet = st.executeQuery(query);
while (resultSet.next()) {
partitionedTable.add(resultSet.getString(1));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return partitionedTable;
}
}

View File

@@ -25,6 +25,7 @@ public final class PostgresUtils {
provider, columnDescriptions, pks, schema, table, false);
}
private PostgresUtils() {
throw new IllegalStateException();
}

View File

@@ -47,6 +47,8 @@ public class SqlserverMetadataQueryProvider extends AbstractMetadataProvider {
excludesSchemaNames.add("db_backupoperator");
excludesSchemaNames.add("db_datareader");
excludesSchemaNames.add("db_owner");
excludesSchemaNames.add("sys");
excludesSchemaNames.add("INFORMATION_SCHEMA");
}
public SqlserverMetadataQueryProvider(ProductFactoryProvider factoryProvider) {