提交 c1c6da68 编写于 作者: S Serge Rider

#10081 GP: child and partition tables loading fix


Former-commit-id: 914a255b
上级 b8c4c7bb
......@@ -28,9 +28,11 @@ 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.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTable;
import org.jkiss.dbeaver.model.meta.Association;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.utils.CommonUtils;
import java.sql.SQLException;
import java.util.ArrayList;
......@@ -80,7 +82,7 @@ public class GreenplumSchema extends PostgreSchema {
getDataSource().isGreenplumVersionAtLeast(session.getProgressMonitor(), 5, 0) ? "urilocation" : "location";
String execLocationColumn =
getDataSource().isGreenplumVersionAtLeast(session.getProgressMonitor(), 5, 0) ? "execlocation" : "location";
StringBuilder sqlQuery = new StringBuilder("SELECT c.oid,d.description, c.*,\n" +
StringBuilder sqlQuery = new StringBuilder("SELECT c.oid,d.description,p.partitiontablename,c.*,\n" +
"CASE WHEN x." + uriLocationColumn + " IS NOT NULL THEN array_to_string(x." + uriLocationColumn + ", ',') ELSE '' END AS urilocation,\n" +
"CASE WHEN x.command IS NOT NULL THEN x.command ELSE '' END AS command,\n" +
"x.fmttype, x.fmtopts,\n" +
......@@ -100,7 +102,7 @@ public class GreenplumSchema extends PostgreSchema {
"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_exttable x\n\ton x.reloid = c.oid\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 ")
"WHERE c.relnamespace= ? AND c.relkind not in ('i','c') ")
.append((object == null && objectName == null ? "" : " AND relname=?"));
final JDBCPreparedStatement dbStat = session.prepareStatement(sqlQuery.toString());
......@@ -109,6 +111,11 @@ public class GreenplumSchema extends PostgreSchema {
dbStat.setString(2, object != null ? object.getName() : objectName);
return dbStat;
}
@Override
protected boolean isPartitionTableRow(@NotNull JDBCResultSet dbResult) {
return !CommonUtils.isEmpty(JDBCUtils.safeGetString(dbResult, "partitiontablename"));
}
}
public class GreenplumFunctionsCache extends ProceduresCache {
......
......@@ -128,4 +128,9 @@ public class PostgreServerGreenplum extends PostgreServerExtensionBase {
public boolean supportsDatabaseSize() {
return true;
}
@Override
public boolean supportsPartitions() {
return true;
}
}
......@@ -729,15 +729,19 @@ public class PostgreSchema implements
protected PostgreTableBase fetchObject(@NotNull JDBCSession session, @NotNull PostgreTableContainer container, @NotNull JDBCResultSet dbResult)
throws SQLException, DBException
{
final String kindString = getDataSource().isServerVersionAtLeast(10, 0)
&& JDBCUtils.safeGetString(dbResult, "relkind").equals(PostgreClass.RelKind.r.getCode())
&& JDBCUtils.safeGetBoolean(dbResult, "relispartition")
final String kindString = getDataSource().getServerType().supportsPartitions()
&& CommonUtils.equalObjects(JDBCUtils.safeGetString(dbResult, "relkind"), PostgreClass.RelKind.r.getCode())
&& isPartitionTableRow(dbResult)
? PostgreClass.RelKind.R.getCode() : JDBCUtils.safeGetString(dbResult, "relkind");
PostgreClass.RelKind kind = PostgreClass.RelKind.valueOf(kindString);
return container.getDataSource().getServerType().createRelationOfClass(PostgreSchema.this, kind, dbResult);
}
protected boolean isPartitionTableRow(@NotNull JDBCResultSet dbResult) {
return JDBCUtils.safeGetBoolean(dbResult, "relispartition");
}
protected JDBCStatement prepareChildrenStatement(@NotNull JDBCSession session, @NotNull PostgreTableContainer container)
throws SQLException {
String sql = "SELECT c.relname,a.*,pg_catalog.pg_get_expr(ad.adbin, ad.adrelid, true) as def_value,dsc.description" +
......
......@@ -424,7 +424,10 @@ public abstract class PostgreTable extends PostgreTableReal implements PostgreTa
if (CommonUtils.isEmpty(si)) {
return null;
}
return si.stream().map(AbstractTableConstraint::getParentObject).collect(Collectors.toList());
return si.stream()
.map(AbstractTableConstraint::getParentObject)
.filter(PostgreTableBase::isPartition)
.collect(Collectors.toList());
}
@Override
......
......@@ -45,6 +45,7 @@ public class PostgreTablePartition extends PostgreTable implements DBSTableParti
public PostgreTablePartition(PostgreTableContainer container, ResultSet dbResult) {
super(container, dbResult);
this.setPartition(true);
this.partitionExpression = JDBCUtils.safeGetString(dbResult, "partition_expr");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册