mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-01-02 15:28:42 +08:00
[improvement][headless&chat]Move EntityInfoProcessor from chat to headless module and optimize code.
[improvement][headless&chat]Move `EntityInfoProcessor` from `chat` to `headless` module and optimize code.
This commit is contained in:
@@ -5,5 +5,4 @@ package com.tencent.supersonic.chat.server.processor;
|
||||
*/
|
||||
public interface ResultProcessor {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import com.tencent.supersonic.chat.server.processor.ResultProcessor;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||
|
||||
/**
|
||||
* A ExecuteResultProcessor wraps things up before returning results to users in execute stage.
|
||||
* A ExecuteResultProcessor wraps things up before returning
|
||||
* execution results to the users.
|
||||
*/
|
||||
public interface ExecuteResultProcessor extends ResultProcessor {
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.tencent.supersonic.chat.server.processor.parse;
|
||||
|
||||
import com.tencent.supersonic.chat.server.pojo.ParseContext;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.EntityInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.headless.chat.query.QueryManager;
|
||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EntityInfoProcessor fills core attributes of an entity so that
|
||||
* users get to know which entity is parsed out.
|
||||
*/
|
||||
public class EntityInfoProcessor implements ParseResultProcessor {
|
||||
|
||||
@Override
|
||||
public void process(ParseContext parseContext, ParseResp parseResp) {
|
||||
List<SemanticParseInfo> selectedParses = parseResp.getSelectedParses();
|
||||
if (CollectionUtils.isEmpty(selectedParses)) {
|
||||
return;
|
||||
}
|
||||
selectedParses.forEach(parseInfo -> {
|
||||
String queryMode = parseInfo.getQueryMode();
|
||||
if (QueryManager.containsRuleQuery(queryMode) || "PLAIN".equals(queryMode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//1. set entity info
|
||||
SemanticLayerService semanticService = ContextUtils.getBean(SemanticLayerService.class);
|
||||
DataSetSchema dataSetSchema = semanticService.getDataSetSchema(parseInfo.getDataSetId());
|
||||
EntityInfo entityInfo = semanticService.getEntityInfo(parseInfo, dataSetSchema, parseContext.getUser());
|
||||
if (QueryManager.isTagQuery(queryMode)
|
||||
|| QueryManager.isMetricQuery(queryMode)) {
|
||||
parseInfo.setEntityInfo(entityInfo);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.tencent.supersonic.chat.server.processor.parse;
|
||||
|
||||
import com.tencent.supersonic.chat.server.pojo.ParseContext;
|
||||
import com.tencent.supersonic.chat.server.processor.ResultProcessor;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
|
||||
public interface ParseResultProcessor {
|
||||
/**
|
||||
* A ParseResultProcessor wraps things up before returning
|
||||
* parsing results to the users.
|
||||
*/
|
||||
public interface ParseResultProcessor extends ResultProcessor {
|
||||
|
||||
void process(ParseContext parseContext, ParseResp parseResp);
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
||||
if (Objects.nonNull(parseInfo.getSqlInfo())
|
||||
&& StringUtils.isNotBlank(parseInfo.getSqlInfo().getCorrectedS2SQL())) {
|
||||
String correctorSql = parseInfo.getSqlInfo().getCorrectedS2SQL();
|
||||
fields = SqlSelectHelper.getAllFields(correctorSql);
|
||||
fields = SqlSelectHelper.getAllSelectFields(correctorSql);
|
||||
}
|
||||
if (LLMSqlQuery.QUERY_MODE.equalsIgnoreCase(parseInfo.getQueryMode())
|
||||
&& checkMetricReplace(fields, chatQueryDataReq.getMetrics())) {
|
||||
|
||||
Reference in New Issue
Block a user