From 11cdcb29fa7f83eaacae8ebb5a84e85df57b0a0f Mon Sep 17 00:00:00 2001 From: lexluo09 <39718951+lexluo09@users.noreply.github.com> Date: Thu, 16 Nov 2023 17:39:46 +0800 Subject: [PATCH] [improvement](chat) When determining the query type, S2SQL is uniformly used for parsing. (#393) --- .../supersonic/chat/parser/QueryTypeParser.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/chat/core/src/main/java/com/tencent/supersonic/chat/parser/QueryTypeParser.java b/chat/core/src/main/java/com/tencent/supersonic/chat/parser/QueryTypeParser.java index 42b27309a..bb62d8af0 100644 --- a/chat/core/src/main/java/com/tencent/supersonic/chat/parser/QueryTypeParser.java +++ b/chat/core/src/main/java/com/tencent/supersonic/chat/parser/QueryTypeParser.java @@ -58,12 +58,14 @@ public class QueryTypeParser implements SemanticParser { // get primaryEntityBizName SemanticService semanticService = ContextUtils.getBean(SemanticService.class); EntityInfo entityInfo = semanticService.getEntityInfo(parseInfo, user); - String primaryEntityBizName = semanticService.getPrimaryEntityBizName(entityInfo); - if (StringUtils.isNotEmpty(primaryEntityBizName)) { - //if exist primaryEntityBizName in parseInfo's dimensions, set nativeQuery to true - boolean existPrimaryEntityBizName = parseInfo.getDimensions().stream() - .anyMatch(schemaElement -> primaryEntityBizName.equalsIgnoreCase(schemaElement.getBizName())); - if (existPrimaryEntityBizName) { + if (Objects.nonNull(entityInfo) && Objects.nonNull(entityInfo.getModelInfo()) && StringUtils.isNotEmpty( + entityInfo.getModelInfo().getPrimaryEntityName())) { + String primaryEntityName = entityInfo.getModelInfo().getPrimaryEntityName(); + //if exist primaryEntityName in S2SQL select. + List selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getS2SQL()); + boolean existPrimaryEntityName = selectFields.stream() + .anyMatch(fieldName -> primaryEntityName.equalsIgnoreCase(fieldName)); + if (existPrimaryEntityName) { return QueryType.ENTITY; } }