mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(improvement)(chat) if there is no group by in dsl,set MetricTable's aggOption to NATIVE (#195)
This commit is contained in:
@@ -22,9 +22,9 @@ public class EntityInfoExecuteResponder implements ExecuteResponder {
|
|||||||
}
|
}
|
||||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
User user = queryReq.getUser();
|
User user = queryReq.getUser();
|
||||||
queryResult.setEntityInfo(semanticService.getEntityInfo(semanticParseInfo, user));
|
EntityInfo entityInfo = semanticService.getEntityInfo(semanticParseInfo, user);
|
||||||
|
queryResult.setEntityInfo(entityInfo);
|
||||||
|
|
||||||
EntityInfo entityInfo = semanticService.getEntityInfo(semanticParseInfo.getModelId());
|
|
||||||
if (Objects.isNull(entityInfo) || Objects.isNull(entityInfo.getModelInfo())
|
if (Objects.isNull(entityInfo) || Objects.isNull(entityInfo.getModelInfo())
|
||||||
|| Objects.isNull(entityInfo.getModelInfo().getPrimaryEntityName())) {
|
|| Objects.isNull(entityInfo.getModelInfo().getPrimaryEntityName())) {
|
||||||
return;
|
return;
|
||||||
@@ -36,6 +36,8 @@ public class EntityInfoExecuteResponder implements ExecuteResponder {
|
|||||||
boolean existPrimaryEntityName = queryResult.getQueryColumns().stream()
|
boolean existPrimaryEntityName = queryResult.getQueryColumns().stream()
|
||||||
.anyMatch(queryColumn -> primaryEntityBizName.equals(queryColumn.getNameEn()));
|
.anyMatch(queryColumn -> primaryEntityBizName.equals(queryColumn.getNameEn()));
|
||||||
|
|
||||||
|
semanticParseInfo.setNativeQuery(existPrimaryEntityName);
|
||||||
|
|
||||||
if (!existPrimaryEntityName) {
|
if (!existPrimaryEntityName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
|||||||
import com.tencent.supersonic.semantic.api.model.request.SqlExecuteReq;
|
import com.tencent.supersonic.semantic.api.model.request.SqlExecuteReq;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||||
|
import com.tencent.supersonic.semantic.api.query.enums.AggOption;
|
||||||
import com.tencent.supersonic.semantic.api.query.pojo.MetricTable;
|
import com.tencent.supersonic.semantic.api.query.pojo.MetricTable;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.ParseSqlReq;
|
import com.tencent.supersonic.semantic.api.query.request.ParseSqlReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryDslReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryDslReq;
|
||||||
@@ -49,10 +50,6 @@ public class QueryReqConverter {
|
|||||||
private Catalog catalog;
|
private Catalog catalog;
|
||||||
|
|
||||||
public QueryStatement convert(QueryDslReq databaseReq, ModelSchemaResp modelSchemaResp) throws Exception {
|
public QueryStatement convert(QueryDslReq databaseReq, ModelSchemaResp modelSchemaResp) throws Exception {
|
||||||
|
|
||||||
List<MetricTable> tables = new ArrayList<>();
|
|
||||||
MetricTable metricTable = new MetricTable();
|
|
||||||
|
|
||||||
if (Objects.isNull(modelSchemaResp)) {
|
if (Objects.isNull(modelSchemaResp)) {
|
||||||
return new QueryStatement();
|
return new QueryStatement();
|
||||||
}
|
}
|
||||||
@@ -64,14 +61,13 @@ public class QueryReqConverter {
|
|||||||
correctTableName(databaseReq);
|
correctTableName(databaseReq);
|
||||||
|
|
||||||
String tableName = SqlParserSelectHelper.getTableName(databaseReq.getSql());
|
String tableName = SqlParserSelectHelper.getTableName(databaseReq.getSql());
|
||||||
|
|
||||||
if (StringUtils.isEmpty(tableName)) {
|
if (StringUtils.isEmpty(tableName)) {
|
||||||
return new QueryStatement();
|
return new QueryStatement();
|
||||||
}
|
}
|
||||||
|
//4.build MetricTables
|
||||||
List<String> allFields = SqlParserSelectHelper.getAllFields(databaseReq.getSql());
|
List<String> allFields = SqlParserSelectHelper.getAllFields(databaseReq.getSql());
|
||||||
|
|
||||||
List<String> metrics = getMetrics(modelSchemaResp, allFields);
|
List<String> metrics = getMetrics(modelSchemaResp, allFields);
|
||||||
|
MetricTable metricTable = new MetricTable();
|
||||||
metricTable.setMetrics(metrics);
|
metricTable.setMetrics(metrics);
|
||||||
|
|
||||||
Set<String> dimensions = getDimensions(modelSchemaResp, allFields);
|
Set<String> dimensions = getDimensions(modelSchemaResp, allFields);
|
||||||
@@ -85,8 +81,13 @@ public class QueryReqConverter {
|
|||||||
queryStructUtils.generateInternalMetricName(databaseReq.getModelId(),
|
queryStructUtils.generateInternalMetricName(databaseReq.getModelId(),
|
||||||
metricTable.getDimensions()))));
|
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);
|
||||||
|
}
|
||||||
|
List<MetricTable> tables = new ArrayList<>();
|
||||||
tables.add(metricTable);
|
tables.add(metricTable);
|
||||||
|
//4.build ParseSqlReq
|
||||||
ParseSqlReq result = new ParseSqlReq();
|
ParseSqlReq result = new ParseSqlReq();
|
||||||
BeanUtils.copyProperties(databaseReq, result);
|
BeanUtils.copyProperties(databaseReq, result);
|
||||||
result.setRootPath(domainService.getModelFullPathMap().get(databaseReq.getModelId()));
|
result.setRootPath(domainService.getModelFullPathMap().get(databaseReq.getModelId()));
|
||||||
@@ -97,7 +98,7 @@ public class QueryReqConverter {
|
|||||||
result.setSupportWith(false);
|
result.setSupportWith(false);
|
||||||
result.setWithAlias(false);
|
result.setWithAlias(false);
|
||||||
}
|
}
|
||||||
|
//5.physicalSql by ParseSqlReq
|
||||||
QueryStatement queryStatement = parserService.physicalSql(result);
|
QueryStatement queryStatement = parserService.physicalSql(result);
|
||||||
queryStatement.setSql(String.format(SqlExecuteReq.LIMIT_WRAPPER, queryStatement.getSql()));
|
queryStatement.setSql(String.format(SqlExecuteReq.LIMIT_WRAPPER, queryStatement.getSql()));
|
||||||
return queryStatement;
|
return queryStatement;
|
||||||
|
|||||||
Reference in New Issue
Block a user