mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
(improvement)(Headless) add tag query mode model (#806)
This commit is contained in:
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.api.pojo.response;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.ModelRela;
|
import com.tencent.supersonic.common.pojo.ModelRela;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.SchemaType;
|
import com.tencent.supersonic.headless.api.pojo.enums.SchemaType;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -27,6 +28,7 @@ public class SemanticSchemaResp {
|
|||||||
private List<ModelResp> modelResps = Lists.newArrayList();
|
private List<ModelResp> modelResps = Lists.newArrayList();
|
||||||
private DataSetResp dataSetResp;
|
private DataSetResp dataSetResp;
|
||||||
private DatabaseResp databaseResp;
|
private DatabaseResp databaseResp;
|
||||||
|
private QueryType queryType;
|
||||||
|
|
||||||
public String getSchemaKey() {
|
public String getSchemaKey() {
|
||||||
if (dataSetId == null) {
|
if (dataSetId == null) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.tencent.supersonic.common.pojo.Aggregator;
|
|||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
import com.tencent.supersonic.common.pojo.enums.ApiItemType;
|
import com.tencent.supersonic.common.pojo.enums.ApiItemType;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TaskStatusEnum;
|
import com.tencent.supersonic.common.pojo.enums.TaskStatusEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||||
@@ -51,18 +52,17 @@ import com.tencent.supersonic.headless.server.utils.QueryReqConverter;
|
|||||||
import com.tencent.supersonic.headless.server.utils.QueryUtils;
|
import com.tencent.supersonic.headless.server.utils.QueryUtils;
|
||||||
import com.tencent.supersonic.headless.server.utils.StatUtils;
|
import com.tencent.supersonic.headless.server.utils.StatUtils;
|
||||||
import com.tencent.supersonic.headless.server.utils.TagConverter;
|
import com.tencent.supersonic.headless.server.utils.TagConverter;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -147,8 +147,11 @@ public class QueryServiceImpl implements QueryService {
|
|||||||
queryStatement.setModelIds(querySqlReq.getModelIds());
|
queryStatement.setModelIds(querySqlReq.getModelIds());
|
||||||
queryStatement.setEnableOptimize(queryUtils.enableOptimize());
|
queryStatement.setEnableOptimize(queryUtils.enableOptimize());
|
||||||
queryStatement.setSemanticSchemaResp(semanticSchemaResp);
|
queryStatement.setSemanticSchemaResp(semanticSchemaResp);
|
||||||
SemanticModel semanticModel = semanticSchemaManager.getSemanticModel(semanticSchemaResp);
|
if (QueryType.TAG.equals(semanticSchemaResp.getQueryType())) {
|
||||||
queryStatement.setSemanticModel(semanticModel);
|
queryStatement.setSemanticModel(semanticSchemaManager.getTagSemanticModel(semanticSchemaResp));
|
||||||
|
} else {
|
||||||
|
queryStatement.setSemanticModel(semanticSchemaManager.getSemanticModel(semanticSchemaResp));
|
||||||
|
}
|
||||||
return queryStatement;
|
return queryStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +182,12 @@ public class QueryServiceImpl implements QueryService {
|
|||||||
queryStatement.setEnableOptimize(queryUtils.enableOptimize());
|
queryStatement.setEnableOptimize(queryUtils.enableOptimize());
|
||||||
queryStatement.setDataSetId(queryStructReq.getDataSetId());
|
queryStatement.setDataSetId(queryStructReq.getDataSetId());
|
||||||
queryStatement.setSemanticSchemaResp(semanticSchemaResp);
|
queryStatement.setSemanticSchemaResp(semanticSchemaResp);
|
||||||
SemanticModel semanticModel = semanticSchemaManager.getSemanticModel(semanticSchemaResp);
|
if (QueryType.TAG.equals(semanticSchemaResp.getQueryType())) {
|
||||||
queryStatement.setSemanticModel(semanticModel);
|
queryStatement = tagConverter.convert(queryStructReq, semanticSchemaResp);
|
||||||
|
queryStatement.setSemanticModel(semanticSchemaManager.getTagSemanticModel(semanticSchemaResp));
|
||||||
|
} else {
|
||||||
|
queryStatement.setSemanticModel(semanticSchemaManager.getSemanticModel(semanticSchemaResp));
|
||||||
|
}
|
||||||
return queryStatement;
|
return queryStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ public class SchemaServiceImpl implements SchemaService {
|
|||||||
semanticSchemaResp.setModelRelas(modelRelas);
|
semanticSchemaResp.setModelRelas(modelRelas);
|
||||||
semanticSchemaResp.setModelIds(modelIds);
|
semanticSchemaResp.setModelIds(modelIds);
|
||||||
semanticSchemaResp.setSchemaType(SchemaType.VIEW);
|
semanticSchemaResp.setSchemaType(SchemaType.VIEW);
|
||||||
|
semanticSchemaResp.setQueryType(dataSetSchemaResp.getQueryType());
|
||||||
} else if (!CollectionUtils.isEmpty(schemaFilterReq.getModelIds())) {
|
} else if (!CollectionUtils.isEmpty(schemaFilterReq.getModelIds())) {
|
||||||
List<ModelSchemaResp> modelSchemaResps = fetchModelSchemaResps(schemaFilterReq.getModelIds());
|
List<ModelSchemaResp> modelSchemaResps = fetchModelSchemaResps(schemaFilterReq.getModelIds());
|
||||||
semanticSchemaResp.setMetrics(modelSchemaResps.stream().map(ModelSchemaResp::getMetrics)
|
semanticSchemaResp.setMetrics(modelSchemaResps.stream().map(ModelSchemaResp::getMetrics)
|
||||||
@@ -318,9 +319,12 @@ public class SchemaServiceImpl implements SchemaService {
|
|||||||
.flatMap(Collection::stream).collect(Collectors.toList()));
|
.flatMap(Collection::stream).collect(Collectors.toList()));
|
||||||
semanticSchemaResp.setModelResps(modelSchemaResps.stream().map(this::convert).collect(Collectors.toList()));
|
semanticSchemaResp.setModelResps(modelSchemaResps.stream().map(this::convert).collect(Collectors.toList()));
|
||||||
semanticSchemaResp.setSchemaType(SchemaType.MODEL);
|
semanticSchemaResp.setSchemaType(SchemaType.MODEL);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!CollectionUtils.isEmpty(semanticSchemaResp.getModelIds())) {
|
||||||
// add tag info
|
// add tag info
|
||||||
TagFilter tagFilter = new TagFilter();
|
TagFilter tagFilter = new TagFilter();
|
||||||
tagFilter.setModelIds(schemaFilterReq.getModelIds());
|
tagFilter.setModelIds(semanticSchemaResp.getModelIds());
|
||||||
List<TagResp> tagResps = tagService.getTags(tagFilter);
|
List<TagResp> tagResps = tagService.getTags(tagFilter);
|
||||||
semanticSchemaResp.setTags(tagResps);
|
semanticSchemaResp.setTags(tagResps);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,16 +40,23 @@ public class TagConverter {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SqlGenerateUtils sqlGenerateUtils;
|
private SqlGenerateUtils sqlGenerateUtils;
|
||||||
|
|
||||||
public QueryStatement convert(QueryTagReq queryTagReq,
|
public QueryStatement convert(QueryStructReq queryStructReq,
|
||||||
SemanticSchemaResp semanticSchemaResp) throws Exception {
|
SemanticSchemaResp semanticSchemaResp) throws Exception {
|
||||||
QueryStatement queryStatement = new QueryStatement();
|
QueryStatement queryStatement = new QueryStatement();
|
||||||
// covert to QueryReqConverter
|
// covert to QueryReqConverter
|
||||||
QueryStructReq queryStructReq = new QueryStructReq();
|
BeanUtils.copyProperties(queryStructReq.convert(), queryStructReq);
|
||||||
BeanUtils.copyProperties(queryTagReq, queryStructReq);
|
|
||||||
if (!CollectionUtils.isEmpty(queryTagReq.getTagFilters())) {
|
|
||||||
queryStructReq.setDimensionFilters(queryTagReq.getTagFilters());
|
|
||||||
}
|
|
||||||
QuerySqlReq querySqlReq = queryStructReq.convert();
|
QuerySqlReq querySqlReq = queryStructReq.convert();
|
||||||
|
convert(querySqlReq, semanticSchemaResp, queryStatement, queryStructReq);
|
||||||
|
QueryParam queryParam = new QueryParam();
|
||||||
|
convert(queryStructReq, queryParam);
|
||||||
|
queryStatement.setQueryParam(queryParam);
|
||||||
|
queryStatement.setDataSetId(queryStructReq.getDataSetId());
|
||||||
|
return queryStatement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convert(QuerySqlReq querySqlReq,
|
||||||
|
SemanticSchemaResp semanticSchemaResp, QueryStatement queryStatement, QueryStructReq queryStructReq)
|
||||||
|
throws Exception {
|
||||||
if (Objects.nonNull(querySqlReq)) {
|
if (Objects.nonNull(querySqlReq)) {
|
||||||
log.info("convert to QuerySqlReq {}", querySqlReq);
|
log.info("convert to QuerySqlReq {}", querySqlReq);
|
||||||
String tableName = SqlSelectHelper.getTableName(querySqlReq.getSql());
|
String tableName = SqlSelectHelper.getTableName(querySqlReq.getSql());
|
||||||
@@ -77,15 +84,30 @@ public class TagConverter {
|
|||||||
queryStructReq.setDateInfo(queryStructUtils.getDateConfBySql(querySqlReq.getSql()));
|
queryStructReq.setDateInfo(queryStructUtils.getDateConfBySql(querySqlReq.getSql()));
|
||||||
queryStructReq.setDataSetId(querySqlReq.getDataSetId());
|
queryStructReq.setDataSetId(querySqlReq.getDataSetId());
|
||||||
queryStructReq.setQueryType(QueryType.TAG);
|
queryStructReq.setQueryType(QueryType.TAG);
|
||||||
QueryParam queryParam = new QueryParam();
|
|
||||||
convert(queryTagReq, queryParam);
|
|
||||||
queryStatement.setQueryParam(queryParam);
|
|
||||||
queryStatement.setDataSetQueryParam(result);
|
queryStatement.setDataSetQueryParam(result);
|
||||||
queryStatement.setIsS2SQL(true);
|
queryStatement.setIsS2SQL(true);
|
||||||
queryStatement.setMinMaxTime(queryStructUtils.getBeginEndTime(queryStructReq));
|
queryStatement.setMinMaxTime(queryStructUtils.getBeginEndTime(queryStructReq));
|
||||||
queryStatement.setDataSetId(queryTagReq.getDataSetId());
|
|
||||||
queryStatement.setEnableLimitWrapper(limitWrapper);
|
queryStatement.setEnableLimitWrapper(limitWrapper);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryStatement convert(QueryTagReq queryTagReq,
|
||||||
|
SemanticSchemaResp semanticSchemaResp) throws Exception {
|
||||||
|
QueryStatement queryStatement = new QueryStatement();
|
||||||
|
// covert to QueryReqConverter
|
||||||
|
QueryStructReq queryStructReq = new QueryStructReq();
|
||||||
|
BeanUtils.copyProperties(queryTagReq, queryStructReq);
|
||||||
|
if (!CollectionUtils.isEmpty(queryTagReq.getTagFilters())) {
|
||||||
|
queryStructReq.setDimensionFilters(queryTagReq.getTagFilters());
|
||||||
|
}
|
||||||
|
QuerySqlReq querySqlReq = queryStructReq.convert();
|
||||||
|
convert(querySqlReq, semanticSchemaResp, queryStatement, queryStructReq);
|
||||||
|
QueryParam queryParam = new QueryParam();
|
||||||
|
convert(queryTagReq, queryParam);
|
||||||
|
queryStatement.setQueryParam(queryParam);
|
||||||
|
queryStatement.setDataSetId(queryTagReq.getDataSetId());
|
||||||
return queryStatement;
|
return queryStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +120,15 @@ public class TagConverter {
|
|||||||
queryParam.setQueryType(QueryType.TAG);
|
queryParam.setQueryType(QueryType.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void convert(QueryStructReq queryTagReq, QueryParam queryParam) {
|
||||||
|
BeanUtils.copyProperties(queryTagReq, queryParam);
|
||||||
|
queryParam.setOrders(queryTagReq.getOrders());
|
||||||
|
queryParam.setMetrics(queryTagReq.getMetrics());
|
||||||
|
queryParam.setGroups(queryTagReq.getGroups());
|
||||||
|
queryParam.setDimensionFilters(queryTagReq.getDimensionFilters());
|
||||||
|
queryParam.setQueryType(QueryType.TAG);
|
||||||
|
}
|
||||||
|
|
||||||
public static List<TagResp> filterByDataSet(List<TagResp> tagResps, DataSetResp dataSetResp) {
|
public static List<TagResp> filterByDataSet(List<TagResp> tagResps, DataSetResp dataSetResp) {
|
||||||
return tagResps.stream().filter(tagResp -> dataSetResp.getAllTags().contains(tagResp.getId())
|
return tagResps.stream().filter(tagResp -> dataSetResp.getAllTags().contains(tagResp.getId())
|
||||||
|| dataSetResp.getAllIncludeAllModels().contains(tagResp.getModelId())).collect(Collectors.toList());
|
|| dataSetResp.getAllIncludeAllModels().contains(tagResp.getModelId())).collect(Collectors.toList());
|
||||||
|
|||||||
Reference in New Issue
Block a user