mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
(improvement)(chat) fix count_distinct error in struct query and not init S2SqlByStruct if isUseS2SqlSwitch is false (#353)
This commit is contained in:
@@ -6,6 +6,7 @@ import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.SqlInfo;
|
||||
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||
import com.tencent.supersonic.chat.utils.QueryReqBuilder;
|
||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
@@ -40,7 +41,8 @@ public abstract class BaseSemanticQuery implements SemanticQuery, Serializable {
|
||||
ExplainSqlReq explainSqlReq = null;
|
||||
SqlInfo sqlInfo = parseInfo.getSqlInfo();
|
||||
try {
|
||||
QueryS2SQLReq queryS2SQLReq = QueryReqBuilder.buildS2SQLReq(sqlInfo.getCorrectS2SQL(), parseInfo.getModelId());
|
||||
QueryS2SQLReq queryS2SQLReq = QueryReqBuilder.buildS2SQLReq(sqlInfo.getCorrectS2SQL(),
|
||||
parseInfo.getModelId());
|
||||
explainSqlReq = ExplainSqlReq.builder()
|
||||
.queryTypeEnum(QueryTypeEnum.SQL)
|
||||
.queryReq(queryS2SQLReq)
|
||||
@@ -103,6 +105,10 @@ public abstract class BaseSemanticQuery implements SemanticQuery, Serializable {
|
||||
}
|
||||
|
||||
protected void initS2SqlByStruct() {
|
||||
OptimizationConfig optimizationConfig = ContextUtils.getBean(OptimizationConfig.class);
|
||||
if (!optimizationConfig.isUseS2SqlSwitch()) {
|
||||
return;
|
||||
}
|
||||
QueryStructReq queryStructReq = convertQueryStruct();
|
||||
convertBizNameToName(queryStructReq);
|
||||
QueryS2SQLReq queryS2SQLReq = queryStructReq.convert(queryStructReq);
|
||||
|
||||
@@ -38,6 +38,7 @@ public class QueryParser {
|
||||
if (semanticConverter.accept(queryStructReq)) {
|
||||
log.info("SemanticConverter accept [{}]", semanticConverter.getClass().getName());
|
||||
semanticConverter.converter(catalog, queryStructReq, parseSqlReq, metricReq);
|
||||
log.info("SemanticConverter accept [{}]", semanticConverter.getClass().getName());
|
||||
}
|
||||
}
|
||||
log.info("SemanticConverter after {} {} {}", queryStructReq, metricReq, parseSqlReq);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.semantic.query.utils;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.JOIN_UNDERLINE;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -54,6 +55,9 @@ public class SqlGenerateUtils {
|
||||
}
|
||||
|
||||
public String getSelectField(final Aggregator agg) {
|
||||
if (AggOperatorEnum.COUNT_DISTINCT.equals(agg.getFunc())) {
|
||||
return "count(distinct " + agg.getColumn() + " ) AS " + agg.getColumn() + " ";
|
||||
}
|
||||
if (CollectionUtils.isEmpty(agg.getArgs())) {
|
||||
return agg.getFunc() + "( " + agg.getColumn() + " ) AS " + agg.getColumn() + " ";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user