[fix][chat]Fix NPE in parse info persistence.

This commit is contained in:
jerryjzhang
2024-10-30 15:43:20 +08:00
parent 5c70607851
commit 621fefb4d4
3 changed files with 13 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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(" ")