Merge pull request #1407 from dataease/pr@dev@refactor_ds_sql

refactor: 数据关联优化
This commit is contained in:
XiaJunjie2020 2021-12-07 16:24:09 +08:00 committed by GitHub
commit 0a5a93fe1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -816,17 +816,12 @@ public class DataSetTableService {
List<DatasetTableField> fieldList = (List<DatasetTableField>) sqlMap.get("field"); List<DatasetTableField> fieldList = (List<DatasetTableField>) sqlMap.get("field");
List<UnionParamDTO> join = (List<UnionParamDTO>) sqlMap.get("join"); List<UnionParamDTO> join = (List<UnionParamDTO>) sqlMap.get("join");
// 处理结果
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
// 使用输入的sql先预执行一次,并拿到所有字段
datasourceRequest.setQuery(sql);
Map<String, Object> res = new HashMap<>(); Map<String, Object> res = new HashMap<>();
// 处理结果
try { try {
List<TableFiled> previewFields = datasourceProvider.fetchResultField(datasourceRequest);
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
datasourceRequest.setQuery(qp.createSQLPreview(sql, previewFields.get(0).getFieldName())); DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
datasourceRequest.setQuery(qp.createSQLPreview(sql, null));
Map<String, List> result = datasourceProvider.fetchResultAndField(datasourceRequest); Map<String, List> result = datasourceProvider.fetchResultAndField(datasourceRequest);
List<String[]> data = result.get("dataList"); List<String[]> data = result.get("dataList");
List<TableFiled> fields = result.get("fieldList"); List<TableFiled> fields = result.get("fieldList");
@ -878,16 +873,11 @@ public class DataSetTableService {
datasourceRequest.setDatasource(ds); datasourceRequest.setDatasource(ds);
sql = getCustomSQLDoris(dataTableInfoDTO, list); sql = getCustomSQLDoris(dataTableInfoDTO, list);
} }
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
// 使用输入的sql先预执行一次,并拿到所有字段
datasourceRequest.setQuery(sql);
Map<String, Object> res = new HashMap<>(); Map<String, Object> res = new HashMap<>();
try { try {
List<TableFiled> previewFields = datasourceProvider.fetchResultField(datasourceRequest); DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
datasourceRequest.setQuery(qp.createSQLPreview(sql, previewFields.get(0).getFieldName())); datasourceRequest.setQuery(qp.createSQLPreview(sql, null));
Map<String, List> result = datasourceProvider.fetchResultAndField(datasourceRequest); Map<String, List> result = datasourceProvider.fetchResultAndField(datasourceRequest);
List<String[]> data = result.get("dataList"); List<String[]> data = result.get("dataList");
List<TableFiled> fields = result.get("fieldList"); List<TableFiled> fields = result.get("fieldList");