forked from github/dataease
feat: 同数据源直连数据集之间支持数据关联
This commit is contained in:
parent
1d927404d9
commit
a68323de2f
@ -20,12 +20,14 @@ import io.dataease.datasource.provider.ProviderFactory;
|
|||||||
import io.dataease.datasource.request.DatasourceRequest;
|
import io.dataease.datasource.request.DatasourceRequest;
|
||||||
import io.dataease.datasource.service.DatasourceService;
|
import io.dataease.datasource.service.DatasourceService;
|
||||||
import io.dataease.dto.chart.*;
|
import io.dataease.dto.chart.*;
|
||||||
|
import io.dataease.dto.dataset.DataSetTableUnionDTO;
|
||||||
import io.dataease.dto.dataset.DataTableInfoDTO;
|
import io.dataease.dto.dataset.DataTableInfoDTO;
|
||||||
import io.dataease.i18n.Translator;
|
import io.dataease.i18n.Translator;
|
||||||
import io.dataease.listener.util.CacheUtils;
|
import io.dataease.listener.util.CacheUtils;
|
||||||
import io.dataease.provider.QueryProvider;
|
import io.dataease.provider.QueryProvider;
|
||||||
import io.dataease.service.dataset.DataSetTableFieldsService;
|
import io.dataease.service.dataset.DataSetTableFieldsService;
|
||||||
import io.dataease.service.dataset.DataSetTableService;
|
import io.dataease.service.dataset.DataSetTableService;
|
||||||
|
import io.dataease.service.dataset.DataSetTableUnionService;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -56,6 +58,8 @@ public class ChartViewService {
|
|||||||
private DataSetTableFieldsService dataSetTableFieldsService;
|
private DataSetTableFieldsService dataSetTableFieldsService;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtChartGroupMapper extChartGroupMapper;
|
private ExtChartGroupMapper extChartGroupMapper;
|
||||||
|
@Resource
|
||||||
|
private DataSetTableUnionService dataSetTableUnionService;
|
||||||
|
|
||||||
//默认使用非公平
|
//默认使用非公平
|
||||||
private ReentrantLock lock = new ReentrantLock();
|
private ReentrantLock lock = new ReentrantLock();
|
||||||
@ -197,6 +201,15 @@ public class ChartViewService {
|
|||||||
} else {
|
} else {
|
||||||
datasourceRequest.setQuery(qp.getSQLAsTmp(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList));
|
datasourceRequest.setQuery(qp.getSQLAsTmp(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList));
|
||||||
}
|
}
|
||||||
|
} else if (StringUtils.equalsIgnoreCase(table.getType(), "custom")) {
|
||||||
|
DataTableInfoDTO dt = new Gson().fromJson(table.getInfo(), DataTableInfoDTO.class);
|
||||||
|
List<DataSetTableUnionDTO> list = dataSetTableUnionService.listByTableId(dt.getList().get(0).getTableId());
|
||||||
|
String sql = dataSetTableService.getCustomSQLDatasource(dt, list, ds);
|
||||||
|
if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType())) {
|
||||||
|
datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(sql, yAxis, customFilter, extFilterList));
|
||||||
|
} else {
|
||||||
|
datasourceRequest.setQuery(qp.getSQLAsTmp(sql, xAxis, yAxis, customFilter, extFilterList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data = datasourceProvider.getData(datasourceRequest);
|
data = datasourceProvider.getData(datasourceRequest);
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import io.dataease.commons.utils.*;
|
|||||||
import io.dataease.controller.request.dataset.DataSetGroupRequest;
|
import io.dataease.controller.request.dataset.DataSetGroupRequest;
|
||||||
import io.dataease.controller.request.dataset.DataSetTableRequest;
|
import io.dataease.controller.request.dataset.DataSetTableRequest;
|
||||||
import io.dataease.controller.request.dataset.DataSetTaskRequest;
|
import io.dataease.controller.request.dataset.DataSetTaskRequest;
|
||||||
|
import io.dataease.datasource.constants.DatasourceTypes;
|
||||||
import io.dataease.datasource.dto.TableFiled;
|
import io.dataease.datasource.dto.TableFiled;
|
||||||
import io.dataease.datasource.provider.DatasourceProvider;
|
import io.dataease.datasource.provider.DatasourceProvider;
|
||||||
import io.dataease.datasource.provider.JdbcProvider;
|
import io.dataease.datasource.provider.JdbcProvider;
|
||||||
@ -373,7 +374,6 @@ public class DataSetTableService {
|
|||||||
String sql = dataTableInfoDTO.getSql();
|
String sql = dataTableInfoDTO.getSql();
|
||||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||||
datasourceRequest.setQuery(qp.createQuerySQLAsTmpWithPage(sql, fields, page, pageSize, realSize));
|
datasourceRequest.setQuery(qp.createQuerySQLAsTmpWithPage(sql, fields, page, pageSize, realSize));
|
||||||
System.out.println(datasourceRequest.getQuery());
|
|
||||||
try {
|
try {
|
||||||
data.addAll(datasourceProvider.getData(datasourceRequest));
|
data.addAll(datasourceProvider.getData(datasourceRequest));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -444,24 +444,52 @@ public class DataSetTableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
||||||
Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");
|
if (datasetTable.getMode() == 0) {
|
||||||
JdbcProvider jdbcProvider = CommonBeanFactory.getBean(JdbcProvider.class);
|
Datasource ds = datasourceMapper.selectByPrimaryKey(dataSetTableRequest.getDataSourceId());
|
||||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
if (ObjectUtils.isEmpty(ds)) {
|
||||||
datasourceRequest.setDatasource(ds);
|
throw new RuntimeException(Translator.get("i18n_datasource_delete"));
|
||||||
String table = DorisTableUtils.dorisName(dataSetTableRequest.getId());
|
}
|
||||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||||
datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize));
|
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||||
try {
|
datasourceRequest.setDatasource(ds);
|
||||||
data.addAll(jdbcProvider.getData(datasourceRequest));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
DataTableInfoDTO dt = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class);
|
||||||
datasourceRequest.setQuery(qp.createQueryTableWithLimit(table, fields, Integer.valueOf(dataSetTableRequest.getRow())));
|
List<DataSetTableUnionDTO> list = dataSetTableUnionService.listByTableId(dt.getList().get(0).getTableId());
|
||||||
dataSetPreviewPage.setTotal(Integer.valueOf(jdbcProvider.getData(datasourceRequest).get(0)[0]));
|
|
||||||
} catch (Exception e) {
|
String sql = getCustomSQLDatasource(dt, list, ds);
|
||||||
e.printStackTrace();
|
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||||
|
datasourceRequest.setQuery(qp.createQuerySQLAsTmpWithPage(sql, fields, page, pageSize, realSize));
|
||||||
|
try {
|
||||||
|
data.addAll(datasourceProvider.getData(datasourceRequest));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
datasourceRequest.setQuery(qp.createQuerySqlWithLimit(sql, fields, Integer.valueOf(dataSetTableRequest.getRow())));
|
||||||
|
dataSetPreviewPage.setTotal(datasourceProvider.getData(datasourceRequest).size());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");
|
||||||
|
JdbcProvider jdbcProvider = CommonBeanFactory.getBean(JdbcProvider.class);
|
||||||
|
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||||
|
datasourceRequest.setDatasource(ds);
|
||||||
|
String table = DorisTableUtils.dorisName(dataSetTableRequest.getId());
|
||||||
|
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||||
|
datasourceRequest.setQuery(qp.createQuerySQLWithPage(table, fields, page, pageSize, realSize));
|
||||||
|
try {
|
||||||
|
data.addAll(jdbcProvider.getData(datasourceRequest));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
datasourceRequest.setQuery(qp.createQueryTableWithLimit(table, fields, Integer.valueOf(dataSetTableRequest.getRow())));
|
||||||
|
dataSetPreviewPage.setTotal(Integer.valueOf(jdbcProvider.getData(datasourceRequest).get(0)[0]));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,25 +551,34 @@ public class DataSetTableService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getCustomPreview(DataSetTableRequest dataSetTableRequest) throws Exception {
|
public Map<String, Object> getCustomPreview(DataSetTableRequest dataSetTableRequest) throws Exception {
|
||||||
Datasource ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");
|
|
||||||
JdbcProvider jdbcProvider = CommonBeanFactory.getBean(JdbcProvider.class);
|
|
||||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
|
||||||
datasourceRequest.setDatasource(ds);
|
|
||||||
// String table = DorisTableUtils.dorisName(dataSetTableRequest.getId());
|
|
||||||
|
|
||||||
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
|
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
|
||||||
List<DataSetTableUnionDTO> list = dataSetTableUnionService.listByTableId(dataTableInfoDTO.getList().get(0).getTableId());
|
List<DataSetTableUnionDTO> list = dataSetTableUnionService.listByTableId(dataTableInfoDTO.getList().get(0).getTableId());
|
||||||
String sql = getCustomSQL(dataTableInfoDTO, list);
|
String sql;
|
||||||
|
|
||||||
|
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||||
|
// JdbcProvider jdbcProvider = CommonBeanFactory.getBean(JdbcProvider.class);
|
||||||
|
Datasource ds;
|
||||||
|
if (dataSetTableRequest.getMode() == 0) {
|
||||||
|
ds = datasourceMapper.selectByPrimaryKey(dataSetTableRequest.getDataSourceId());
|
||||||
|
datasourceRequest.setDatasource(ds);
|
||||||
|
sql = getCustomSQLDatasource(dataTableInfoDTO, list, ds);
|
||||||
|
} else {
|
||||||
|
ds = (Datasource) CommonBeanFactory.getBean("DorisDatasource");
|
||||||
|
datasourceRequest.setDatasource(ds);
|
||||||
|
sql = getCustomSQLDoris(dataTableInfoDTO, list);
|
||||||
|
}
|
||||||
|
// String table = DorisTableUtils.dorisName(dataSetTableRequest.getId());
|
||||||
|
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||||
// 使用输入的sql先预执行一次,并拿到所有字段
|
// 使用输入的sql先预执行一次,并拿到所有字段
|
||||||
datasourceRequest.setQuery(sql);
|
datasourceRequest.setQuery(sql);
|
||||||
|
|
||||||
Map<String, Object> res = new HashMap<>();
|
Map<String, Object> res = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
List<TableFiled> previewFields = jdbcProvider.fetchResultField(datasourceRequest);
|
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()));
|
datasourceRequest.setQuery(qp.createSQLPreview(sql, previewFields.get(0).getFieldName()));
|
||||||
Map<String, List> result = jdbcProvider.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");
|
||||||
String[] fieldArray = fields.stream().map(TableFiled::getFieldName).toArray(String[]::new);
|
String[] fieldArray = fields.stream().map(TableFiled::getFieldName).toArray(String[]::new);
|
||||||
@ -564,7 +601,8 @@ public class DataSetTableService {
|
|||||||
});
|
});
|
||||||
for (DatasetTableField datasetTableField : checkedFieldList) {
|
for (DatasetTableField datasetTableField : checkedFieldList) {
|
||||||
for (TableFiled tableFiled : fields) {
|
for (TableFiled tableFiled : fields) {
|
||||||
if (StringUtils.equalsIgnoreCase(tableFiled.getFieldName(), DorisTableUtils.dorisFieldName(datasetTableField.getTableId() + "_" + datasetTableField.getDataeaseName()))) {
|
if (StringUtils.equalsIgnoreCase(tableFiled.getFieldName(), DorisTableUtils.dorisFieldName(datasetTableField.getTableId() + "_" + datasetTableField.getDataeaseName()))
|
||||||
|
|| StringUtils.equalsIgnoreCase(tableFiled.getFieldName(), DorisTableUtils.dorisFieldName(datasetTableField.getTableId() + "_" + datasetTableField.getOriginName()))) {
|
||||||
tableFiled.setRemarks(datasetTableField.getName());
|
tableFiled.setRemarks(datasetTableField.getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -580,7 +618,7 @@ public class DataSetTableService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 自助数据集从doris里预览数据
|
// 自助数据集从doris里预览数据
|
||||||
private String getCustomSQL(DataTableInfoDTO dataTableInfoDTO, List<DataSetTableUnionDTO> list) {
|
private String getCustomSQLDoris(DataTableInfoDTO dataTableInfoDTO, List<DataSetTableUnionDTO> list) {
|
||||||
Map<String, String[]> customInfo = new TreeMap<>();
|
Map<String, String[]> customInfo = new TreeMap<>();
|
||||||
dataTableInfoDTO.getList().forEach(ele -> {
|
dataTableInfoDTO.getList().forEach(ele -> {
|
||||||
String table = DorisTableUtils.dorisName(ele.getTableId());
|
String table = DorisTableUtils.dorisName(ele.getTableId());
|
||||||
@ -633,6 +671,67 @@ public class DataSetTableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCustomSQLDatasource(DataTableInfoDTO dataTableInfoDTO, List<DataSetTableUnionDTO> list, Datasource ds) {
|
||||||
|
DatasourceTypes datasourceTypes = DatasourceTypes.valueOf(ds.getType());
|
||||||
|
String keyword = datasourceTypes.getKeywordPrefix() + "%s" + datasourceTypes.getKeywordSuffix();
|
||||||
|
Map<String, String[]> customInfo = new TreeMap<>();
|
||||||
|
for (DataTableInfoCustomUnion ele : dataTableInfoDTO.getList()) {
|
||||||
|
DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(ele.getTableId());
|
||||||
|
String table = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getTable();
|
||||||
|
if (ObjectUtils.isEmpty(datasetTable)) {
|
||||||
|
throw new RuntimeException(Translator.get("i18n_custom_ds_delete"));
|
||||||
|
}
|
||||||
|
List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(ele.getCheckedFields());
|
||||||
|
if (CollectionUtils.isEmpty(fields)) {
|
||||||
|
throw new RuntimeException(Translator.get("i18n_cst_ds_tb_or_field_deleted"));
|
||||||
|
}
|
||||||
|
String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldName(ele.getTableId() + "_" + f.getOriginName())).toArray(String[]::new);
|
||||||
|
customInfo.put(table, array);
|
||||||
|
}
|
||||||
|
DataTableInfoCustomUnion first = dataTableInfoDTO.getList().get(0);
|
||||||
|
DatasetTable table = datasetTableMapper.selectByPrimaryKey(first.getTableId());
|
||||||
|
String tableName = new Gson().fromJson(table.getInfo(), DataTableInfoDTO.class).getTable();
|
||||||
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
StringBuilder field = new StringBuilder();
|
||||||
|
Iterator<Map.Entry<String, String[]>> iterator = customInfo.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<String, String[]> next = iterator.next();
|
||||||
|
field.append(StringUtils.join(next.getValue(), ",")).append(",");
|
||||||
|
}
|
||||||
|
String f = field.substring(0, field.length() - 1);
|
||||||
|
|
||||||
|
StringBuilder join = new StringBuilder();
|
||||||
|
for (DataTableInfoCustomUnion dataTableInfoCustomUnion : dataTableInfoDTO.getList()) {
|
||||||
|
for (DataSetTableUnionDTO dto : list) {
|
||||||
|
// 被关联表和自助数据集的表相等
|
||||||
|
if (StringUtils.equals(dto.getTargetTableId(), dataTableInfoCustomUnion.getTableId())) {
|
||||||
|
DatasetTableField sourceField = dataSetTableFieldsService.get(dto.getSourceTableFieldId());
|
||||||
|
DatasetTableField targetField = dataSetTableFieldsService.get(dto.getTargetTableFieldId());
|
||||||
|
DatasetTable sourceTable = datasetTableMapper.selectByPrimaryKey(dto.getSourceTableId());
|
||||||
|
String sourceTableName = new Gson().fromJson(sourceTable.getInfo(), DataTableInfoDTO.class).getTable();
|
||||||
|
DatasetTable targetTable = datasetTableMapper.selectByPrimaryKey(dto.getTargetTableId());
|
||||||
|
String targetTableName = new Gson().fromJson(targetTable.getInfo(), DataTableInfoDTO.class).getTable();
|
||||||
|
join.append(convertUnionTypeToSQL(dto.getSourceUnionRelation()))
|
||||||
|
.append(String.format(keyword, targetTableName))
|
||||||
|
.append(" ON ")
|
||||||
|
.append(String.format(keyword, sourceTableName)).append(".").append(String.format(keyword, sourceField.getOriginName()))
|
||||||
|
.append(" = ")
|
||||||
|
.append(String.format(keyword, targetTableName)).append(".").append(String.format(keyword, targetField.getOriginName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(f)) {
|
||||||
|
throw new RuntimeException(Translator.get("i18n_custom_ds_delete"));
|
||||||
|
}
|
||||||
|
return MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)) + join.toString();
|
||||||
|
} else {
|
||||||
|
if (StringUtils.isEmpty(StringUtils.join(customInfo.get(tableName), ","))) {
|
||||||
|
throw new RuntimeException(Translator.get("i18n_custom_ds_delete"));
|
||||||
|
}
|
||||||
|
return MessageFormat.format("SELECT {0} FROM {1}", StringUtils.join(customInfo.get(tableName), ","), String.format(keyword, tableName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String convertUnionTypeToSQL(String unionType) {
|
private String convertUnionTypeToSQL(String unionType) {
|
||||||
switch (unionType) {
|
switch (unionType) {
|
||||||
case "1:1":
|
case "1:1":
|
||||||
@ -673,27 +772,56 @@ public class DataSetTableService {
|
|||||||
fields = (List<TableFiled>) map.get("fields");*/
|
fields = (List<TableFiled>) map.get("fields");*/
|
||||||
fields = dataSetTableRequest.getFields();
|
fields = dataSetTableRequest.getFields();
|
||||||
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
} else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), "custom")) {
|
||||||
// save field
|
if (datasetTable.getMode() == 1) {
|
||||||
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
|
// save field
|
||||||
List<DataTableInfoCustomUnion> list = dataTableInfoDTO.getList();
|
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
|
||||||
List<DatasetTableField> fieldList = new ArrayList<>();
|
List<DataTableInfoCustomUnion> list = dataTableInfoDTO.getList();
|
||||||
list.forEach(ele -> {
|
List<DatasetTableField> fieldList = new ArrayList<>();
|
||||||
List<DatasetTableField> listByIds = dataSetTableFieldsService.getListByIdsEach(ele.getCheckedFields());
|
list.forEach(ele -> {
|
||||||
listByIds.forEach(f -> {
|
List<DatasetTableField> listByIds = dataSetTableFieldsService.getListByIdsEach(ele.getCheckedFields());
|
||||||
f.setDataeaseName(DorisTableUtils.dorisFieldName(ele.getTableId() + "_" + f.getDataeaseName()));
|
listByIds.forEach(f -> {
|
||||||
|
f.setDataeaseName(DorisTableUtils.dorisFieldName(ele.getTableId() + "_" + f.getDataeaseName()));
|
||||||
|
});
|
||||||
|
fieldList.addAll(listByIds);
|
||||||
});
|
});
|
||||||
fieldList.addAll(listByIds);
|
for (int i = 0; i < fieldList.size(); i++) {
|
||||||
});
|
DatasetTableField datasetTableField = fieldList.get(i);
|
||||||
for (int i = 0; i < fieldList.size(); i++) {
|
datasetTableField.setId(null);
|
||||||
DatasetTableField datasetTableField = fieldList.get(i);
|
datasetTableField.setTableId(datasetTable.getId());
|
||||||
datasetTableField.setId(null);
|
datasetTableField.setColumnIndex(i);
|
||||||
datasetTableField.setTableId(datasetTable.getId());
|
}
|
||||||
datasetTableField.setColumnIndex(i);
|
dataSetTableFieldsService.batchEdit(fieldList);
|
||||||
|
// custom 创建doris视图
|
||||||
|
if (datasetTable.getMode() == 1) {
|
||||||
|
createDorisView(DorisTableUtils.dorisName(datasetTable.getId()), getCustomSQLDoris(dataTableInfoDTO, dataSetTableUnionService.listByTableId(dataTableInfoDTO.getList().get(0).getTableId())));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||||
|
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||||
|
datasourceRequest.setDatasource(ds);
|
||||||
|
DataTableInfoDTO dt = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class);
|
||||||
|
List<DataSetTableUnionDTO> list = dataSetTableUnionService.listByTableId(dt.getList().get(0).getTableId());
|
||||||
|
String sqlAsTable = getCustomSQLDatasource(dt, list, ds);
|
||||||
|
datasourceRequest.setQuery(sqlAsTable);
|
||||||
|
fields = datasourceProvider.fetchResultField(datasourceRequest);
|
||||||
|
|
||||||
|
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class);
|
||||||
|
List<DataTableInfoCustomUnion> listField = dataTableInfoDTO.getList();
|
||||||
|
List<DatasetTableField> fieldList = new ArrayList<>();
|
||||||
|
listField.forEach(ele -> {
|
||||||
|
List<DatasetTableField> listByIds = dataSetTableFieldsService.getListByIdsEach(ele.getCheckedFields());
|
||||||
|
fieldList.addAll(listByIds);
|
||||||
|
});
|
||||||
|
for (DatasetTableField field : fieldList) {
|
||||||
|
for (TableFiled tableFiled : fields) {
|
||||||
|
if (StringUtils.equalsIgnoreCase(DorisTableUtils.dorisFieldName(field.getTableId() + "_" + field.getOriginName()), tableFiled.getFieldName())) {
|
||||||
|
tableFiled.setRemarks(field.getName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dataSetTableFieldsService.batchEdit(fieldList);
|
|
||||||
// custom 创建doris视图
|
|
||||||
createDorisView(DorisTableUtils.dorisName(datasetTable.getId()), getCustomSQL(dataTableInfoDTO, dataSetTableUnionService.listByTableId(dataTableInfoDTO.getList().get(0).getTableId())));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
QueryProvider qp = null;
|
QueryProvider qp = null;
|
||||||
if (!ObjectUtils.isEmpty(ds)) {
|
if (!ObjectUtils.isEmpty(ds)) {
|
||||||
|
@ -954,7 +954,8 @@ export default {
|
|||||||
left_join: 'LEFT JOIN',
|
left_join: 'LEFT JOIN',
|
||||||
right_join: 'RIGHT JOIN',
|
right_join: 'RIGHT JOIN',
|
||||||
inner_join: 'INNER JOIN',
|
inner_join: 'INNER JOIN',
|
||||||
full_join: 'FULL JOIN'
|
full_join: 'FULL JOIN',
|
||||||
|
can_not_union_diff_datasource: 'Union dataset must have same data source'
|
||||||
},
|
},
|
||||||
datasource: {
|
datasource: {
|
||||||
datasource: 'Data Source',
|
datasource: 'Data Source',
|
||||||
|
@ -954,7 +954,8 @@ export default {
|
|||||||
left_join: '左連接',
|
left_join: '左連接',
|
||||||
right_join: '右連接',
|
right_join: '右連接',
|
||||||
inner_join: '內連接',
|
inner_join: '內連接',
|
||||||
full_join: '全連接'
|
full_join: '全連接',
|
||||||
|
can_not_union_diff_datasource: '被關聯數據集必須與當前數據集的數據源一致'
|
||||||
},
|
},
|
||||||
datasource: {
|
datasource: {
|
||||||
datasource: '數據源',
|
datasource: '數據源',
|
||||||
|
@ -954,7 +954,8 @@ export default {
|
|||||||
left_join: '左连接',
|
left_join: '左连接',
|
||||||
right_join: '右连接',
|
right_join: '右连接',
|
||||||
inner_join: '内连接',
|
inner_join: '内连接',
|
||||||
full_join: '全连接'
|
full_join: '全连接',
|
||||||
|
can_not_union_diff_datasource: '被关联数据集必须与当前数据集的数据源一致'
|
||||||
},
|
},
|
||||||
datasource: {
|
datasource: {
|
||||||
datasource: '数据源',
|
datasource: '数据源',
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
<el-col style="display: flex;flex-direction: row">
|
<el-col style="display: flex;flex-direction: row">
|
||||||
<el-col class="panel-height" style="width: 220px;border-right:solid 1px #dcdfe6;border-top:solid 1px #dcdfe6;padding-right: 15px;overflow-y: auto;">
|
<el-col class="panel-height" style="width: 220px;border-right:solid 1px #dcdfe6;border-top:solid 1px #dcdfe6;padding-right: 15px;overflow-y: auto;">
|
||||||
<dataset-group-selector :custom-type="customType" :table="table" :mode="1" :checked-list="checkedList" :union-data="unionData" @getTable="getTable" />
|
<dataset-group-selector :custom-type="customType" :table="table" :checked-list="checkedList" :union-data="unionData" @getTable="getTable" />
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col class="panel-height" style="width: 235px;border-top:solid 1px #dcdfe6;padding: 0 15px;overflow-y: auto;">
|
<el-col class="panel-height" style="width: 235px;border-top:solid 1px #dcdfe6;padding: 0 15px;overflow-y: auto;">
|
||||||
<dataset-custom-field :table="table" :checked-list="checkedList" @getChecked="getChecked" />
|
<dataset-custom-field :table="table" :checked-list="checkedList" @getChecked="getChecked" />
|
||||||
@ -151,9 +151,9 @@ export default {
|
|||||||
id: this.param.tableId,
|
id: this.param.tableId,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
sceneId: this.param.id,
|
sceneId: this.param.id,
|
||||||
dataSourceId: null,
|
dataSourceId: this.param.tableId ? this.param.table.dataSourceId : this.table.dataSourceId,
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
mode: 1,
|
mode: this.param.tableId ? this.param.table.mode : this.table.mode,
|
||||||
info: '{"list":' + JSON.stringify(this.checkedList) + '}'
|
info: '{"list":' + JSON.stringify(this.checkedList) + '}'
|
||||||
}
|
}
|
||||||
post('/dataset/table/customPreview', table).then(response => {
|
post('/dataset/table/customPreview', table).then(response => {
|
||||||
@ -202,9 +202,9 @@ export default {
|
|||||||
id: this.param.tableId,
|
id: this.param.tableId,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
sceneId: this.param.id,
|
sceneId: this.param.id,
|
||||||
dataSourceId: null,
|
dataSourceId: this.table.dataSourceId,
|
||||||
type: 'custom',
|
type: 'custom',
|
||||||
mode: 1,
|
mode: this.table.mode,
|
||||||
info: '{"list":' + JSON.stringify(this.checkedList) + '}'
|
info: '{"list":' + JSON.stringify(this.checkedList) + '}'
|
||||||
}
|
}
|
||||||
post('/dataset/table/update', table).then(response => {
|
post('/dataset/table/update', table).then(response => {
|
||||||
|
@ -265,7 +265,9 @@ export default {
|
|||||||
mode: this.mode < 0 ? null : this.mode,
|
mode: this.mode < 0 ? null : this.mode,
|
||||||
typeFilter: this.customType ? this.customType : null
|
typeFilter: this.customType ? this.customType : null
|
||||||
}, false).then(response => {
|
}, false).then(response => {
|
||||||
this.tables = response.data
|
this.tables = response.data.filter(ele => {
|
||||||
|
return !(ele.mode === 0 && ele.type === 'sql')
|
||||||
|
})
|
||||||
for (let i = 0; i < this.tables.length; i++) {
|
for (let i = 0; i < this.tables.length; i++) {
|
||||||
if (this.tables[i].mode === 1 && this.kettleRunning === false) {
|
if (this.tables[i].mode === 1 && this.kettleRunning === false) {
|
||||||
this.$set(this.tables[i], 'disabled', true)
|
this.$set(this.tables[i], 'disabled', true)
|
||||||
|
@ -81,16 +81,16 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column property="originName" :label="$t('dataset.field_origin_name')" width="100">
|
<el-table-column property="originName" :label="$t('dataset.field_origin_name')" width="100">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span :title="scope.row.originName" class="field-class" style="display: inline-block;width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
|
<span :title="scope.row.originName" class="field-class" style="width: 100%;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
|
||||||
{{ scope.row.originName }}
|
<span style="font-size: 12px;">{{ scope.row.originName }}</span>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column property="groupType" :label="$t('dataset.field_group_type')" width="180">
|
<el-table-column property="groupType" :label="$t('dataset.field_group_type')" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-radio-group v-model="scope.row.groupType">
|
<el-radio-group v-model="scope.row.groupType" size="mini">
|
||||||
<el-radio label="d">{{ $t('chart.dimension') }}</el-radio>
|
<el-radio-button label="d">{{ $t('chart.dimension') }}</el-radio-button>
|
||||||
<el-radio label="q">{{ $t('chart.quota') }}</el-radio>
|
<el-radio-button label="q">{{ $t('chart.quota') }}</el-radio-button>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
<el-radio class="union-relation-css" label="1:N">{{ $t('dataset.left_join') }}</el-radio>
|
<el-radio class="union-relation-css" label="1:N">{{ $t('dataset.left_join') }}</el-radio>
|
||||||
<el-radio class="union-relation-css" label="N:1">{{ $t('dataset.right_join') }}</el-radio>
|
<el-radio class="union-relation-css" label="N:1">{{ $t('dataset.right_join') }}</el-radio>
|
||||||
<el-radio class="union-relation-css" label="1:1">{{ $t('dataset.inner_join') }}</el-radio>
|
<el-radio class="union-relation-css" label="1:1">{{ $t('dataset.inner_join') }}</el-radio>
|
||||||
<el-radio class="union-relation-css" label="N:N">{{ $t('dataset.full_join') }}</el-radio>
|
<!-- <el-radio class="union-relation-css" label="N:N">{{ $t('dataset.full_join') }}</el-radio>-->
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
|
||||||
@ -105,7 +105,7 @@
|
|||||||
width="500"
|
width="500"
|
||||||
trigger="click"
|
trigger="click"
|
||||||
>
|
>
|
||||||
<dataset-group-selector-tree :fix-height="true" show-mode="union" :custom-type="customType" :mode="1" @getTable="getTable" />
|
<dataset-group-selector-tree :fix-height="true" show-mode="union" :custom-type="customType" :mode="table.mode" @getTable="getTable" />
|
||||||
<el-button slot="reference" size="mini" style="width: 100%;">
|
<el-button slot="reference" size="mini" style="width: 100%;">
|
||||||
<p class="table-name-css" :title="targetTable.name || $t('dataset.pls_slc_union_table')">{{ targetTable.name || $t('dataset.pls_slc_union_table') }}</p>
|
<p class="table-name-css" :title="targetTable.name || $t('dataset.pls_slc_union_table')">{{ targetTable.name || $t('dataset.pls_slc_union_table') }}</p>
|
||||||
</el-button>
|
</el-button>
|
||||||
@ -204,6 +204,9 @@ export default {
|
|||||||
},
|
},
|
||||||
initUnion() {
|
initUnion() {
|
||||||
if (this.table.id) {
|
if (this.table.id) {
|
||||||
|
if (this.table.mode === 0) {
|
||||||
|
this.customType = ['db']
|
||||||
|
}
|
||||||
post('dataset/union/listByTableId/' + this.table.id, {}).then(response => {
|
post('dataset/union/listByTableId/' + this.table.id, {}).then(response => {
|
||||||
// console.log(response)
|
// console.log(response)
|
||||||
this.unionData = response.data
|
this.unionData = response.data
|
||||||
@ -301,6 +304,16 @@ export default {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (this.table.mode === 0) {
|
||||||
|
if (param.dataSourceId !== this.table.dataSourceId) {
|
||||||
|
this.$message({
|
||||||
|
type: 'error',
|
||||||
|
message: this.$t('dataset.can_not_union_diff_datasource'),
|
||||||
|
showClose: true
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
this.targetTable = param
|
this.targetTable = param
|
||||||
this.union.targetTableId = param.id
|
this.union.targetTableId = param.id
|
||||||
this.union.targetTableFieldId = ''
|
this.union.targetTableFieldId = ''
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
<el-tab-pane :label="$t('dataset.data_preview')" name="dataPreview">
|
<el-tab-pane :label="$t('dataset.data_preview')" name="dataPreview">
|
||||||
<tab-data-preview :param="param" :table="table" :fields="fields" :data="data" :page="page" :form="tableViewRowForm" @reSearch="reSearch" />
|
<tab-data-preview :param="param" :table="table" :fields="fields" :data="data" :page="page" :form="tableViewRowForm" @reSearch="reSearch" />
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane v-if="table.type !== 'custom' && table.mode === 1" :label="$t('dataset.join_view')" name="joinView">
|
<el-tab-pane v-if="table.type !== 'custom'" :label="$t('dataset.join_view')" name="joinView">
|
||||||
<union-view :param="param" :table="table" />
|
<union-view :param="param" :table="table" />
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
<el-tab-pane v-if="table.mode === 1 && (table.type === 'db' || table.type === 'sql')" :label="$t('dataset.update_info')" name="updateInfo">
|
<el-tab-pane v-if="table.mode === 1 && (table.type === 'db' || table.type === 'sql')" :label="$t('dataset.update_info')" name="updateInfo">
|
||||||
@ -156,10 +156,10 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
editSql() {
|
editSql() {
|
||||||
this.$emit('switchComponent', { name: 'AddSQL', param: { id: this.table.sceneId, tableId: this.table.id }})
|
this.$emit('switchComponent', { name: 'AddSQL', param: { id: this.table.sceneId, tableId: this.table.id, table: this.table }})
|
||||||
},
|
},
|
||||||
editCustom() {
|
editCustom() {
|
||||||
this.$emit('switchComponent', { name: 'AddCustom', param: { id: this.table.sceneId, tableId: this.table.id }})
|
this.$emit('switchComponent', { name: 'AddCustom', param: { id: this.table.sceneId, tableId: this.table.id, table: this.table }})
|
||||||
},
|
},
|
||||||
|
|
||||||
reSearch(val) {
|
reSearch(val) {
|
||||||
|
Loading…
Reference in New Issue
Block a user