提交 88d0b0f8 authored 作者: taojinlong's avatar taojinlong

fix: 校验增量更新sql

上级 9bffc6a2
......@@ -972,14 +972,15 @@ public class DataSetTableService {
DatasetTable datasetTable = datasetTableMapper.selectByPrimaryKey(datasetTableIncrementalConfig.getTableId());
List<DatasetTableField> datasetTableFields = dataSetTableFieldsService.getFieldsByTableId(datasetTable.getId());
datasetTableFields.sort((o1, o2) -> {
if (o1.getOriginName() == null) {
if (o1.getColumnIndex() == null) {
return -1;
}
if (o2.getOriginName() == null) {
if (o2.getColumnIndex() == null) {
return 1;
}
return o1.getOriginName().compareTo(o2.getOriginName());
return o1.getColumnIndex().compareTo(o2.getColumnIndex());
});
List<String> originNameFileds = datasetTableFields.stream().map(DatasetTableField::getOriginName).collect(Collectors.toList());
Datasource ds = datasourceMapper.selectByPrimaryKey(datasetTable.getDataSourceId());
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
......@@ -998,10 +999,7 @@ public class DataSetTableService {
}catch (Exception e){
DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage());
}
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
sqlFileds.add(filed);
});
sort(sqlFileds);
if (!originNameFileds.equals(sqlFileds)) {
DataEaseException.throwException(Translator.get("i18n_sql_add_not_matching") + sqlFileds.toString());
}
......@@ -1011,28 +1009,20 @@ public class DataSetTableService {
.replace(currentUpdateTime, Long.valueOf(System.currentTimeMillis()).toString());
datasourceRequest.setQuery(qp.wrapSql(sql));
List<String> sqlFileds = new ArrayList<>();
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
sqlFileds.add(filed);
});
sort(sqlFileds);
try{
datasourceProvider.fetchResultField(datasourceRequest).stream().map(TableFiled::getFieldName).forEach(filed -> {
sqlFileds.add(filed);
});
}catch (Exception e){
DataEaseException.throwException(Translator.get("i18n_check_sql_error") + e.getMessage());
}
if (!originNameFileds.equals(sqlFileds)) {
DataEaseException.throwException(Translator.get("i18n_sql_delete_not_matching") + sqlFileds.toString());
}
}
}
private void sort(List<String> sqlFileds) {
sqlFileds.sort((o1, o2) -> {
if (o1 == null) {
return -1;
}
if (o2 == null) {
return 1;
}
return o1.compareTo(o2);
});
}
private void checkName(DatasetTable datasetTable) {
// if (StringUtils.isEmpty(datasetTable.getId()) && StringUtils.equalsIgnoreCase("db", datasetTable.getType())) {
// return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论