forked from github/dataease
Merge pull request #11443 from dataease/pr@dev-v2@fixDS
Pr@dev v2@fix ds
This commit is contained in:
commit
0f709d4558
@ -22,6 +22,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -178,13 +179,21 @@ public class ApiUtils {
|
||||
String resultStr = execHttpRequest(definition, definition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 10 : apiDefinition.getApiQueryTimeout(), null);
|
||||
List<String[]> dataList = fetchResult(resultStr, definition);
|
||||
if (dataList.size() > 0) {
|
||||
result = result.replace("${" + param +"}",dataList.get(0)[i]);
|
||||
result = result.replace("${" + param + "}", dataList.get(0)[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
httpClientConfig.addHeader(header.get("name").toString(), result);
|
||||
} else if (header.get("nameType") != null && header.get("nameType").toString().equalsIgnoreCase("timeFun")) {
|
||||
String timeFormat = header.get("value").toString();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date date = calendar.getTime();
|
||||
if (StringUtils.isNotEmpty(timeFormat) && timeFormat.split(" ")[0].equalsIgnoreCase("currentDay")) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat.split(" ")[1]);
|
||||
httpClientConfig.addHeader(header.get("name").toString(), simpleDateFormat.format(date));
|
||||
}
|
||||
} else {
|
||||
httpClientConfig.addHeader(header.get("name").toString(), header.get("value").toString());
|
||||
}
|
||||
@ -203,7 +212,55 @@ public class ApiUtils {
|
||||
List<String> params = new ArrayList<>();
|
||||
for (Map<String, String> argument : apiDefinition.getRequest().getArguments()) {
|
||||
if (StringUtils.isNotEmpty(argument.get("name")) && StringUtils.isNotEmpty(argument.get("value"))) {
|
||||
params.add(argument.get("name") + "=" + URLEncoder.encode(argument.get("value")));
|
||||
if (argument.get("nameType") != null && argument.get("nameType").toString().equalsIgnoreCase("params")) {
|
||||
String param = argument.get("value").toString();
|
||||
for (ApiDefinition definition : paramsList) {
|
||||
for (int i = 0; i < definition.getFields().size(); i++) {
|
||||
TableField field = definition.getFields().get(i);
|
||||
if (field.getOriginName().equalsIgnoreCase(param)) {
|
||||
String resultStr = execHttpRequest(definition, definition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 10 : apiDefinition.getApiQueryTimeout(), null);
|
||||
List<String[]> dataList = fetchResult(resultStr, definition);
|
||||
if (dataList.size() > 0) {
|
||||
params.add(argument.get("name") + "=" + dataList.get(0)[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (argument.get("nameType") != null && argument.get("nameType").toString().equalsIgnoreCase("custom")) {
|
||||
List<String> arrayList = new ArrayList<>();
|
||||
String regex = "\\$\\{(.*?)\\}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(argument.get("value").toString());
|
||||
while (matcher.find()) {
|
||||
arrayList.add(matcher.group(1));
|
||||
}
|
||||
String result = argument.get("value").toString();
|
||||
for (String param : arrayList) {
|
||||
for (ApiDefinition definition : paramsList) {
|
||||
for (int i = 0; i < definition.getFields().size(); i++) {
|
||||
TableField field = definition.getFields().get(i);
|
||||
if (field.getOriginName().equalsIgnoreCase(param)) {
|
||||
String resultStr = execHttpRequest(definition, definition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 10 : apiDefinition.getApiQueryTimeout(), null);
|
||||
List<String[]> dataList = fetchResult(resultStr, definition);
|
||||
if (dataList.size() > 0) {
|
||||
result = result.replace("${" + param + "}", dataList.get(0)[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
params.add(argument.get("name") + "=" + result);
|
||||
} else if (argument.get("nameType") != null && argument.get("nameType").toString().equalsIgnoreCase("timeFun")) {
|
||||
String timeFormat = argument.get("value").toString();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date date = calendar.getTime();
|
||||
if (StringUtils.isNotEmpty(timeFormat) && timeFormat.split(" ")[0].equalsIgnoreCase("currentDay")) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat.split(" ")[1]);
|
||||
params.add(argument.get("name") + "=" + simpleDateFormat.format(date));
|
||||
}
|
||||
} else {
|
||||
params.add(argument.get("name") + "=" + URLEncoder.encode(argument.get("value")));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(params)) {
|
||||
|
@ -221,8 +221,7 @@ public class CalciteProvider extends Provider {
|
||||
String table = datasourceRequest.getTable();
|
||||
if (StringUtils.isEmpty(table)) {
|
||||
ResultSet resultSet = null;
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
||||
Statement statement = getStatement(con.getConnection(), 30)) {
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con.getConnection(), 30)) {
|
||||
if (DatasourceConfiguration.DatasourceType.valueOf(datasourceSchemaDTO.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||
}
|
||||
@ -241,10 +240,9 @@ public class CalciteProvider extends Provider {
|
||||
}
|
||||
} else {
|
||||
ResultSet resultSet = null;
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
||||
Statement statement = getStatement(con.getConnection(), 30)) {
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con.getConnection(), 30)) {
|
||||
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 ");
|
||||
return fetchResultField(resultSet);
|
||||
}
|
||||
@ -278,6 +276,21 @@ public class CalciteProvider extends Provider {
|
||||
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
|
||||
public ConnectionObj getConnection(DatasourceDTO coreDatasource) throws Exception {
|
||||
ConnectionObj connectionObj = new ConnectionObj();
|
||||
@ -373,8 +386,7 @@ public class CalciteProvider extends Provider {
|
||||
|
||||
// schema
|
||||
ResultSet resultSet = null;
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
||||
PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||
}
|
||||
@ -418,8 +430,7 @@ public class CalciteProvider extends Provider {
|
||||
|
||||
// schema
|
||||
ResultSet resultSet = null;
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
||||
PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||
}
|
||||
@ -458,8 +469,7 @@ public class CalciteProvider extends Provider {
|
||||
|
||||
// schema
|
||||
ResultSet resultSet = null;
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource());
|
||||
PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||
try (ConnectionObj con = getConnection(datasourceRequest.getDatasource()); PreparedStatement statement = getPreparedStatement(con.getConnection(), datasourceConfiguration.getQueryTimeout(), datasourceRequest.getQuery())) {
|
||||
if (DatasourceConfiguration.DatasourceType.valueOf(value.getType()) == DatasourceConfiguration.DatasourceType.oracle) {
|
||||
statement.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = " + datasourceConfiguration.getSchema());
|
||||
}
|
||||
@ -660,137 +670,7 @@ public class CalciteProvider extends Provider {
|
||||
}
|
||||
}
|
||||
|
||||
private String getTableFiledSql(DatasourceRequest datasourceRequest) {
|
||||
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 {
|
||||
private TableField getTableFieldDesc(DatasourceRequest datasourceRequest, ResultSet resultSet) throws SQLException {
|
||||
TableField tableField = new TableField();
|
||||
tableField.setOriginName(resultSet.getString(1));
|
||||
tableField.setType(resultSet.getString(2).toUpperCase());
|
||||
@ -1050,6 +930,103 @@ public class CalciteProvider extends Provider {
|
||||
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 {
|
||||
List<String> tableSqls = new ArrayList<>();
|
||||
DatasourceConfiguration.DatasourceType datasourceType = DatasourceConfiguration.DatasourceType.valueOf(datasourceRequest.getDatasource().getType());
|
||||
@ -1058,6 +1035,22 @@ public class CalciteProvider extends Provider {
|
||||
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(".")) {
|
||||
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:
|
||||
tableSqls.add("show tables");
|
||||
break;
|
||||
@ -1096,57 +1089,19 @@ public class CalciteProvider extends Provider {
|
||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
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()));
|
||||
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()));
|
||||
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()));
|
||||
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;
|
||||
case pg:
|
||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);
|
||||
if (StringUtils.isEmpty(configuration.getSchema())) {
|
||||
DEException.throwException(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
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()));
|
||||
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()));
|
||||
break;
|
||||
case redshift:
|
||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
||||
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()));
|
||||
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()));
|
||||
break;
|
||||
case ck:
|
||||
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), CK.class);
|
||||
@ -1159,9 +1114,9 @@ public class CalciteProvider extends Provider {
|
||||
String[] databasePrams = matcher.group(3).split("\\?");
|
||||
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));
|
||||
}else {
|
||||
} else {
|
||||
tableSqls.add("SELECT name, comment FROM system.tables where database='DATABASE';".replace("DATABASE", database));
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,7 @@ const emits = defineEmits(['changeId'])
|
||||
:is-read-only="isReadOnly"
|
||||
:isShowEnable="isShowEnable"
|
||||
:parameters="apiRequest.arguments"
|
||||
:value-list="valueList"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
|
||||
|
@ -86,11 +86,26 @@ const options = [
|
||||
label: '固定值',
|
||||
value: 'fixed'
|
||||
},
|
||||
{
|
||||
label: '时间函数',
|
||||
value: 'timeFun'
|
||||
},
|
||||
{
|
||||
label: '自定义',
|
||||
value: 'custom'
|
||||
}
|
||||
]
|
||||
|
||||
const timeFunLists = [
|
||||
{
|
||||
label: '当天(yyyy-MM-DD)',
|
||||
value: 'currentDay yyyy-MM-DD'
|
||||
},
|
||||
{
|
||||
label: '当天(yyyy/MM/DD)',
|
||||
value: 'currentDay yyyy/MM/DD'
|
||||
}
|
||||
]
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -161,9 +176,25 @@ const options = [
|
||||
:value="item.originName"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select
|
||||
v-model="element.value"
|
||||
v-if="!needMock && activeName === 'table' && element.nameType === 'timeFun'"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in timeFunLists"
|
||||
:key="item.originName"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
|
||||
<el-input
|
||||
v-if="!needMock && activeName === 'table' && element.nameType !== 'params'"
|
||||
v-if="
|
||||
!needMock &&
|
||||
activeName === 'table' &&
|
||||
element.nameType !== 'params' &&
|
||||
element.nameType !== 'timeFun'
|
||||
"
|
||||
v-model="element.value"
|
||||
:disabled="isReadOnly"
|
||||
:placeholder="element.nameType === 'fixed' ? '值' : '可用${参数名},使用参数'"
|
||||
|
@ -22,6 +22,10 @@ const props = defineProps({
|
||||
type: Array as PropType<Item[]>,
|
||||
default: () => []
|
||||
},
|
||||
valueList: {
|
||||
type: Array as PropType<Item[]>,
|
||||
default: () => []
|
||||
},
|
||||
suggestions: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
@ -43,6 +47,7 @@ onBeforeMount(() => {
|
||||
parameters.value.push(
|
||||
new KeyValue({
|
||||
type: 'text',
|
||||
nameType: 'fixed',
|
||||
enable: true,
|
||||
required: true,
|
||||
uuid: guid(),
|
||||
@ -91,7 +96,36 @@ const createFilter = (queryString: string) => {
|
||||
return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
|
||||
}
|
||||
}
|
||||
|
||||
const activeName = inject('api-active-name')
|
||||
const options = [
|
||||
{
|
||||
label: '参数',
|
||||
value: 'params'
|
||||
},
|
||||
{
|
||||
label: '固定值',
|
||||
value: 'fixed'
|
||||
},
|
||||
{
|
||||
label: '时间函数',
|
||||
value: 'timeFun'
|
||||
},
|
||||
{
|
||||
label: '自定义',
|
||||
value: 'custom'
|
||||
}
|
||||
]
|
||||
const timeFunLists = [
|
||||
{
|
||||
label: '当天(yyyy-MM-DD)',
|
||||
value: 'currentDay yyyy-MM-DD'
|
||||
},
|
||||
{
|
||||
label: '当天(yyyy/MM/DD)',
|
||||
value: 'currentDay yyyy/MM/DD'
|
||||
}
|
||||
]
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -138,9 +172,55 @@ const activeName = inject('api-active-name')
|
||||
show-word-limit
|
||||
/>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="3" v-if="activeName === 'table'">
|
||||
<el-select v-model="element.nameType">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col v-if="element.type !== 'file'" :span="6">
|
||||
<el-input
|
||||
v-if="activeName === 'params'"
|
||||
v-model="element.value"
|
||||
:disabled="isReadOnly"
|
||||
class="input-with-autocomplete"
|
||||
:placeholder="valueText"
|
||||
value-key="name"
|
||||
highlight-first-item
|
||||
/>
|
||||
|
||||
<el-select
|
||||
v-model="element.value"
|
||||
v-if="!needMock && activeName === 'table' && element.nameType === 'params'"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in valueList"
|
||||
:key="item.originName"
|
||||
:label="item.name"
|
||||
:value="item.originName"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select
|
||||
v-model="element.value"
|
||||
v-if="!needMock && activeName === 'table' && element.nameType === 'timeFun'"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in timeFunLists"
|
||||
:key="item.originName"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input
|
||||
v-if="
|
||||
activeName === 'table' &&
|
||||
element.nameType !== 'params' &&
|
||||
element.nameType !== 'timeFun'
|
||||
"
|
||||
v-model="element.value"
|
||||
:disabled="isReadOnly"
|
||||
class="input-with-autocomplete"
|
||||
@ -150,7 +230,7 @@ const activeName = inject('api-active-name')
|
||||
/>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="10">
|
||||
<el-col :span="activeName === 'params' ? 10 : 7">
|
||||
<el-input
|
||||
v-model="element.description"
|
||||
maxlength="200"
|
||||
|
Loading…
Reference in New Issue
Block a user