fix(数据集):sql数据集优化

This commit is contained in:
junjie 2021-05-11 11:11:42 +08:00
parent 7a5037068e
commit 2cd8111047

View File

@ -74,6 +74,11 @@ public class DataSetTableService {
public DatasetTable save(DatasetTable datasetTable) throws Exception {
checkName(datasetTable);
if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "sql")) {
DataSetTableRequest dataSetTableRequest = new DataSetTableRequest();
BeanUtils.copyBean(dataSetTableRequest, datasetTable);
getSQLPreview(dataSetTableRequest);
}
if (StringUtils.isEmpty(datasetTable.getId())) {
datasetTable.setId(UUID.randomUUID().toString());
datasetTable.setCreateBy(AuthUtils.getUser().getUsername());
@ -320,6 +325,10 @@ public class DataSetTableService {
DatasourceRequest datasourceRequest = new DatasourceRequest();
datasourceRequest.setDatasource(ds);
String sql = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getSql();
// 使用输入的sql先预执行一次
datasourceRequest.setQuery(sql);
datasourceProvider.fetchResultAndField(datasourceRequest);
// 正式执行
datasourceRequest.setQuery("SELECT * FROM (" + sql + ") AS tmp LIMIT 0,1000");
Map<String, List> result = datasourceProvider.fetchResultAndField(datasourceRequest);
List<String[]> data = result.get("dataList");