mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
(improvement)(chat) The group by field can be added even if the group by field already exists (#192)
This commit is contained in:
@@ -17,6 +17,9 @@ public class EntityInfoExecuteResponder implements ExecuteResponder {
|
||||
|
||||
@Override
|
||||
public void fillResponse(QueryResult queryResult, SemanticParseInfo semanticParseInfo, ExecuteQueryReq queryReq) {
|
||||
if (semanticParseInfo == null || semanticParseInfo.getModelId() <= 0L) {
|
||||
return;
|
||||
}
|
||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||
User user = queryReq.getUser();
|
||||
queryResult.setEntityInfo(semanticService.getEntityInfo(semanticParseInfo, user));
|
||||
@@ -27,6 +30,9 @@ public class EntityInfoExecuteResponder implements ExecuteResponder {
|
||||
return;
|
||||
}
|
||||
String primaryEntityBizName = entityInfo.getModelInfo().getPrimaryEntityBizName();
|
||||
if (CollectionUtils.isEmpty(queryResult.getQueryColumns())) {
|
||||
return;
|
||||
}
|
||||
boolean existPrimaryEntityName = queryResult.getQueryColumns().stream()
|
||||
.anyMatch(queryColumn -> primaryEntityBizName.equals(queryColumn.getNameEn()));
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ public class SqlParserUpdateHelper {
|
||||
}
|
||||
|
||||
public static String addGroupBy(String sql, Set<String> groupByFields) {
|
||||
if (SqlParserSelectHelper.hasGroupBy(sql) || CollectionUtils.isEmpty(groupByFields)) {
|
||||
if (CollectionUtils.isEmpty(groupByFields)) {
|
||||
return sql;
|
||||
}
|
||||
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
||||
@@ -324,6 +324,10 @@ public class SqlParserUpdateHelper {
|
||||
|
||||
PlainSelect plainSelect = (PlainSelect) selectBody;
|
||||
GroupByElement groupByElement = new GroupByElement();
|
||||
List<String> originalGroupByFields = SqlParserSelectHelper.getGroupByFields(sql);
|
||||
if (!CollectionUtils.isEmpty(originalGroupByFields)) {
|
||||
groupByFields.addAll(originalGroupByFields);
|
||||
}
|
||||
for (String groupByField : groupByFields) {
|
||||
groupByElement.addGroupByExpression(new Column(groupByField));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user