提交 6f71939b 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #4841 from greenplum-db/hide-partition-tables-162462448

Hide partition tables from the table list under schemas for greenplum.

Former-commit-id: d4ab7fb3
package org.jkiss.dbeaver.ext.greenplum.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTableBase;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCStatement;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.stream.Collectors;
public class GreenplumSchema extends PostgreSchema {
private static final Log log = Log.getLog(GreenplumSchema.class);
private GreenplumTableCache greenplumTableCache = new GreenplumTableCache();
public GreenplumSchema(PostgreDatabase owner, String name, JDBCResultSet resultSet) throws SQLException {
super(owner, name, resultSet);
}
@Override
public Collection<? extends JDBCTable> getTables(DBRProgressMonitor monitor) throws DBException {
return greenplumTableCache.getTypedObjects(monitor, this, GreenplumTable.class)
.stream()
.filter(table -> !table.isPartition())
.collect(Collectors.toCollection(ArrayList::new));
}
public class GreenplumTableCache extends TableCache {
protected GreenplumTableCache() {
super();
}
@NotNull
@Override
public JDBCStatement prepareLookupStatement(@NotNull JDBCSession session, @NotNull PostgreSchema postgreSchema, @Nullable PostgreTableBase object, @Nullable String objectName) throws SQLException {
String sqlQuery = "SELECT c.oid,d.description, c.*\n" +
"FROM pg_catalog.pg_class c\n" +
"inner join pg_catalog.pg_namespace ns\n" +
"\ton ns.oid = c.relnamespace\n" +
"LEFT OUTER JOIN pg_catalog.pg_description d\n" +
"\tON d.objoid=c.oid AND d.objsubid=0\n" +
"left outer join pg_catalog.pg_partitions p\n" +
"\ton c.relname = p.partitiontablename and ns.nspname = p.schemaname\n" +
"WHERE c.relnamespace= ? AND c.relkind not in ('i','c') AND p.partitiontablename is null "
+ (object == null && objectName == null ? "" : " AND relname=?");
final JDBCPreparedStatement dbStat = session.prepareStatement(sqlQuery);
dbStat.setLong(1, getObjectId());
if (object != null || objectName != null)
dbStat.setString(2, object != null ? object.getName() : objectName);
return dbStat;
}
}
}
package org.jkiss.dbeaver.ext.greenplum.model;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import java.sql.SQLException;
public class GreenplumSchemaCache extends PostgreDatabase.SchemaCache {
@Override
protected GreenplumSchema fetchObject(@NotNull JDBCSession session, @NotNull PostgreDatabase owner, @NotNull JDBCResultSet resultSet) throws SQLException, DBException {
String name = JDBCUtils.safeGetString(resultSet, "nspname");
if (name == null) {
return null;
}
if (GreenplumSchema.isUtilitySchema(name) && !owner.getDataSource().getContainer().isShowUtilityObjects()) {
return null;
}
return new GreenplumSchema(owner, name, resultSet);
}
}
......@@ -57,6 +57,11 @@ public class PostgreServerGreenplum extends PostgreServerExtensionBase {
return super.createRelationOfClass(schema, kind, dbResult);
}
@Override
public PostgreDatabase.SchemaCache createSchemaCache(PostgreDatabase database) {
return new GreenplumSchemaCache();
}
@Override
public void configureDialect(PostgreDialect dialect) {
dialect.addExtraKeywords("DISTRIBUTED");
......
......@@ -49,7 +49,7 @@ public interface PostgreClass extends PostgreObject, DBSEntity, DBPRefreshableOb
return code;
}
static RelKind valueOf(String code) {
public static RelKind valueOf(String code) {
try {
return (RelKind) RelKind.class.getField(code).get(null);
} catch (Throwable e1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册