mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-05-08 11:14:19 +08:00
feat(dataset): 实现数据集模型配置中的全量维度指标扩展功能
- 实现 expandIncludesAllModels 方法处理全量维度指标映射 - 根据模型ID分组收集维度和指标并合并到配置中 - 将 includesAll 标志重置为 false 避免重复扩展 - 确保在线状态的维度和指标被正确包含到数据集中
This commit is contained in:
@@ -13,6 +13,7 @@ import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
|||||||
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||||
import com.tencent.supersonic.common.util.BeanMapper;
|
import com.tencent.supersonic.common.util.BeanMapper;
|
||||||
import com.tencent.supersonic.headless.api.pojo.DataSetDetail;
|
import com.tencent.supersonic.headless.api.pojo.DataSetDetail;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.DataSetModelConfig;
|
||||||
import com.tencent.supersonic.headless.api.pojo.MetaFilter;
|
import com.tencent.supersonic.headless.api.pojo.MetaFilter;
|
||||||
import com.tencent.supersonic.headless.api.pojo.QueryConfig;
|
import com.tencent.supersonic.headless.api.pojo.QueryConfig;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.*;
|
import com.tencent.supersonic.headless.api.pojo.request.*;
|
||||||
@@ -52,6 +53,9 @@ public class DataSetServiceImpl extends ServiceImpl<DataSetDOMapper, DataSetDO>
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MetricService metricService;
|
private MetricService metricService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ModelService modelService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSetResp save(DataSetReq dataSetReq, User user) {
|
public DataSetResp save(DataSetReq dataSetReq, User user) {
|
||||||
dataSetReq.createdBy(user.getName());
|
dataSetReq.createdBy(user.getName());
|
||||||
@@ -77,7 +81,13 @@ public class DataSetServiceImpl extends ServiceImpl<DataSetDOMapper, DataSetDO>
|
|||||||
@Override
|
@Override
|
||||||
public DataSetResp getDataSet(Long id) {
|
public DataSetResp getDataSet(Long id) {
|
||||||
DataSetDO dataSetDO = getById(id);
|
DataSetDO dataSetDO = getById(id);
|
||||||
return convert(dataSetDO);
|
DataSetResp dataSetResp = convert(dataSetDO);
|
||||||
|
|
||||||
|
if (dataSetResp.getDataSetDetail() != null) {
|
||||||
|
expandIncludesAllModels(dataSetResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataSetResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -273,6 +283,59 @@ public class DataSetServiceImpl extends ServiceImpl<DataSetDOMapper, DataSetDO>
|
|||||||
.map(Object::toString).collect(Collectors.toList());
|
.map(Object::toString).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void expandIncludesAllModels(DataSetResp dataSetResp) {
|
||||||
|
List<DataSetModelConfig> configs = dataSetResp.getDataSetDetail().getDataSetModelConfigs();
|
||||||
|
if (CollectionUtils.isEmpty(configs)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Long> includeAllModelIds = configs.stream()
|
||||||
|
.filter(DataSetModelConfig::getIncludesAll)
|
||||||
|
.map(DataSetModelConfig::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(includeAllModelIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MetaFilter metaFilter = new MetaFilter();
|
||||||
|
metaFilter.setModelIds(new ArrayList<>(includeAllModelIds));
|
||||||
|
metaFilter.setStatus(StatusEnum.ONLINE.getCode());
|
||||||
|
|
||||||
|
List<DimensionResp> allDimensions = dimensionService.getDimensions(metaFilter);
|
||||||
|
List<MetricResp> allMetrics = metricService.getMetrics(metaFilter);
|
||||||
|
|
||||||
|
Map<Long, List<Long>> modelDimensionMap = allDimensions.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
DimensionResp::getModelId,
|
||||||
|
Collectors.mapping(DimensionResp::getId, Collectors.toList())
|
||||||
|
));
|
||||||
|
|
||||||
|
Map<Long, List<Long>> modelMetricMap = allMetrics.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
MetricResp::getModelId,
|
||||||
|
Collectors.mapping(MetricResp::getId, Collectors.toList())
|
||||||
|
));
|
||||||
|
|
||||||
|
for (DataSetModelConfig config : configs) {
|
||||||
|
if (Boolean.TRUE.equals(config.getIncludesAll())) {
|
||||||
|
Long modelId = config.getId();
|
||||||
|
|
||||||
|
List<Long> modelDimensions = modelDimensionMap.getOrDefault(modelId, Lists.newArrayList());
|
||||||
|
Set<Long> existingDimensions = new HashSet<>(config.getDimensions());
|
||||||
|
existingDimensions.addAll(modelDimensions);
|
||||||
|
config.setDimensions(new ArrayList<>(existingDimensions));
|
||||||
|
|
||||||
|
List<Long> modelMetrics = modelMetricMap.getOrDefault(modelId, Lists.newArrayList());
|
||||||
|
Set<Long> existingMetrics = new HashSet<>(config.getMetrics());
|
||||||
|
existingMetrics.addAll(modelMetrics);
|
||||||
|
config.setMetrics(new ArrayList<>(existingMetrics));
|
||||||
|
|
||||||
|
config.setIncludesAll(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Long getDataSetIdFromSql(String sql, User user) {
|
public Long getDataSetIdFromSql(String sql, User user) {
|
||||||
List<DataSetResp> dataSets = null;
|
List<DataSetResp> dataSets = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user