mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvement)(chat) Replace the table name in correct sql with a string concatenated by the model name in FromCorrector (#566)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -13,7 +13,9 @@ public class FromCorrector extends BaseSemanticCorrector {
|
|||||||
@Override
|
@Override
|
||||||
public void doCorrect(QueryReq queryReq, SemanticParseInfo semanticParseInfo) {
|
public void doCorrect(QueryReq queryReq, SemanticParseInfo semanticParseInfo) {
|
||||||
String modelName = semanticParseInfo.getModel().getName();
|
String modelName = semanticParseInfo.getModel().getName();
|
||||||
SqlParserReplaceHelper.replaceTable(semanticParseInfo.getSqlInfo().getCorrectS2SQL(), modelName);
|
String correctSql = SqlParserReplaceHelper
|
||||||
|
.replaceTable(semanticParseInfo.getSqlInfo().getCorrectS2SQL(), modelName);
|
||||||
|
semanticParseInfo.getSqlInfo().setCorrectS2SQL(correctSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ public class Item {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private String bizName;
|
||||||
|
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
private ApiItemType type;
|
private ApiItemType type;
|
||||||
|
|
||||||
private List<Item> relateItems = Lists.newArrayList();
|
private List<Item> relateItems = Lists.newArrayList();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -138,14 +139,18 @@ public class AppServiceImpl extends ServiceImpl<AppMapper, AppDO> implements App
|
|||||||
@Override
|
@Override
|
||||||
public AppDetailResp getApp(Integer id, User user) {
|
public AppDetailResp getApp(Integer id, User user) {
|
||||||
AppDO appDO = getAppDO(id);
|
AppDO appDO = getAppDO(id);
|
||||||
|
Map<Long, MetricResp> metricResps = metricService.getMetrics(new MetaFilter())
|
||||||
|
.stream().collect(Collectors.toMap(MetricResp::getId, m -> m));
|
||||||
|
Map<Long, DimensionResp> dimensionResps = dimensionService.getDimensions(new MetaFilter())
|
||||||
|
.stream().collect(Collectors.toMap(DimensionResp::getId, m -> m));
|
||||||
checkAuth(appDO, user);
|
checkAuth(appDO, user);
|
||||||
return convertDetail(appDO);
|
return convertDetail(appDO, dimensionResps, metricResps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AppDetailResp getApp(Integer id) {
|
public AppDetailResp getApp(Integer id) {
|
||||||
AppDO appDO = getAppDO(id);
|
AppDO appDO = getAppDO(id);
|
||||||
return convertDetail(appDO);
|
return convertDetail(appDO, new HashMap<>(), new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppDO getAppDO(Integer id) {
|
private AppDO getAppDO(Integer id) {
|
||||||
@@ -175,12 +180,7 @@ public class AppServiceImpl extends ServiceImpl<AppMapper, AppDO> implements App
|
|||||||
AppResp app = new AppResp();
|
AppResp app = new AppResp();
|
||||||
BeanMapper.mapper(appDO, app);
|
BeanMapper.mapper(appDO, app);
|
||||||
AppConfig appConfig = JSONObject.parseObject(appDO.getConfig(), AppConfig.class);
|
AppConfig appConfig = JSONObject.parseObject(appDO.getConfig(), AppConfig.class);
|
||||||
appConfig.getItems().forEach(metricItem -> {
|
fillItemName(appConfig, dimensionMap, metricMap);
|
||||||
metricItem.setName(metricMap.getOrDefault(metricItem.getId(), new MetricResp()).getName());
|
|
||||||
metricItem.getRelateItems().forEach(dimensionItem -> {
|
|
||||||
dimensionItem.setName(dimensionMap.getOrDefault(dimensionItem.getId(), new DimensionResp()).getName());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
app.setConfig(appConfig);
|
app.setConfig(appConfig);
|
||||||
app.setAppStatus(AppStatusEnum.fromCode(appDO.getStatus()));
|
app.setAppStatus(AppStatusEnum.fromCode(appDO.getStatus()));
|
||||||
app.setHasAdminRes(hasAuth(appDO, user));
|
app.setHasAdminRes(hasAuth(appDO, user));
|
||||||
@@ -188,13 +188,36 @@ public class AppServiceImpl extends ServiceImpl<AppMapper, AppDO> implements App
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AppDetailResp convertDetail(AppDO appDO) {
|
private AppDetailResp convertDetail(AppDO appDO) {
|
||||||
|
return convertDetail(appDO, new HashMap<>(), new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private AppDetailResp convertDetail(AppDO appDO, Map<Long, DimensionResp> dimensionMap,
|
||||||
|
Map<Long, MetricResp> metricMap) {
|
||||||
AppDetailResp app = new AppDetailResp();
|
AppDetailResp app = new AppDetailResp();
|
||||||
BeanMapper.mapper(appDO, app);
|
BeanMapper.mapper(appDO, app);
|
||||||
app.setConfig(JSONObject.parseObject(appDO.getConfig(), AppConfig.class));
|
AppConfig appConfig = JSONObject.parseObject(appDO.getConfig(), AppConfig.class);
|
||||||
|
fillItemName(appConfig, dimensionMap, metricMap);
|
||||||
|
app.setConfig(appConfig);
|
||||||
app.setAppStatus(AppStatusEnum.fromCode(appDO.getStatus()));
|
app.setAppStatus(AppStatusEnum.fromCode(appDO.getStatus()));
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void fillItemName(AppConfig appConfig, Map<Long, DimensionResp> dimensionMap,
|
||||||
|
Map<Long, MetricResp> metricMap) {
|
||||||
|
appConfig.getItems().forEach(metricItem -> {
|
||||||
|
metricItem.setName(metricMap.getOrDefault(metricItem.getId(), new MetricResp()).getName());
|
||||||
|
metricItem.setBizName(metricMap.getOrDefault(metricItem.getId(), new MetricResp()).getBizName());
|
||||||
|
metricItem.setCreatedBy(metricMap.getOrDefault(metricItem.getId(), new MetricResp()).getCreatedBy());
|
||||||
|
metricItem.getRelateItems().forEach(dimensionItem -> {
|
||||||
|
dimensionItem.setName(dimensionMap.getOrDefault(dimensionItem.getId(), new DimensionResp()).getName());
|
||||||
|
dimensionItem.setBizName(dimensionMap.getOrDefault(dimensionItem.getId(),
|
||||||
|
new DimensionResp()).getBizName());
|
||||||
|
dimensionItem.setCreatedBy(dimensionMap.getOrDefault(dimensionItem.getId(),
|
||||||
|
new DimensionResp()).getCreatedBy());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private String getUniqueId() {
|
private String getUniqueId() {
|
||||||
return UUID.randomUUID().toString().replaceAll("_", "");
|
return UUID.randomUUID().toString().replaceAll("_", "");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user