mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-15 06:27:21 +00:00
(improvement)(Headless) Abstracted tags from dimensions and metrics. (#828)
This commit is contained in:
@@ -146,11 +146,7 @@ public class QueryServiceImpl implements QueryService {
|
||||
queryStatement.setModelIds(querySqlReq.getModelIds());
|
||||
queryStatement.setEnableOptimize(queryUtils.enableOptimize());
|
||||
queryStatement.setSemanticSchemaResp(semanticSchemaResp);
|
||||
if (QueryType.TAG.equals(semanticSchemaResp.getQueryType())) {
|
||||
queryStatement.setSemanticModel(semanticSchemaManager.getTagSemanticModel(semanticSchemaResp));
|
||||
} else {
|
||||
queryStatement.setSemanticModel(semanticSchemaManager.getSemanticModel(semanticSchemaResp));
|
||||
}
|
||||
queryStatement.setSemanticModel(semanticSchemaManager.getSemanticModel(semanticSchemaResp));
|
||||
return queryStatement;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,6 @@ public class TagMetaServiceImpl implements TagMetaService {
|
||||
|
||||
@Override
|
||||
public TagResp getTag(Long id, User user) {
|
||||
// return convert(tagRepository.getTagById(id));
|
||||
TagDO tagDO = tagRepository.getTagById(id);
|
||||
TagResp tagResp = fillCollectAndAdminInfo(tagDO, user);
|
||||
tagResp = fillModelInfo(tagResp);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class TagQueryServiceImpl implements TagQueryService {
|
||||
public ItemValueResp queryTagValue(ItemValueReq itemValueReq, User user) throws Exception {
|
||||
ItemValueResp itemValueResp = new ItemValueResp();
|
||||
itemValueResp.setItemId(itemValueReq.getItemId());
|
||||
itemValueResp.setType(SchemaElementType.TAG);
|
||||
itemValueResp.setType(SchemaElementType.DIMENSION);
|
||||
TagResp tag = tagMetaService.getTag(itemValueReq.getItemId(), user);
|
||||
checkTag(tag);
|
||||
itemValueResp.setName(tag.getName());
|
||||
|
||||
@@ -34,7 +34,6 @@ public class WordService {
|
||||
addWordsByType(DictWordType.METRIC, semanticSchema.getMetrics(), words);
|
||||
addWordsByType(DictWordType.ENTITY, semanticSchema.getEntities(), words);
|
||||
addWordsByType(DictWordType.VALUE, semanticSchema.getDimensionValues(), words);
|
||||
addWordsByType(DictWordType.TAG, semanticSchema.getTags(), words);
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,6 @@ import com.tencent.supersonic.headless.api.pojo.SchemaValueMap;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DataSetSchemaResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DimSchemaResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.MetricSchemaResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.TagResp;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -24,6 +19,9 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
public class DataSetSchemaBuilder {
|
||||
|
||||
@@ -43,18 +41,18 @@ public class DataSetSchemaBuilder {
|
||||
Set<SchemaElement> metrics = getMetrics(resp);
|
||||
dataSetSchema.getMetrics().addAll(metrics);
|
||||
|
||||
Set<SchemaElement> metricTags = getMetricTags(resp);
|
||||
dataSetSchema.getTags().addAll(metricTags);
|
||||
|
||||
Set<SchemaElement> dimensions = getDimensions(resp);
|
||||
dataSetSchema.getDimensions().addAll(dimensions);
|
||||
|
||||
Set<SchemaElement> dimensionTags = getDimensionTags(resp);
|
||||
dataSetSchema.getTags().addAll(dimensionTags);
|
||||
|
||||
Set<SchemaElement> dimensionValues = getDimensionValues(resp);
|
||||
dataSetSchema.getDimensionValues().addAll(dimensionValues);
|
||||
|
||||
Set<SchemaElement> tags = getTags(resp);
|
||||
dataSetSchema.getTags().addAll(tags);
|
||||
|
||||
Set<SchemaElement> tagValues = getTagValues(resp);
|
||||
dataSetSchema.getTagValues().addAll(tagValues);
|
||||
|
||||
SchemaElement entity = getEntity(resp);
|
||||
if (Objects.nonNull(entity)) {
|
||||
dataSetSchema.setEntity(entity);
|
||||
@@ -62,6 +60,58 @@ public class DataSetSchemaBuilder {
|
||||
return dataSetSchema;
|
||||
}
|
||||
|
||||
private static Set<SchemaElement> getMetricTags(DataSetSchemaResp resp) {
|
||||
Set<SchemaElement> tags = new HashSet<>();
|
||||
for (MetricSchemaResp metric : resp.getMetrics()) {
|
||||
List<String> alias = SchemaItem.getAliasList(metric.getAlias());
|
||||
if (metric.getIsTag() == 1) {
|
||||
SchemaElement tagToAdd = SchemaElement.builder()
|
||||
.dataSet(resp.getId())
|
||||
.model(metric.getModelId())
|
||||
.id(metric.getId())
|
||||
.name(metric.getName())
|
||||
.bizName(metric.getBizName())
|
||||
.type(SchemaElementType.TAG)
|
||||
.useCnt(metric.getUseCnt())
|
||||
.alias(alias)
|
||||
.build();
|
||||
tags.add(tagToAdd);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
private static Set<SchemaElement> getDimensionTags(DataSetSchemaResp resp) {
|
||||
Set<SchemaElement> tags = new HashSet<>();
|
||||
for (DimSchemaResp dim : resp.getDimensions()) {
|
||||
List<String> alias = SchemaItem.getAliasList(dim.getAlias());
|
||||
List<DimValueMap> dimValueMaps = dim.getDimValueMaps();
|
||||
List<SchemaValueMap> schemaValueMaps = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(dimValueMaps)) {
|
||||
for (DimValueMap dimValueMap : dimValueMaps) {
|
||||
SchemaValueMap schemaValueMap = new SchemaValueMap();
|
||||
BeanUtils.copyProperties(dimValueMap, schemaValueMap);
|
||||
schemaValueMaps.add(schemaValueMap);
|
||||
}
|
||||
}
|
||||
if (dim.getIsTag() == 1) {
|
||||
SchemaElement tagToAdd = SchemaElement.builder()
|
||||
.dataSet(resp.getId())
|
||||
.model(dim.getModelId())
|
||||
.id(dim.getId())
|
||||
.name(dim.getName())
|
||||
.bizName(dim.getBizName())
|
||||
.type(SchemaElementType.TAG)
|
||||
.useCnt(dim.getUseCnt())
|
||||
.alias(alias)
|
||||
.schemaValueMaps(schemaValueMaps)
|
||||
.build();
|
||||
tags.add(tagToAdd);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
private static SchemaElement getEntity(DataSetSchemaResp resp) {
|
||||
DimSchemaResp dim = resp.getPrimaryKey();
|
||||
if (Objects.isNull(dim)) {
|
||||
@@ -79,38 +129,6 @@ public class DataSetSchemaBuilder {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Set<SchemaElement> getTags(DataSetSchemaResp resp) {
|
||||
Set<SchemaElement> tags = new HashSet<>();
|
||||
for (TagResp tagResp : resp.getTags()) {
|
||||
SchemaElement element = SchemaElement.builder()
|
||||
.dataSet(resp.getId())
|
||||
.model(tagResp.getModelId())
|
||||
.id(tagResp.getId())
|
||||
.name(tagResp.getName())
|
||||
.bizName(tagResp.getBizName())
|
||||
.type(SchemaElementType.TAG)
|
||||
.build();
|
||||
tags.add(element);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
private static Set<SchemaElement> getTagValues(DataSetSchemaResp resp) {
|
||||
Set<SchemaElement> dimensionValues = new HashSet<>();
|
||||
for (TagResp tagResp : resp.getTags()) {
|
||||
SchemaElement element = SchemaElement.builder()
|
||||
.dataSet(resp.getId())
|
||||
.model(tagResp.getModelId())
|
||||
.id(tagResp.getId())
|
||||
.name(tagResp.getName())
|
||||
.bizName(tagResp.getBizName())
|
||||
.type(SchemaElementType.TAG_VALUE)
|
||||
.build();
|
||||
dimensionValues.add(element);
|
||||
}
|
||||
return dimensionValues;
|
||||
}
|
||||
|
||||
private static Set<SchemaElement> getDimensions(DataSetSchemaResp resp) {
|
||||
Set<SchemaElement> dimensions = new HashSet<>();
|
||||
for (DimSchemaResp dim : resp.getDimensions()) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.tencent.supersonic.headless.server.utils;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.AND_UPPER;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.POUND;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.SPACE;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
@@ -35,12 +41,6 @@ import com.tencent.supersonic.headless.server.service.MetricService;
|
||||
import com.tencent.supersonic.headless.server.service.ModelService;
|
||||
import com.tencent.supersonic.headless.server.service.QueryService;
|
||||
import com.tencent.supersonic.headless.server.service.TagMetaService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -53,11 +53,12 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.AND_UPPER;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.POUND;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.SPACE;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -185,7 +186,7 @@ public class DictUtils {
|
||||
mergeMultivaluedValue(valueAndFrequencyPair, dimValue, metric);
|
||||
}
|
||||
}
|
||||
String nature = dictItemResp.generateNature();
|
||||
String nature = dictItemResp.getNature();
|
||||
constructDictLines(valueAndFrequencyPair, lines, nature);
|
||||
addWhiteValueLines(dictItemResp, lines, nature);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user