fix:【数据源】StarRocks选择数据源表详情其中表备注是否可以显示注释 #11433
This commit is contained in:
parent
1abddd7874
commit
d0666257ee
@ -221,8 +221,7 @@ public class CalciteProvider extends Provider {
|
|||||||
String table = datasourceRequest.getTable();
|
String table = datasourceRequest.getTable();
|
||||||
if (StringUtils.isEmpty(table)) {
|
if (StringUtils.isEmpty(table)) {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con.getConnection(), 30)) {
|
||||||
Statement statement = getStatement(con.getConnection(), 30)) {
|
|
||||||
if (DatasourceConfiguration.DatasourceType.valueOf(datasourceSchemaDTO.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
if (DatasourceConfiguration.DatasourceType.valueOf(datasourceSchemaDTO.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||||
}
|
}
|
||||||
@ -241,10 +240,9 @@ public class CalciteProvider extends Provider {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con.getConnection(), 30)) {
|
||||||
Statement statement = getStatement(con.getConnection(), 30)) {
|
|
||||||
datasourceRequest.setDsVersion(con.getConnection().getMetaData().getDatabaseMajorVersion());
|
datasourceRequest.setDsVersion(con.getConnection().getMetaData().getDatabaseMajorVersion());
|
||||||
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase("mongo") || datasourceRequest.getDatasource().getType().equalsIgnoreCase("doris")) {
|
if (datasourceRequest.getDatasource().getType().equalsIgnoreCase("mongo") || isDorisCatalog(datasourceRequest)) {
|
||||||
resultSet = statement.executeQuery("select * from " + table + " limit 0 offset 0 ");
|
resultSet = statement.executeQuery("select * from " + table + " limit 0 offset 0 ");
|
||||||
return fetchResultField(resultSet);
|
return fetchResultField(resultSet);
|
||||||
}
|
}
|
||||||
@ -278,6 +276,21 @@ public class CalciteProvider extends Provider {
|
|||||||
return datasetTableFields;
|
return datasetTableFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDorisCatalog(DatasourceRequest datasourceRequest) {
|
||||||
|
DatasourceConfiguration configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Mysql.class);
|
||||||
|
String database = "";
|
||||||
|
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
||||||
|
database = configuration.getDataBase();
|
||||||
|
} else {
|
||||||
|
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)");
|
||||||
|
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
||||||
|
matcher.find();
|
||||||
|
String[] databasePrams = matcher.group(3).split("\\?");
|
||||||
|
database = databasePrams[0];
|
||||||
|
}
|
||||||
|
return datasourceRequest.getDatasource().getType().equalsIgnoreCase("doris") && database.contains(".");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionObj getConnection(DatasourceDTO coreDatasource) throws Exception {
|
public ConnectionObj getConnection(DatasourceDTO coreDatasource) throws Exception {
|
||||||
ConnectionObj connectionObj = new ConnectionObj();
|
ConnectionObj connectionObj = new ConnectionObj();
|
||||||
@ -373,8 +386,7 @@ public class CalciteProvider extends Provider {
|
|||||||
|
|
||||||
// schema
|
// schema
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||||
PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
|
||||||
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||||
}
|
}
|
||||||
@ -418,8 +430,7 @@ public class CalciteProvider extends Provider {
|
|||||||
|
|
||||||
// schema
|
// schema
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||||
PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
|
||||||
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||||
}
|
}
|
||||||
@ -458,8 +469,7 @@ public class CalciteProvider extends Provider {
|
|||||||
|
|
||||||
// schema
|
// schema
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||||
PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
|
||||||
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||||
}
|
}
|
||||||
@ -660,137 +670,7 @@ public class CalciteProvider extends Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTableFiledSql(DatasourceRequest datasourceRequest) {
|
private TableField getTableFieldDesc(DatasourceRequest datasourceRequest, ResultSet resultSet) throws SQLException {
|
||||||
String sql = "";
|
|
||||||
DatasourceConfiguration configuration = null;
|
|
||||||
String database = "";
|
|
||||||
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType());
|
|
||||||
switch (datasourceType) {
|
|
||||||
case mysql:
|
|
||||||
case mongo:
|
|
||||||
case mariadb:
|
|
||||||
case TiDB:
|
|
||||||
case StarRocks:
|
|
||||||
case doris:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Mysql.class);
|
|
||||||
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
|
||||||
database = configuration.getDataBase();
|
|
||||||
} else {
|
|
||||||
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)");
|
|
||||||
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
|
||||||
matcher.find();
|
|
||||||
String[] databasePrams = matcher.group(3).split("\\?");
|
|
||||||
database = databasePrams[0];
|
|
||||||
}
|
|
||||||
sql = String.format("SELECT COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT,IF(COLUMN_KEY='PRI',1,0) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'", database, datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case oracle:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Oracle.class);
|
|
||||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
|
||||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
|
||||||
}
|
|
||||||
sql = String.format("SELECT a.COLUMN_NAME , a.DATA_TYPE , b.COMMENTS ,0 FROM all_tab_columns a LEFT JOIN all_col_comments b ON a.owner = b.owner AND a.table_name = b.table_name AND a.column_name = b.column_name WHERE a.owner = '%s' AND a.table_name = '%s' ORDER BY a.table_name, a.column_id", configuration.getSchema(), datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case db2:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Db2.class);
|
|
||||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
|
||||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
|
||||||
}
|
|
||||||
sql = String.format("SELECT COLNAME , TYPENAME , REMARKS FROM SYSCAT.COLUMNS WHERE TABSCHEMA = '%s' AND TABNAME = '%s' ", configuration.getSchema(), datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case sqlServer:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Sqlserver.class);
|
|
||||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
|
||||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
|
||||||
}
|
|
||||||
|
|
||||||
sql = String.format("SELECT \n" +
|
|
||||||
" c.name ,t.name ,ep.value, 0 \n" +
|
|
||||||
"FROM \n" +
|
|
||||||
" sys.columns AS c\n" +
|
|
||||||
"LEFT JOIN sys.extended_properties AS ep ON c.object_id = ep.major_id AND c.column_id = ep.minor_id\n" +
|
|
||||||
"LEFT JOIN sys.types AS t ON c.user_type_id = t.user_type_id\n" +
|
|
||||||
"LEFT JOIN sys.objects AS o ON c.object_id = o.object_id\n" +
|
|
||||||
"WHERE o.name = '%s'", datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case pg:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
|
|
||||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
|
||||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
|
||||||
}
|
|
||||||
sql = String.format("SELECT\n" +
|
|
||||||
" a.attname AS ColumnName,\n" +
|
|
||||||
" t.typname,\n" +
|
|
||||||
" b.description AS ColumnDescription,\n" +
|
|
||||||
" 0\n" +
|
|
||||||
"FROM\n" +
|
|
||||||
" pg_class c\n" +
|
|
||||||
" JOIN pg_attribute a ON a.attrelid = c.oid\n" +
|
|
||||||
" LEFT JOIN pg_description b ON a.attrelid = b.objoid AND a.attnum = b.objsubid\n" +
|
|
||||||
" JOIN pg_type t ON a.atttypid = t.oid\n" +
|
|
||||||
"where\n" +
|
|
||||||
" \tc.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '%s') \n" +
|
|
||||||
" AND c.relname = '%s'\n" +
|
|
||||||
" AND a.attnum > 0\n" +
|
|
||||||
" AND NOT a.attisdropped\n" +
|
|
||||||
"ORDER BY\n" +
|
|
||||||
" a.attnum;", configuration.getSchema(), datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case redshift:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
|
||||||
sql = String.format("SELECT\n" +
|
|
||||||
" a.attname AS ColumnName,\n" +
|
|
||||||
" t.typname,\n" +
|
|
||||||
" b.description AS ColumnDescription,\n" +
|
|
||||||
" 0\n" +
|
|
||||||
"FROM\n" +
|
|
||||||
" pg_class c\n" +
|
|
||||||
" JOIN pg_attribute a ON a.attrelid = c.oid\n" +
|
|
||||||
" LEFT JOIN pg_description b ON a.attrelid = b.objoid AND a.attnum = b.objsubid\n" +
|
|
||||||
" JOIN pg_type t ON a.atttypid = t.oid\n" +
|
|
||||||
"WHERE\n" +
|
|
||||||
" c.relname = '%s'\n" +
|
|
||||||
" AND a.attnum > 0\n" +
|
|
||||||
" AND NOT a.attisdropped\n" +
|
|
||||||
"ORDER BY\n" +
|
|
||||||
" a.attnum\n" +
|
|
||||||
" ", datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case ck:
|
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
|
||||||
database = configuration.getDataBase();
|
|
||||||
} else {
|
|
||||||
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:clickhouse://(.*):(\\d+)/(.*)");
|
|
||||||
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
|
||||||
matcher.find();
|
|
||||||
String[] databasePrams = matcher.group(3).split("\\?");
|
|
||||||
database = databasePrams[0];
|
|
||||||
}
|
|
||||||
sql = String.format(" SELECT\n" +
|
|
||||||
" name,\n" +
|
|
||||||
" type,\n" +
|
|
||||||
" comment,\n" +
|
|
||||||
" 0\n" +
|
|
||||||
"FROM\n" +
|
|
||||||
" system.columns\n" +
|
|
||||||
"WHERE\n" +
|
|
||||||
" database = '%s' \n" +
|
|
||||||
" AND table = '%s' ", database, datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
case impala:
|
|
||||||
sql = String.format("DESCRIBE `%s`", datasourceRequest.getTable());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TableField getTableFieldDesc(DatasourceRequest datasourceRequest, ResultSet resultSet) throws
|
|
||||||
SQLException {
|
|
||||||
TableField tableField = new TableField();
|
TableField tableField = new TableField();
|
||||||
tableField.setOriginName(resultSet.getString(1));
|
tableField.setOriginName(resultSet.getString(1));
|
||||||
tableField.setType(resultSet.getString(2).toUpperCase());
|
tableField.setType(resultSet.getString(2).toUpperCase());
|
||||||
@ -1050,6 +930,103 @@ public class CalciteProvider extends Provider {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTableFiledSql(DatasourceRequest datasourceRequest) {
|
||||||
|
String sql = "";
|
||||||
|
DatasourceConfiguration configuration = null;
|
||||||
|
String database = "";
|
||||||
|
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType());
|
||||||
|
switch (datasourceType) {
|
||||||
|
case StarRocks:
|
||||||
|
case doris:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Mysql.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
||||||
|
database = configuration.getDataBase();
|
||||||
|
} else {
|
||||||
|
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)");
|
||||||
|
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
||||||
|
matcher.find();
|
||||||
|
String[] databasePrams = matcher.group(3).split("\\?");
|
||||||
|
database = databasePrams[0];
|
||||||
|
}
|
||||||
|
if (database.contains(".")) {
|
||||||
|
sql = "select * from " + datasourceRequest.getTable() + " limit 0 offset 0 ";
|
||||||
|
} else {
|
||||||
|
sql = String.format("SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s' ;", database);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mysql:
|
||||||
|
case mongo:
|
||||||
|
case mariadb:
|
||||||
|
case TiDB:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Mysql.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
||||||
|
database = configuration.getDataBase();
|
||||||
|
} else {
|
||||||
|
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)");
|
||||||
|
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
||||||
|
matcher.find();
|
||||||
|
String[] databasePrams = matcher.group(3).split("\\?");
|
||||||
|
database = databasePrams[0];
|
||||||
|
}
|
||||||
|
sql = String.format("SELECT COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT,IF(COLUMN_KEY='PRI',1,0) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s'", database, datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case oracle:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Oracle.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||||
|
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||||
|
}
|
||||||
|
sql = String.format("SELECT a.COLUMN_NAME , a.DATA_TYPE , b.COMMENTS ,0 FROM all_tab_columns a LEFT JOIN all_col_comments b ON a.owner = b.owner AND a.table_name = b.table_name AND a.column_name = b.column_name WHERE a.owner = '%s' AND a.table_name = '%s' ORDER BY a.table_name, a.column_id", configuration.getSchema(), datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case db2:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Db2.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||||
|
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||||
|
}
|
||||||
|
sql = String.format("SELECT COLNAME , TYPENAME , REMARKS FROM SYSCAT.COLUMNS WHERE TABSCHEMA = '%s' AND TABNAME = '%s' ", configuration.getSchema(), datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case sqlServer:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Sqlserver.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||||
|
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||||
|
}
|
||||||
|
|
||||||
|
sql = String.format("SELECT \n" + " c.name ,t.name ,ep.value, 0 \n" + "FROM \n" + " sys.columns AS c\n" + "LEFT JOIN sys.extended_properties AS ep ON c.object_id = ep.major_id AND c.column_id = ep.minor_id\n" + "LEFT JOIN sys.types AS t ON c.user_type_id = t.user_type_id\n" + "LEFT JOIN sys.objects AS o ON c.object_id = o.object_id\n" + "WHERE o.name = '%s'", datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case pg:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||||
|
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||||
|
}
|
||||||
|
sql = String.format("SELECT\n" + " a.attname AS ColumnName,\n" + " t.typname,\n" + " b.description AS ColumnDescription,\n" + " 0\n" + "FROM\n" + " pg_class c\n" + " JOIN pg_attribute a ON a.attrelid = c.oid\n" + " LEFT JOIN pg_description b ON a.attrelid = b.objoid AND a.attnum = b.objsubid\n" + " JOIN pg_type t ON a.atttypid = t.oid\n" + "where\n" + " \tc.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = '%s') \n" + " AND c.relname = '%s'\n" + " AND a.attnum > 0\n" + " AND NOT a.attisdropped\n" + "ORDER BY\n" + " a.attnum;", configuration.getSchema(), datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case redshift:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
||||||
|
sql = String.format("SELECT\n" + " a.attname AS ColumnName,\n" + " t.typname,\n" + " b.description AS ColumnDescription,\n" + " 0\n" + "FROM\n" + " pg_class c\n" + " JOIN pg_attribute a ON a.attrelid = c.oid\n" + " LEFT JOIN pg_description b ON a.attrelid = b.objoid AND a.attnum = b.objsubid\n" + " JOIN pg_type t ON a.atttypid = t.oid\n" + "WHERE\n" + " c.relname = '%s'\n" + " AND a.attnum > 0\n" + " AND NOT a.attisdropped\n" + "ORDER BY\n" + " a.attnum\n" + " ", datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case ck:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
||||||
|
database = configuration.getDataBase();
|
||||||
|
} else {
|
||||||
|
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:clickhouse://(.*):(\\d+)/(.*)");
|
||||||
|
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
||||||
|
matcher.find();
|
||||||
|
String[] databasePrams = matcher.group(3).split("\\?");
|
||||||
|
database = databasePrams[0];
|
||||||
|
}
|
||||||
|
sql = String.format(" SELECT\n" + " name,\n" + " type,\n" + " comment,\n" + " 0\n" + "FROM\n" + " system.columns\n" + "WHERE\n" + " database = '%s' \n" + " AND table = '%s' ", database, datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
case impala:
|
||||||
|
sql = String.format("DESCRIBE `%s`", datasourceRequest.getTable());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> getTablesSql(DatasourceRequest datasourceRequest) throws DEException {
|
private List<String> getTablesSql(DatasourceRequest datasourceRequest) throws DEException {
|
||||||
List<String> tableSqls = new ArrayList<>();
|
List<String> tableSqls = new ArrayList<>();
|
||||||
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType());
|
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType());
|
||||||
@ -1058,6 +1035,22 @@ public class CalciteProvider extends Provider {
|
|||||||
switch (datasourceType) {
|
switch (datasourceType) {
|
||||||
case StarRocks:
|
case StarRocks:
|
||||||
case doris:
|
case doris:
|
||||||
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Mysql.class);
|
||||||
|
if (StringUtils.isEmpty(configuration.getUrlType()) || configuration.getUrlType().equalsIgnoreCase("hostName")) {
|
||||||
|
database = configuration.getDataBase();
|
||||||
|
} else {
|
||||||
|
Pattern WITH_SQL_FRAGMENT = Pattern.compile("jdbc:mysql://(.*):(\\d+)/(.*)");
|
||||||
|
Matcher matcher = WITH_SQL_FRAGMENT.matcher(configuration.getJdbcUrl());
|
||||||
|
matcher.find();
|
||||||
|
String[] databasePrams = matcher.group(3).split("\\?");
|
||||||
|
database = databasePrams[0];
|
||||||
|
}
|
||||||
|
if (database.contains(".")) {
|
||||||
|
tableSqls.add("show tables");
|
||||||
|
} else {
|
||||||
|
tableSqls.add(String.format("SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '%s' ;", database));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case mongo:
|
case mongo:
|
||||||
tableSqls.add("show tables");
|
tableSqls.add("show tables");
|
||||||
break;
|
break;
|
||||||
@ -1096,57 +1089,19 @@ public class CalciteProvider extends Provider {
|
|||||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||||
}
|
}
|
||||||
tableSqls.add("SELECT \n" +
|
tableSqls.add("SELECT \n" + " t.name AS TableName, \n" + " ep.value AS TableDescription \n" + "FROM \n" + " sys.tables t \n" + "LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" + "LEFT OUTER JOIN \n" + " sys.extended_properties ep ON t.object_id = ep.major_id \n" + " AND ep.minor_id = 0 \n" + " AND ep.class = 1 \n" + " AND ep.name = 'MS_Description'\n" + "where sc.name ='DS_SCHEMA'".replace("DS_SCHEMA", configuration.getSchema()));
|
||||||
" t.name AS TableName, \n" +
|
tableSqls.add("SELECT \n" + " t.name AS TableName, \n" + " ep.value AS TableDescription \n" + "FROM \n" + " sys.views t \n" + "LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" + "LEFT OUTER JOIN \n" + " sys.extended_properties ep ON t.object_id = ep.major_id \n" + " AND ep.minor_id = 0 \n" + " AND ep.class = 1 \n" + " AND ep.name = 'MS_Description'\n" + "where sc.name ='DS_SCHEMA'".replace("DS_SCHEMA", configuration.getSchema()));
|
||||||
" ep.value AS TableDescription \n" +
|
|
||||||
"FROM \n" +
|
|
||||||
" sys.tables t \n" +
|
|
||||||
"LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" +
|
|
||||||
"LEFT OUTER JOIN \n" +
|
|
||||||
" sys.extended_properties ep ON t.object_id = ep.major_id \n" +
|
|
||||||
" AND ep.minor_id = 0 \n" +
|
|
||||||
" AND ep.class = 1 \n" +
|
|
||||||
" AND ep.name = 'MS_Description'\n" +
|
|
||||||
"where sc.name ='DS_SCHEMA'"
|
|
||||||
.replace("DS_SCHEMA", configuration.getSchema()));
|
|
||||||
tableSqls.add("SELECT \n" +
|
|
||||||
" t.name AS TableName, \n" +
|
|
||||||
" ep.value AS TableDescription \n" +
|
|
||||||
"FROM \n" +
|
|
||||||
" sys.views t \n" +
|
|
||||||
"LEFT OUTER JOIN sys.schemas sc ON sc.schema_id =t.schema_id \n" +
|
|
||||||
"LEFT OUTER JOIN \n" +
|
|
||||||
" sys.extended_properties ep ON t.object_id = ep.major_id \n" +
|
|
||||||
" AND ep.minor_id = 0 \n" +
|
|
||||||
" AND ep.class = 1 \n" +
|
|
||||||
" AND ep.name = 'MS_Description'\n" +
|
|
||||||
"where sc.name ='DS_SCHEMA'"
|
|
||||||
.replace("DS_SCHEMA", configuration.getSchema()));
|
|
||||||
break;
|
break;
|
||||||
case pg:
|
case pg:
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
|
||||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||||
}
|
}
|
||||||
tableSqls.add("SELECT \n" +
|
tableSqls.add("SELECT \n" + " relname AS TableName, \n" + " obj_description(relfilenode::regclass, 'pg_class') AS TableDescription \n" + "FROM \n" + " pg_class \n" + "WHERE \n" + " relkind = 'r' \n" + " AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'SCHEMA') ".replace("SCHEMA", configuration.getSchema()));
|
||||||
" relname AS TableName, \n" +
|
|
||||||
" obj_description(relfilenode::regclass, 'pg_class') AS TableDescription \n" +
|
|
||||||
"FROM \n" +
|
|
||||||
" pg_class \n" +
|
|
||||||
"WHERE \n" +
|
|
||||||
" relkind = 'r' \n" +
|
|
||||||
" AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'SCHEMA') ".replace("SCHEMA", configuration.getSchema()));
|
|
||||||
break;
|
break;
|
||||||
case redshift:
|
case redshift:
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
||||||
tableSqls.add("SELECT \n" +
|
tableSqls.add("SELECT \n" + " relname AS TableName, \n" + " obj_description(relfilenode::regclass, 'pg_class') AS TableDescription \n" + "FROM \n" + " pg_class \n" + "WHERE \n" + " relkind = 'r' \n" + " AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'SCHEMA') ".replace("SCHEMA", configuration.getSchema()));
|
||||||
" relname AS TableName, \n" +
|
|
||||||
" obj_description(relfilenode::regclass, 'pg_class') AS TableDescription \n" +
|
|
||||||
"FROM \n" +
|
|
||||||
" pg_class \n" +
|
|
||||||
"WHERE \n" +
|
|
||||||
" relkind = 'r' \n" +
|
|
||||||
" AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'SCHEMA') ".replace("SCHEMA", configuration.getSchema()));
|
|
||||||
break;
|
break;
|
||||||
case ck:
|
case ck:
|
||||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
||||||
@ -1159,9 +1114,9 @@ public class CalciteProvider extends Provider {
|
|||||||
String[] databasePrams = matcher.group(3).split("\\?");
|
String[] databasePrams = matcher.group(3).split("\\?");
|
||||||
database = databasePrams[0];
|
database = databasePrams[0];
|
||||||
}
|
}
|
||||||
if(datasourceRequest.getDsVersion() < 22){
|
if (datasourceRequest.getDsVersion() < 22) {
|
||||||
tableSqls.add("SELECT name, name FROM system.tables where database='DATABASE';".replace("DATABASE", database));
|
tableSqls.add("SELECT name, name FROM system.tables where database='DATABASE';".replace("DATABASE", database));
|
||||||
}else {
|
} else {
|
||||||
tableSqls.add("SELECT name, comment FROM system.tables where database='DATABASE';".replace("DATABASE", database));
|
tableSqls.add("SELECT name, comment FROM system.tables where database='DATABASE';".replace("DATABASE", database));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user