forked from github/dataease
fix: 【数据集】识别doris类型错误
This commit is contained in:
parent
1d1525edd7
commit
e934e48589
@ -15,9 +15,9 @@ public abstract class DatasourceProvider {
|
||||
|
||||
abstract public List<String> getTables(DatasourceRequest datasourceRequest) throws Exception;
|
||||
|
||||
public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
return new ArrayList<>();
|
||||
};
|
||||
// public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
// return new ArrayList<>();
|
||||
// };
|
||||
|
||||
public void checkStatus(DatasourceRequest datasourceRequest) throws Exception {
|
||||
getData(datasourceRequest);
|
||||
|
@ -211,17 +211,17 @@ public class EsProvider extends DatasourceProvider {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
List<TableFiled> tableFileds = new ArrayList<>();
|
||||
try {
|
||||
String response = exexQuery(datasourceRequest, "desc " + datasourceRequest.getTable(), "?format=json");
|
||||
tableFileds = fetchResultField(response);
|
||||
} catch (Exception e) {
|
||||
DataEaseException.throwException(e);
|
||||
}
|
||||
return tableFileds;
|
||||
}
|
||||
// @Override
|
||||
// public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
// List<TableFiled> tableFileds = new ArrayList<>();
|
||||
// try {
|
||||
// String response = exexQuery(datasourceRequest, "desc " + datasourceRequest.getTable(), "?format=json");
|
||||
// tableFileds = fetchResultField(response);
|
||||
// } catch (Exception e) {
|
||||
// DataEaseException.throwException(e);
|
||||
// }
|
||||
// return tableFileds;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void checkStatus(DatasourceRequest datasourceRequest) throws Exception {
|
||||
|
@ -267,46 +267,53 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
List<TableFiled> list = new LinkedList<>();
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = getConnectionFromPool(datasourceRequest);
|
||||
DatabaseMetaData databaseMetaData = connection.getMetaData();
|
||||
ResultSet resultSet = databaseMetaData.getColumns(null, "%", datasourceRequest.getTable(), "%");
|
||||
while (resultSet.next()) {
|
||||
String tableName = resultSet.getString("TABLE_NAME");
|
||||
String database = null;
|
||||
if(datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name())){
|
||||
database = resultSet.getString("TABLE_SCHEM");
|
||||
}else {
|
||||
database = resultSet.getString("TABLE_CAT");
|
||||
}
|
||||
if(database != null){
|
||||
if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) {
|
||||
TableFiled tableFiled = getTableFiled(resultSet, datasourceRequest);
|
||||
list.add(tableFiled);
|
||||
}
|
||||
}else {
|
||||
if (tableName.equals(datasourceRequest.getTable())) {
|
||||
TableFiled tableFiled = getTableFiled(resultSet, datasourceRequest);
|
||||
list.add(tableFiled);
|
||||
}
|
||||
}
|
||||
}
|
||||
resultSet.close();
|
||||
} catch (SQLException e) {
|
||||
DataEaseException.throwException(e);
|
||||
} catch (Exception e) {
|
||||
DataEaseException.throwException(e);
|
||||
} finally {
|
||||
if(connection != null){
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
// @Override
|
||||
// public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
// List<TableFiled> list = new LinkedList<>();
|
||||
// Connection connection = null;
|
||||
// ResultSet resultSet = null;
|
||||
// try {
|
||||
// connection = getConnectionFromPool(datasourceRequest);
|
||||
// DatabaseMetaData databaseMetaData = connection.getMetaData();
|
||||
// resultSet = databaseMetaData.getColumns(null, "%", datasourceRequest.getTable(), "%");
|
||||
// while (resultSet.next()) {
|
||||
// String tableName = resultSet.getString("TABLE_NAME");
|
||||
// String database = null;
|
||||
// if(datasourceRequest.getDatasource().getType().equalsIgnoreCase(DatasourceTypes.ck.name())){
|
||||
// database = resultSet.getString("TABLE_SCHEM");
|
||||
// }else {
|
||||
// database = resultSet.getString("TABLE_CAT");
|
||||
// }
|
||||
// if(database != null){
|
||||
// if (tableName.equals(datasourceRequest.getTable()) && database.equalsIgnoreCase(getDatabase(datasourceRequest))) {
|
||||
// TableFiled tableFiled = getTableFiled(resultSet, datasourceRequest);
|
||||
// list.add(tableFiled);
|
||||
// }
|
||||
// }else {
|
||||
// if (tableName.equals(datasourceRequest.getTable())) {
|
||||
// TableFiled tableFiled = getTableFiled(resultSet, datasourceRequest);
|
||||
// list.add(tableFiled);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// resultSet.close();
|
||||
//
|
||||
// Statement stat = connection.createStatement();
|
||||
// resultSet = stat.executeQuery(datasourceRequest.getQuery());
|
||||
// return fetchResultField(resultSet, datasourceRequest);
|
||||
//
|
||||
//
|
||||
// } catch (SQLException e) {
|
||||
// DataEaseException.throwException(e);
|
||||
// } catch (Exception e) {
|
||||
// DataEaseException.throwException(e);
|
||||
// } finally {
|
||||
// if(connection != null){
|
||||
// connection.close();
|
||||
// }
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
|
||||
private TableFiled getTableFiled(ResultSet resultSet, DatasourceRequest datasourceRequest) throws SQLException {
|
||||
TableFiled tableFiled = new TableFiled();
|
||||
|
@ -81,4 +81,8 @@ public abstract class QueryProvider {
|
||||
tableObj.setTableName(schema + "." + tableObj.getTableName());
|
||||
}
|
||||
}
|
||||
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
return "select * from tableName";
|
||||
}
|
||||
}
|
||||
|
@ -724,6 +724,11 @@ public class CKQueryProvider extends QueryProvider {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") AS tmp ", fields, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
return "SELECT * FROM " + String.format(CKConstants.KEYWORD_TABLE, tableName);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
|
@ -10,6 +10,7 @@ import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.ck.CKConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -698,6 +699,11 @@ public class DorisQueryProvider extends QueryProvider {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") AS tmp ", fields, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
return createSQLPreview("SELECT * FROM " + String.format(DorisConstants.KEYWORD_TABLE, tableName), null);
|
||||
}
|
||||
|
||||
private String sqlFix(String sql) {
|
||||
if (sql.lastIndexOf(";") == (sql.length() - 1)) {
|
||||
sql = sql.substring(0, sql.length() - 1);
|
||||
|
@ -11,6 +11,7 @@ import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.ck.CKConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -653,6 +654,11 @@ public class EsQueryProvider extends QueryProvider {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") AS tmp ", fields, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
return createSQLPreview("SELECT * FROM " + String.format(EsSqlLConstants.KEYWORD_TABLE, tableName), null);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
|
@ -10,6 +10,7 @@ import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.es.EsSqlLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -692,6 +693,11 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") AS tmp ", fields, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
return createSQLPreview("SELECT * FROM " + String.format(MySQLConstants.KEYWORD_TABLE, tableName), null);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
|
@ -13,6 +13,7 @@ import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.mysql.MySQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -743,6 +744,13 @@ public class OracleQueryProvider extends QueryProvider {
|
||||
return MessageFormat.format("SELECT {0} FROM {1}", StringUtils.join(array, ","), " (" + sqlFix(sql) + ") DE_TMP ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
String schema = new Gson().fromJson(ds.getConfiguration(), JdbcDTO.class).getSchema();
|
||||
schema = String.format( OracleConstants.KEYWORD_TABLE, schema);
|
||||
return createSQLPreview("SELECT * FROM " + schema + "." + String.format(OracleConstants.KEYWORD_TABLE, tableName), null);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
|
@ -13,6 +13,8 @@ import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.mysql.MySQLConstants;
|
||||
import io.dataease.provider.oracle.OracleConstants;
|
||||
import io.dataease.provider.sqlserver.SqlServerSQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@ -720,6 +722,13 @@ public class PgQueryProvider extends QueryProvider {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") AS tmp ", fields, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
String schema = new Gson().fromJson(ds.getConfiguration(), JdbcDTO.class).getSchema();
|
||||
schema = String.format( PgConstants.KEYWORD_TABLE, schema);
|
||||
return createSQLPreview("SELECT * FROM " + schema + "." + String.format(PgConstants.KEYWORD_TABLE, tableName), null);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
|
@ -15,6 +15,7 @@ import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.oracle.OracleConstants;
|
||||
import io.dataease.provider.pg.PgConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -678,6 +679,13 @@ public class SqlserverQueryProvider extends QueryProvider {
|
||||
return createRawQuerySQL(" (" + sqlFix(sql) + ") AS tmp ", fields, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertTableToSql(String tableName, Datasource ds){
|
||||
String schema = new Gson().fromJson(ds.getConfiguration(), JdbcDTO.class).getSchema();
|
||||
schema = String.format( SqlServerSQLConstants.KEYWORD_TABLE, schema);
|
||||
return createSQLPreview("SELECT * FROM " + schema + "." + String.format(SqlServerSQLConstants.KEYWORD_TABLE, tableName), null);
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
|
@ -387,8 +387,9 @@ public class DataSetTableService {
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
datasourceRequest.setTable(new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getTable());
|
||||
return datasourceProvider.getTableFileds(datasourceRequest);
|
||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||
datasourceRequest.setQuery(qp.convertTableToSql(new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getTable(), ds));
|
||||
return datasourceProvider.fetchResultField(datasourceRequest);
|
||||
}
|
||||
|
||||
public Map<String, List<DatasetTableField>> getFieldsFromDE(DataSetTableRequest dataSetTableRequest) throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user