fix(数据集): 识别 pg 表的字段错误

This commit is contained in:
taojinlong 2022-07-28 15:51:12 +08:00
parent e5ca3808ee
commit 449d56b31b

View File

@ -95,11 +95,17 @@ public class JdbcProvider extends DefaultJdbcProvider {
while (resultSet.next()) { while (resultSet.next()) {
String tableName = resultSet.getString("TABLE_NAME"); String tableName = resultSet.getString("TABLE_NAME");
String database; String database;
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name()) || datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.impala.name())) { if (datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.pg.name()) ||datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name()) || datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.impala.name())) {
database = resultSet.getString("TABLE_SCHEM"); database = resultSet.getString("TABLE_SCHEM");
} else { } else {
database = resultSet.getString("TABLE_CAT"); database = resultSet.getString("TABLE_CAT");
} }
if(datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.pg.name())){
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDsSchema(datasourceRequest))) {
TableField tableField = getTableFiled(resultSet, datasourceRequest);
list.add(tableField);
}
}else {
if (database != null) { if (database != null) {
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) { if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) {
TableField tableField = getTableFiled(resultSet, datasourceRequest); TableField tableField = getTableFiled(resultSet, datasourceRequest);
@ -112,6 +118,8 @@ public class JdbcProvider extends DefaultJdbcProvider {
} }
} }
} }
}
resultSet.close(); resultSet.close();
} catch (SQLException e) { } catch (SQLException e) {
DataEaseException.throwException(e); DataEaseException.throwException(e);
@ -191,6 +199,11 @@ public class JdbcProvider extends DefaultJdbcProvider {
} }
} }
private String getDsSchema(DatasourceRequest datasourceRequest) {
JdbcConfiguration jdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class);
return jdbcConfiguration.getSchema();
}
@Override @Override
public List<TableField> fetchResultField(DatasourceRequest datasourceRequest) throws Exception { public List<TableField> fetchResultField(DatasourceRequest datasourceRequest) throws Exception {
JdbcConfiguration jdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class); JdbcConfiguration jdbcConfiguration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), JdbcConfiguration.class);