mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-15 06:27:21 +00:00
(improvment)(chat) if exist count() in dsl,set query to NATIVE and only order by field and group by field can add to select (#206)
This commit is contained in:
@@ -2,6 +2,7 @@ package com.tencent.supersonic.semantic.query.parser.convert;
|
||||
|
||||
import com.tencent.supersonic.common.util.DateUtils;
|
||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserReplaceHelper;
|
||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||
import com.tencent.supersonic.semantic.api.model.enums.TimeDimensionEnum;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
||||
@@ -81,10 +82,7 @@ public class QueryReqConverter {
|
||||
queryStructUtils.generateInternalMetricName(databaseReq.getModelId(),
|
||||
metricTable.getDimensions()))));
|
||||
}
|
||||
// if there is no group by in dsl,set MetricTable's aggOption to "NATIVE"
|
||||
if (!SqlParserSelectHelper.hasGroupBy(databaseReq.getSql())) {
|
||||
metricTable.setAggOption(AggOption.NATIVE);
|
||||
}
|
||||
metricTable.setAggOption(getAggOption(databaseReq));
|
||||
List<MetricTable> tables = new ArrayList<>();
|
||||
tables.add(metricTable);
|
||||
//4.build ParseSqlReq
|
||||
@@ -104,6 +102,17 @@ public class QueryReqConverter {
|
||||
return queryStatement;
|
||||
}
|
||||
|
||||
private AggOption getAggOption(QueryDslReq databaseReq) {
|
||||
// if there is no group by in dsl,set MetricTable's aggOption to "NATIVE"
|
||||
// if there is count() in dsl,set MetricTable's aggOption to "NATIVE"
|
||||
String sql = databaseReq.getSql();
|
||||
if (!SqlParserSelectHelper.hasGroupBy(sql)
|
||||
|| SqlParserSelectFunctionHelper.hasFunction(sql, "count")) {
|
||||
return AggOption.NATIVE;
|
||||
}
|
||||
return AggOption.DEFAULT;
|
||||
}
|
||||
|
||||
private void convertNameToBizName(QueryDslReq databaseReq, ModelSchemaResp modelSchemaResp) {
|
||||
Map<String, String> fieldNameToBizNameMap = getFieldNameToBizNameMap(modelSchemaResp);
|
||||
String sql = databaseReq.getSql();
|
||||
|
||||
@@ -61,8 +61,7 @@ public class QueryController {
|
||||
|
||||
@PostMapping("/queryStatement")
|
||||
public Object queryStatement(@RequestBody QueryStatement queryStatement) throws Exception {
|
||||
Object result = queryService.queryByQueryStatement(queryStatement);
|
||||
return result;
|
||||
return queryService.queryByQueryStatement(queryStatement);
|
||||
}
|
||||
|
||||
@PostMapping("/struct/parse")
|
||||
|
||||
@@ -89,8 +89,7 @@ public class QueryServiceImpl implements QueryService {
|
||||
}
|
||||
|
||||
public Object queryByQueryStatement(QueryStatement queryStatement) {
|
||||
QueryResultWithSchemaResp results = semanticQueryEngine.execute(queryStatement);
|
||||
return results;
|
||||
return semanticQueryEngine.execute(queryStatement);
|
||||
}
|
||||
|
||||
private QueryStatement convertToQueryStatement(QueryDslReq querySqlCmd, User user) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user