mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 02:46:56 +00:00
[fix][chat]Fix NPE in parse info persistence.
This commit is contained in:
@@ -14,6 +14,7 @@ public class PlainTextParser implements ChatQueryParser {
|
||||
|
||||
SemanticParseInfo parseInfo = new SemanticParseInfo();
|
||||
parseInfo.setQueryMode("PLAIN_TEXT");
|
||||
parseInfo.setId(1);
|
||||
parseContext.getResponse().getSelectedParses().add(parseInfo);
|
||||
parseContext.getResponse().setState(ParseResp.ParseState.COMPLETED);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,11 @@ public abstract class PluginRecognizer {
|
||||
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
||||
QueryNLReq queryNLReq = QueryReqConverter.buildQueryNLReq(parseContext);
|
||||
SchemaMapInfo schemaMapInfo = chatLayerService.map(queryNLReq).getMapInfo();
|
||||
int parseId = 1;
|
||||
for (Long dataSetId : dataSetIds) {
|
||||
SemanticParseInfo semanticParseInfo = buildSemanticParseInfo(dataSetId, plugin,
|
||||
parseContext, schemaMapInfo, pluginRecallResult.getDistance());
|
||||
semanticParseInfo.setId(parseId++);
|
||||
semanticParseInfo.setQueryMode(plugin.getType());
|
||||
semanticParseInfo.setScore(pluginRecallResult.getScore());
|
||||
parseResp.getSelectedParses().add(semanticParseInfo);
|
||||
|
||||
@@ -19,36 +19,38 @@ public class ParseInfoFormatProcessor implements ParseResultProcessor {
|
||||
@Override
|
||||
public void process(ParseContext parseContext) {
|
||||
parseContext.getResponse().getSelectedParses().forEach(p -> {
|
||||
if (!PluginQueryManager.isPluginQuery(p.getQueryMode())) {
|
||||
formatNL2SQLParseInfo(p);
|
||||
if (PluginQueryManager.isPluginQuery(p.getQueryMode())
|
||||
|| "PLAIN_TEXT".equals(p.getQueryMode())) {
|
||||
return;
|
||||
}
|
||||
|
||||
formatNL2SQLParseInfo(p);
|
||||
});
|
||||
}
|
||||
|
||||
private static void formatNL2SQLParseInfo(SemanticParseInfo parseInfo) {
|
||||
StringBuilder textBuilder = new StringBuilder();
|
||||
textBuilder.append("数据集: ").append(parseInfo.getDataSet().getName()).append(" ");
|
||||
textBuilder.append("**数据集:** ").append(parseInfo.getDataSet().getName()).append(" ");
|
||||
List<String> metricNames = parseInfo.getMetrics().stream().map(SchemaElement::getName)
|
||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(metricNames)) {
|
||||
textBuilder.append(" 指标: ").append(String.join(",", metricNames));
|
||||
textBuilder.append(" **指标:** ").append(String.join(",", metricNames));
|
||||
}
|
||||
List<String> dimensionNames = parseInfo.getDimensions().stream().map(SchemaElement::getName)
|
||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(dimensionNames)) {
|
||||
textBuilder.append(" 维度: ").append(String.join(",", dimensionNames));
|
||||
textBuilder.append(" **维度:** ").append(String.join(",", dimensionNames));
|
||||
}
|
||||
if (parseInfo.getDateInfo() != null) {
|
||||
textBuilder.append(" 数据时间: ").append(parseInfo.getDateInfo().getStartDate())
|
||||
textBuilder.append(" **数据时间:** ").append(parseInfo.getDateInfo().getStartDate())
|
||||
.append("~").append(parseInfo.getDateInfo().getEndDate()).append(" ");
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(parseInfo.getDimensionFilters())
|
||||
|| CollectionUtils.isEmpty(parseInfo.getMetricFilters())) {
|
||||
Set<QueryFilter> queryFilters = parseInfo.getDimensionFilters();
|
||||
queryFilters.addAll(parseInfo.getMetricFilters());
|
||||
if (!queryFilters.isEmpty()) {
|
||||
textBuilder.append(" 筛选条件: ");
|
||||
textBuilder.append(" **筛选条件:** ");
|
||||
}
|
||||
for (QueryFilter queryFilter : queryFilters) {
|
||||
textBuilder.append(queryFilter.getName()).append(" ")
|
||||
|
||||
Reference in New Issue
Block a user