提交 a1909f59 authored 作者: junjie's avatar junjie

feat(数据集): 关联数据集

上级 9dd41785
...@@ -1083,9 +1083,7 @@ public class DataSetTableService { ...@@ -1083,9 +1083,7 @@ public class DataSetTableService {
DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId)); DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId));
} }
List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField());
if (CollectionUtils.isEmpty(fields)) {
DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId));
}
String[] array = fields.stream().map(f -> table + "." + f.getDataeaseName() + " AS " + DorisTableUtils.dorisFieldName(tableId + "_" + f.getDataeaseName())).toArray(String[]::new); String[] array = fields.stream().map(f -> table + "." + f.getDataeaseName() + " AS " + DorisTableUtils.dorisFieldName(tableId + "_" + f.getDataeaseName())).toArray(String[]::new);
checkedInfo.put(table, array); checkedInfo.put(table, array);
checkedFields.addAll(fields); checkedFields.addAll(fields);
...@@ -1103,7 +1101,7 @@ public class DataSetTableService { ...@@ -1103,7 +1101,7 @@ public class DataSetTableService {
Map.Entry<String, String[]> next = iterator.next(); Map.Entry<String, String[]> next = iterator.next();
field.append(StringUtils.join(next.getValue(), ",")).append(","); field.append(StringUtils.join(next.getValue(), ",")).append(",");
} }
String f = field.substring(0, field.length() - 1); String f = subPrefixSuffixChar(field.toString());
// join // join
StringBuilder join = new StringBuilder(); StringBuilder join = new StringBuilder();
for (UnionParamDTO unionParamDTO : unionList) { for (UnionParamDTO unionParamDTO : unionList) {
...@@ -1134,13 +1132,13 @@ public class DataSetTableService { ...@@ -1134,13 +1132,13 @@ public class DataSetTableService {
} }
} }
if (StringUtils.isEmpty(f)) { if (StringUtils.isEmpty(f)) {
DEException.throwException(Translator.get("i18n_custom_ds_delete")); DEException.throwException(Translator.get("i18n_union_ds_no_checked"));
} }
sql = MessageFormat.format("SELECT {0} FROM {1}", f, DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())) + join.toString(); sql = MessageFormat.format("SELECT {0} FROM {1}", f, DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())) + join.toString();
} else { } else {
String f = StringUtils.join(checkedInfo.get(DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())), ","); String f = StringUtils.join(checkedInfo.get(DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())), ",");
if (StringUtils.isEmpty(f)) { if (StringUtils.isEmpty(f)) {
throw new RuntimeException(Translator.get("i18n_custom_ds_delete")); throw new RuntimeException(Translator.get("i18n_union_ds_no_checked"));
} }
sql = MessageFormat.format("SELECT {0} FROM {1}", f, DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId())); sql = MessageFormat.format("SELECT {0} FROM {1}", f, DorisTableUtils.dorisName(union.get(0).getCurrentDs().getId()));
} }
...@@ -1162,9 +1160,7 @@ public class DataSetTableService { ...@@ -1162,9 +1160,7 @@ public class DataSetTableService {
DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId)); DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId));
} }
List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField());
if (CollectionUtils.isEmpty(fields)) {
DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId));
}
String[] array = fields.stream().map(f -> table + "." + f.getDataeaseName() + " AS " + DorisTableUtils.dorisFieldName(tableId + "_" + f.getDataeaseName())).toArray(String[]::new); String[] array = fields.stream().map(f -> table + "." + f.getDataeaseName() + " AS " + DorisTableUtils.dorisFieldName(tableId + "_" + f.getDataeaseName())).toArray(String[]::new);
checkedInfo.put(table, array); checkedInfo.put(table, array);
checkedFields.addAll(fields); checkedFields.addAll(fields);
...@@ -1196,9 +1192,7 @@ public class DataSetTableService { ...@@ -1196,9 +1192,7 @@ public class DataSetTableService {
DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId)); DEException.throwException(Translator.get("i18n_custom_ds_delete") + String.format(":table id [%s]", tableId));
} }
List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField());
if (CollectionUtils.isEmpty(fields)) {
DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId));
}
String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldNameShort(tableId + "_" + f.getOriginName())).toArray(String[]::new); String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldNameShort(tableId + "_" + f.getOriginName())).toArray(String[]::new);
checkedInfo.put(table, array); checkedInfo.put(table, array);
checkedFields.addAll(fields); checkedFields.addAll(fields);
...@@ -1216,7 +1210,7 @@ public class DataSetTableService { ...@@ -1216,7 +1210,7 @@ public class DataSetTableService {
Map.Entry<String, String[]> next = iterator.next(); Map.Entry<String, String[]> next = iterator.next();
field.append(StringUtils.join(next.getValue(), ",")).append(","); field.append(StringUtils.join(next.getValue(), ",")).append(",");
} }
String f = field.substring(0, field.length() - 1); String f = subPrefixSuffixChar(field.toString());
// join // join
StringBuilder join = new StringBuilder(); StringBuilder join = new StringBuilder();
for (UnionParamDTO unionParamDTO : unionList) { for (UnionParamDTO unionParamDTO : unionList) {
...@@ -1249,13 +1243,13 @@ public class DataSetTableService { ...@@ -1249,13 +1243,13 @@ public class DataSetTableService {
} }
} }
if (StringUtils.isEmpty(f)) { if (StringUtils.isEmpty(f)) {
DEException.throwException(Translator.get("i18n_custom_ds_delete")); DEException.throwException(Translator.get("i18n_union_ds_no_checked"));
} }
sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)) + join.toString(); sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)) + join.toString();
} else { } else {
String f = StringUtils.join(checkedInfo.get(tableName), ","); String f = StringUtils.join(checkedInfo.get(tableName), ",");
if (StringUtils.isEmpty(f)) { if (StringUtils.isEmpty(f)) {
throw new RuntimeException(Translator.get("i18n_custom_ds_delete")); throw new RuntimeException(Translator.get("i18n_union_ds_no_checked"));
} }
sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)); sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName));
} }
...@@ -1266,6 +1260,16 @@ public class DataSetTableService { ...@@ -1266,6 +1260,16 @@ public class DataSetTableService {
return map; return map;
} }
private String subPrefixSuffixChar(String str) {
while (StringUtils.startsWith(str, ",")) {
str = str.substring(1, str.length());
}
while (StringUtils.endsWith(str, ",")) {
str = str.substring(0, str.length() - 1);
}
return str;
}
// 递归计算出所有子级的checkedFields和unionParam // 递归计算出所有子级的checkedFields和unionParam
private void getUnionSQLDatasourceJoin(List<UnionDTO> childrenDs, Map<String, String[]> checkedInfo, List<UnionParamDTO> unionList, String keyword, List<DatasetTableField> checkedFields) { private void getUnionSQLDatasourceJoin(List<UnionDTO> childrenDs, Map<String, String[]> checkedInfo, List<UnionParamDTO> unionList, String keyword, List<DatasetTableField> checkedFields) {
for (int i = 0; i < childrenDs.size(); i++) { for (int i = 0; i < childrenDs.size(); i++) {
...@@ -1279,9 +1283,7 @@ public class DataSetTableService { ...@@ -1279,9 +1283,7 @@ public class DataSetTableService {
String table = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getTable(); String table = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getTable();
List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField()); List<DatasetTableField> fields = dataSetTableFieldsService.getListByIdsEach(unionDTO.getCurrentDsField());
if (CollectionUtils.isEmpty(fields)) {
DEException.throwException(Translator.get("i18n_cst_ds_tb_or_field_deleted") + String.format(":table id [%s]", tableId));
}
String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldNameShort(tableId + "_" + f.getOriginName())).toArray(String[]::new); String[] array = fields.stream().map(f -> String.format(keyword, table) + "." + String.format(keyword, f.getOriginName()) + " AS " + DorisTableUtils.dorisFieldNameShort(tableId + "_" + f.getOriginName())).toArray(String[]::new);
checkedInfo.put(table, array); checkedInfo.put(table, array);
checkedFields.addAll(fields); checkedFields.addAll(fields);
......
...@@ -289,4 +289,5 @@ i18n_Exec=Running ...@@ -289,4 +289,5 @@ i18n_Exec=Running
i18n_no_trigger=The current setting does not trigger task generation. i18n_no_trigger=The current setting does not trigger task generation.
i18n_dataset_field_delete=Union field deleted,please set again and redo. i18n_dataset_field_delete=Union field deleted,please set again and redo.
i18n_es_limit=Elasticsearch version cannot be less than 6.3 i18n_es_limit=Elasticsearch version cannot be less than 6.3
i18n_ds_error=Preview fail:Execute SQL error。Cause field、table、dataset changed,please check i18n_ds_error=Preview fail:Execute SQL error。Cause field、table、dataset changed,please check
\ No newline at end of file i18n_union_ds_no_checked=This union dataset no checked field,please edit
\ No newline at end of file
...@@ -289,3 +289,4 @@ i18n_no_trigger=当前设置没有触发任务生成 ...@@ -289,3 +289,4 @@ i18n_no_trigger=当前设置没有触发任务生成
i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重新确认关联关系并重做该数据集 i18n_dataset_field_delete=该自定义数据集有关联字段被删除,请重新确认关联关系并重做该数据集
i18n_es_limit=Elasticsearch 版本不能小于6.3 i18n_es_limit=Elasticsearch 版本不能小于6.3
i18n_ds_error=预览数据错误:执行SQL失败。可能因相关字段、表、数据集等元素发生变更,请检查 i18n_ds_error=预览数据错误:执行SQL失败。可能因相关字段、表、数据集等元素发生变更,请检查
i18n_union_ds_no_checked=当前关联数据集,无选中字段,请重新编辑
...@@ -291,4 +291,5 @@ i18n_Exec=運行中 ...@@ -291,4 +291,5 @@ i18n_Exec=運行中
i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成. i18n_no_trigger=当前设置没有触发任务生成 當前設置沒有觸發任務生成.
i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集 i18n_dataset_field_delete=該自定義數據集有關聯字段被刪除,請重新確認關聯關系並重做該數據集
i18n_es_limit=Elasticsearch 版本不能小於6.3 i18n_es_limit=Elasticsearch 版本不能小於6.3
i18n_ds_error=預覽數據錯誤:執行SQL失敗。可能因相關字段、表、數據集等元素發生變更,請檢查 i18n_ds_error=預覽數據錯誤:執行SQL失敗。可能因相關字段、表、數據集等元素發生變更,請檢查
\ No newline at end of file i18n_union_ds_no_checked=當前關聯數據集,無選中字段,請重新編輯
\ No newline at end of file
...@@ -310,8 +310,8 @@ export default { ...@@ -310,8 +310,8 @@ export default {
} }
.union-container{ .union-container{
display: flex; display: flex;
width:100%; width: 100%;
height:400px; height: calc(100vh - 200px);
overflow: auto; overflow: auto;
} }
.form-item{ .form-item{
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论