forked from github/dataease
fix: 校验增量更新sql
This commit is contained in:
parent
4b5d272f63
commit
6261dff6cc
@ -986,14 +986,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());
|
||||
@ -1012,10 +1013,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());
|
||||
}
|
||||
@ -1025,28 +1023,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;
|
||||
|
Loading…
Reference in New Issue
Block a user