mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
(improvement) Move out the datasource and merge the datasource with the model, and adapt the chat module (#423)
Co-authored-by: jolunoluo <jolunoluo@tencent.com>
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
package com.tencent.supersonic.auth.api.authorization.request;
|
package com.tencent.supersonic.auth.api.authorization.request;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRes;
|
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRes;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ToString
|
@ToString
|
||||||
@@ -16,4 +18,16 @@ public class QueryAuthResReq {
|
|||||||
private List<AuthRes> resources;
|
private List<AuthRes> resources;
|
||||||
|
|
||||||
private Long modelId;
|
private Long modelId;
|
||||||
|
|
||||||
|
private List<Long> modelIds;
|
||||||
|
|
||||||
|
public List<Long> getModelIds() {
|
||||||
|
if (!CollectionUtils.isEmpty(modelIds)) {
|
||||||
|
return modelIds;
|
||||||
|
}
|
||||||
|
if (modelId != null) {
|
||||||
|
return Lists.newArrayList(modelId);
|
||||||
|
}
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
public List<AuthGroup> queryAuthGroups(String modelId, Integer groupId) {
|
public List<AuthGroup> queryAuthGroups(String modelId, Integer groupId) {
|
||||||
return load().stream()
|
return load().stream()
|
||||||
.filter(group -> (Objects.isNull(groupId) || groupId.equals(group.getGroupId()))
|
.filter(group -> (Objects.isNull(groupId) || groupId.equals(group.getGroupId()))
|
||||||
&& modelId.equals(group.getModelId()))
|
&& modelId.equals(group.getModelId().toString()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
@Override
|
@Override
|
||||||
public AuthorizedResourceResp queryAuthorizedResources(QueryAuthResReq req, User user) {
|
public AuthorizedResourceResp queryAuthorizedResources(QueryAuthResReq req, User user) {
|
||||||
Set<String> userOrgIds = userService.getUserAllOrgId(user.getName());
|
Set<String> userOrgIds = userService.getUserAllOrgId(user.getName());
|
||||||
List<AuthGroup> groups = getAuthGroups(req.getModelId(), user.getName(), new ArrayList<>(userOrgIds));
|
List<AuthGroup> groups = getAuthGroups(req.getModelIds(), user.getName(), new ArrayList<>(userOrgIds));
|
||||||
AuthorizedResourceResp resource = new AuthorizedResourceResp();
|
AuthorizedResourceResp resource = new AuthorizedResourceResp();
|
||||||
Map<Long, List<AuthGroup>> authGroupsByModelId = groups.stream()
|
Map<Long, List<AuthGroup>> authGroupsByModelId = groups.stream()
|
||||||
.collect(Collectors.groupingBy(AuthGroup::getModelId));
|
.collect(Collectors.groupingBy(AuthGroup::getModelId));
|
||||||
@@ -126,10 +126,10 @@ public class AuthServiceImpl implements AuthService {
|
|||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AuthGroup> getAuthGroups(Long modelId, String userName, List<String> departmentIds) {
|
private List<AuthGroup> getAuthGroups(List<Long> modelIds, String userName, List<String> departmentIds) {
|
||||||
List<AuthGroup> groups = load().stream()
|
List<AuthGroup> groups = load().stream()
|
||||||
.filter(group -> {
|
.filter(group -> {
|
||||||
if (modelId != null && Objects.equals(group.getModelId(), modelId)) {
|
if (CollectionUtils.isEmpty(modelIds) || !modelIds.contains(group.getModelId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(group.getAuthorizedUsers()) && group.getAuthorizedUsers()
|
if (!CollectionUtils.isEmpty(group.getAuthorizedUsers()) && group.getAuthorizedUsers()
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import com.tencent.supersonic.semantic.api.model.request.PageMetricReq;
|
|||||||
import com.tencent.supersonic.semantic.api.model.response.DomainResp;
|
import com.tencent.supersonic.semantic.api.model.response.DomainResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ExplainResp;
|
import com.tencent.supersonic.semantic.api.model.response.ExplainResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
||||||
|
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package com.tencent.supersonic.chat.api.pojo;
|
package com.tencent.supersonic.chat.api.pojo;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelRela;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -14,8 +19,8 @@ public class ModelSchema {
|
|||||||
private Set<SchemaElement> dimensions = new HashSet<>();
|
private Set<SchemaElement> dimensions = new HashSet<>();
|
||||||
private Set<SchemaElement> dimensionValues = new HashSet<>();
|
private Set<SchemaElement> dimensionValues = new HashSet<>();
|
||||||
private Set<SchemaElement> tags = new HashSet<>();
|
private Set<SchemaElement> tags = new HashSet<>();
|
||||||
@Deprecated
|
|
||||||
private SchemaElement entity = new SchemaElement();
|
private SchemaElement entity = new SchemaElement();
|
||||||
|
private List<ModelRela> modelRelas = new ArrayList<>();
|
||||||
|
|
||||||
public SchemaElement getElement(SchemaElementType elementType, long elementID) {
|
public SchemaElement getElement(SchemaElementType elementType, long elementID) {
|
||||||
Optional<SchemaElement> element = Optional.empty();
|
Optional<SchemaElement> element = Optional.empty();
|
||||||
@@ -75,4 +80,16 @@ public class ModelSchema {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Long> getModelClusterSet() {
|
||||||
|
if (CollectionUtils.isEmpty(modelRelas)) {
|
||||||
|
return Sets.newHashSet();
|
||||||
|
}
|
||||||
|
Set<Long> modelClusterSet = new HashSet<>();
|
||||||
|
modelRelas.forEach(modelRela -> {
|
||||||
|
modelClusterSet.add(modelRela.getToModelId());
|
||||||
|
modelClusterSet.add(modelRela.getFromModelId());
|
||||||
|
});
|
||||||
|
return modelClusterSet;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class QueryContext {
|
|||||||
private QueryReq request;
|
private QueryReq request;
|
||||||
private List<SemanticQuery> candidateQueries = new ArrayList<>();
|
private List<SemanticQuery> candidateQueries = new ArrayList<>();
|
||||||
private SchemaMapInfo mapInfo = new SchemaMapInfo();
|
private SchemaMapInfo mapInfo = new SchemaMapInfo();
|
||||||
|
private SchemaModelClusterMapInfo modelClusterMapInfo = new SchemaModelClusterMapInfo();
|
||||||
|
|
||||||
public QueryContext(QueryReq request) {
|
public QueryContext(QueryReq request) {
|
||||||
this.request = request;
|
this.request = request;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ public enum SchemaElementType {
|
|||||||
DIMENSION,
|
DIMENSION,
|
||||||
VALUE,
|
VALUE,
|
||||||
ENTITY,
|
ENTITY,
|
||||||
|
TAG,
|
||||||
ID,
|
ID,
|
||||||
DATE,
|
DATE
|
||||||
TAG
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.tencent.supersonic.chat.api.pojo;
|
||||||
|
|
||||||
|
import com.clickhouse.client.internal.apache.commons.compress.utils.Lists;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SchemaModelClusterMapInfo {
|
||||||
|
|
||||||
|
private Map<String, List<SchemaElementMatch>> modelElementMatches = new HashMap<>();
|
||||||
|
|
||||||
|
public Set<String> getMatchedModelClusters() {
|
||||||
|
return modelElementMatches.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SchemaElementMatch> getMatchedElements(Long modelId) {
|
||||||
|
for (String key : modelElementMatches.keySet()) {
|
||||||
|
if (ModelCluster.getModelIdFromKey(key).contains(modelId)) {
|
||||||
|
return modelElementMatches.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SchemaElementMatch> getMatchedElements(String modelCluster) {
|
||||||
|
return modelElementMatches.get(modelCluster);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<SchemaElementMatch>> getModelElementMatches() {
|
||||||
|
return modelElementMatches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, List<SchemaElementMatch>> getElementMatchesByModelIds(Set<Long> modelIds) {
|
||||||
|
if (CollectionUtils.isEmpty(modelIds)) {
|
||||||
|
return modelElementMatches;
|
||||||
|
}
|
||||||
|
Map<String, List<SchemaElementMatch>> modelElementMatchesFiltered = new HashMap<>();
|
||||||
|
for (String key : modelElementMatches.keySet()) {
|
||||||
|
for (Long modelId : modelIds) {
|
||||||
|
if (ModelCluster.getModelIdFromKey(key).contains(modelId)) {
|
||||||
|
modelElementMatchesFiltered.put(key, modelElementMatches.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modelElementMatchesFiltered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModelElementMatches(Map<String, List<SchemaElementMatch>> modelElementMatches) {
|
||||||
|
this.modelElementMatches = modelElementMatches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMatchedElements(String modelCluster, List<SchemaElementMatch> elementMatches) {
|
||||||
|
modelElementMatches.put(modelCluster, elementMatches);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,13 @@ import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.response.EntityInfo;
|
import com.tencent.supersonic.chat.api.pojo.response.EntityInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.SqlInfo;
|
import com.tencent.supersonic.chat.api.pojo.response.SqlInfo;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.pojo.Order;
|
import com.tencent.supersonic.common.pojo.Order;
|
||||||
import com.tencent.supersonic.common.pojo.QueryType;
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.FilterType;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -16,15 +20,13 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterType;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SemanticParseInfo {
|
public class SemanticParseInfo {
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String queryMode;
|
private String queryMode;
|
||||||
private SchemaElement model;
|
private ModelCluster model = new ModelCluster();
|
||||||
private Set<SchemaElement> metrics = new TreeSet<>(new SchemaNameLengthComparator());
|
private Set<SchemaElement> metrics = new TreeSet<>(new SchemaNameLengthComparator());
|
||||||
private Set<SchemaElement> dimensions = new LinkedHashSet();
|
private Set<SchemaElement> dimensions = new LinkedHashSet();
|
||||||
private SchemaElement entity;
|
private SchemaElement entity;
|
||||||
@@ -42,12 +44,18 @@ public class SemanticParseInfo {
|
|||||||
private SqlInfo sqlInfo = new SqlInfo();
|
private SqlInfo sqlInfo = new SqlInfo();
|
||||||
private QueryType queryType = QueryType.OTHER;
|
private QueryType queryType = QueryType.OTHER;
|
||||||
|
|
||||||
public Long getModelId() {
|
public String getModelClusterKey() {
|
||||||
return model != null ? model.getId() : 0L;
|
if (model == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return model.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModelName() {
|
public String getModelName() {
|
||||||
return model != null ? model.getName() : "null";
|
if (model == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return model.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SchemaNameLengthComparator implements Comparator<SchemaElement> {
|
private static class SchemaNameLengthComparator implements Comparator<SchemaElement> {
|
||||||
@@ -78,4 +86,26 @@ public class SemanticParseInfo {
|
|||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<Long, Integer> getModelElementCountMap() {
|
||||||
|
Map<Long, Integer> elementCountMap = new HashMap<>();
|
||||||
|
elementMatches.forEach(element -> {
|
||||||
|
int count = elementCountMap.getOrDefault(element.getElement().getModel(), 0);
|
||||||
|
elementCountMap.put(element.getElement().getModel(), count + 1);
|
||||||
|
});
|
||||||
|
return elementCountMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getModelId() {
|
||||||
|
Map<Long, Integer> elementCountMap = getModelElementCountMap();
|
||||||
|
Long modelId = -1L;
|
||||||
|
int maxCnt = 0;
|
||||||
|
for (Long model : elementCountMap.keySet()) {
|
||||||
|
if (elementCountMap.get(model) > maxCnt) {
|
||||||
|
maxCnt = elementCountMap.get(model);
|
||||||
|
modelId = model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modelId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package com.tencent.supersonic.chat.api.pojo;
|
package com.tencent.supersonic.chat.api.pojo;
|
||||||
|
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SemanticSchema implements Serializable {
|
public class SemanticSchema implements Serializable {
|
||||||
@@ -18,6 +23,64 @@ public class SemanticSchema implements Serializable {
|
|||||||
modelSchemaList.add(schema);
|
modelSchemaList.add(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SchemaElement getElement(SchemaElementType elementType, long elementID) {
|
||||||
|
Optional<SchemaElement> element = Optional.empty();
|
||||||
|
|
||||||
|
switch (elementType) {
|
||||||
|
case ENTITY:
|
||||||
|
element = getElementsById(elementID, getEntities());
|
||||||
|
break;
|
||||||
|
case MODEL:
|
||||||
|
element = getElementsById(elementID, getModels());
|
||||||
|
break;
|
||||||
|
case METRIC:
|
||||||
|
element = getElementsById(elementID, getMetrics());
|
||||||
|
break;
|
||||||
|
case DIMENSION:
|
||||||
|
element = getElementsById(elementID, getDimensions());
|
||||||
|
break;
|
||||||
|
case VALUE:
|
||||||
|
element = getElementsById(elementID, getDimensionValues());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.isPresent()) {
|
||||||
|
return element.get();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SchemaElement getElementByName(SchemaElementType elementType, String name) {
|
||||||
|
Optional<SchemaElement> element = Optional.empty();
|
||||||
|
|
||||||
|
switch (elementType) {
|
||||||
|
case ENTITY:
|
||||||
|
element = getElementsByName(name, getEntities());
|
||||||
|
break;
|
||||||
|
case MODEL:
|
||||||
|
element = getElementsByName(name, getModels());
|
||||||
|
break;
|
||||||
|
case METRIC:
|
||||||
|
element = getElementsByName(name, getMetrics());
|
||||||
|
break;
|
||||||
|
case DIMENSION:
|
||||||
|
element = getElementsByName(name, getDimensions());
|
||||||
|
break;
|
||||||
|
case VALUE:
|
||||||
|
element = getElementsByName(name, getDimensionValues());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element.isPresent()) {
|
||||||
|
return element.get();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Long, String> getModelIdToName() {
|
public Map<Long, String> getModelIdToName() {
|
||||||
return modelSchemaList.stream()
|
return modelSchemaList.stream()
|
||||||
.collect(Collectors.toMap(a -> a.getModel().getId(), a -> a.getModel().getName(), (k1, k2) -> k1));
|
.collect(Collectors.toMap(a -> a.getModel().getId(), a -> a.getModel().getName(), (k1, k2) -> k1));
|
||||||
@@ -35,9 +98,21 @@ public class SemanticSchema implements Serializable {
|
|||||||
return dimensions;
|
return dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SchemaElement> getDimensions(Long modelId) {
|
public List<SchemaElement> getDimensions(Set<Long> modelIds) {
|
||||||
List<SchemaElement> dimensions = getDimensions();
|
List<SchemaElement> dimensions = getDimensions();
|
||||||
return getElementsByModelId(modelId, dimensions);
|
return getElementsByModelId(modelIds, dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SchemaElement getDimensions(Long id) {
|
||||||
|
List<SchemaElement> dimensions = getDimensions();
|
||||||
|
Optional<SchemaElement> dimension = getElementsById(id, dimensions);
|
||||||
|
return dimension.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SchemaElement> getTags() {
|
||||||
|
List<SchemaElement> tags = new ArrayList<>();
|
||||||
|
modelSchemaList.stream().forEach(d -> tags.addAll(d.getTags()));
|
||||||
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SchemaElement> getMetrics() {
|
public List<SchemaElement> getMetrics() {
|
||||||
@@ -46,21 +121,9 @@ public class SemanticSchema implements Serializable {
|
|||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SchemaElement> getMetrics(Long modelId) {
|
public List<SchemaElement> getMetrics(Set<Long> modelIds) {
|
||||||
List<SchemaElement> metrics = getMetrics();
|
List<SchemaElement> metrics = getMetrics();
|
||||||
return getElementsByModelId(modelId, metrics);
|
return getElementsByModelId(modelIds, metrics);
|
||||||
}
|
|
||||||
|
|
||||||
private List<SchemaElement> getElementsByModelId(Long modelId, List<SchemaElement> elements) {
|
|
||||||
return elements.stream()
|
|
||||||
.filter(schemaElement -> modelId.equals(schemaElement.getModel()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SchemaElement> getModels() {
|
|
||||||
List<SchemaElement> models = new ArrayList<>();
|
|
||||||
modelSchemaList.stream().forEach(d -> models.add(d.getModel()));
|
|
||||||
return models;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SchemaElement> getEntities() {
|
public List<SchemaElement> getEntities() {
|
||||||
@@ -69,11 +132,43 @@ public class SemanticSchema implements Serializable {
|
|||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getBizNameToName(Long modelId) {
|
private List<SchemaElement> getElementsByModelId(Set<Long> modelIds, List<SchemaElement> elements) {
|
||||||
|
return elements.stream()
|
||||||
|
.filter(schemaElement -> modelIds.contains(schemaElement.getModel()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<SchemaElement> getElementsById(Long id, List<SchemaElement> elements) {
|
||||||
|
return elements.stream()
|
||||||
|
.filter(schemaElement -> id.equals(schemaElement.getId()))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<SchemaElement> getElementsByName(String name, List<SchemaElement> elements) {
|
||||||
|
return elements.stream()
|
||||||
|
.filter(schemaElement -> name.equals(schemaElement.getName()))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SchemaElement> getModels() {
|
||||||
|
List<SchemaElement> models = new ArrayList<>();
|
||||||
|
modelSchemaList.stream().forEach(d -> models.add(d.getModel()));
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getBizNameToName(Set<Long> modelIds) {
|
||||||
List<SchemaElement> allElements = new ArrayList<>();
|
List<SchemaElement> allElements = new ArrayList<>();
|
||||||
allElements.addAll(getDimensions(modelId));
|
allElements.addAll(getDimensions(modelIds));
|
||||||
allElements.addAll(getMetrics(modelId));
|
allElements.addAll(getMetrics(modelIds));
|
||||||
return allElements.stream()
|
return allElements.stream()
|
||||||
.collect(Collectors.toMap(a -> a.getBizName(), a -> a.getName(), (k1, k2) -> k1));
|
.collect(Collectors.toMap(SchemaElement::getBizName, SchemaElement::getName, (k1, k2) -> k1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Long, ModelSchema> getModelSchemaMap() {
|
||||||
|
if (CollectionUtils.isEmpty(modelSchemaList)) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
return modelSchemaList.stream().collect(Collectors.toMap(modelSchema
|
||||||
|
-> modelSchema.getModel().getModel(), modelSchema -> modelSchema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import lombok.Data;
|
|||||||
public class QueryReq {
|
public class QueryReq {
|
||||||
private String queryText;
|
private String queryText;
|
||||||
private Integer chatId;
|
private Integer chatId;
|
||||||
private Long modelId = 0L;
|
private Long modelId;
|
||||||
private User user;
|
private User user;
|
||||||
private QueryFilters queryFilters;
|
private QueryFilters queryFilters;
|
||||||
private boolean saveAnswer = true;
|
private boolean saveAnswer = true;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class SolvedQueryReq {
|
|||||||
|
|
||||||
private String queryText;
|
private String queryText;
|
||||||
|
|
||||||
private Long modelId;
|
private String modelId;
|
||||||
|
|
||||||
private Integer agentId;
|
private Integer agentId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.tencent.supersonic.chat.api.pojo.response;
|
package com.tencent.supersonic.chat.api.pojo.response;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ModelInfo extends DataInfo implements Serializable {
|
public class ModelInfo extends DataInfo implements Serializable {
|
||||||
|
|
||||||
private List<String> words;
|
private List<String> words;
|
||||||
private String primaryEntityName;
|
private String primaryKey;
|
||||||
private String primaryEntityBizName;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ import com.tencent.supersonic.common.util.jsqlparser.SqlParserAddHelper;
|
|||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -19,9 +23,6 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* basic semantic correction functionality, offering common methods and an
|
* basic semantic correction functionality, offering common methods and an
|
||||||
@@ -45,7 +46,7 @@ public abstract class BaseSemanticCorrector implements SemanticCorrector {
|
|||||||
|
|
||||||
public abstract void doCorrect(QueryReq queryReq, SemanticParseInfo semanticParseInfo);
|
public abstract void doCorrect(QueryReq queryReq, SemanticParseInfo semanticParseInfo);
|
||||||
|
|
||||||
protected Map<String, String> getFieldNameMap(Long modelId) {
|
protected Map<String, String> getFieldNameMap(Set<Long> modelIds) {
|
||||||
|
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ public abstract class BaseSemanticCorrector implements SemanticCorrector {
|
|||||||
|
|
||||||
// support fieldName and field alias
|
// support fieldName and field alias
|
||||||
Map<String, String> result = dbAllFields.stream()
|
Map<String, String> result = dbAllFields.stream()
|
||||||
.filter(entry -> entry.getModel().equals(modelId))
|
.filter(entry -> modelIds.contains(entry.getModel()))
|
||||||
.flatMap(schemaElement -> {
|
.flatMap(schemaElement -> {
|
||||||
Set<String> elements = new HashSet<>();
|
Set<String> elements = new HashSet<>();
|
||||||
elements.add(schemaElement.getName());
|
elements.add(schemaElement.getName());
|
||||||
@@ -103,9 +104,9 @@ public abstract class BaseSemanticCorrector implements SemanticCorrector {
|
|||||||
protected void addAggregateToMetric(SemanticParseInfo semanticParseInfo) {
|
protected void addAggregateToMetric(SemanticParseInfo semanticParseInfo) {
|
||||||
//add aggregate to all metric
|
//add aggregate to all metric
|
||||||
String correctS2SQL = semanticParseInfo.getSqlInfo().getCorrectS2SQL();
|
String correctS2SQL = semanticParseInfo.getSqlInfo().getCorrectS2SQL();
|
||||||
Long modelId = semanticParseInfo.getModel().getModel();
|
Set<Long> modelIds = semanticParseInfo.getModel().getModelIds();
|
||||||
|
|
||||||
List<SchemaElement> metrics = getMetricElements(modelId);
|
List<SchemaElement> metrics = getMetricElements(modelIds);
|
||||||
|
|
||||||
Map<String, String> metricToAggregate = metrics.stream()
|
Map<String, String> metricToAggregate = metrics.stream()
|
||||||
.map(schemaElement -> {
|
.map(schemaElement -> {
|
||||||
@@ -122,9 +123,9 @@ public abstract class BaseSemanticCorrector implements SemanticCorrector {
|
|||||||
semanticParseInfo.getSqlInfo().setCorrectS2SQL(aggregateSql);
|
semanticParseInfo.getSqlInfo().setCorrectS2SQL(aggregateSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<SchemaElement> getMetricElements(Long modelId) {
|
protected List<SchemaElement> getMetricElements(Set<Long> modelIds) {
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
return semanticSchema.getMetrics(modelId);
|
return semanticSchema.getMetrics(modelIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.tencent.supersonic.chat.corrector;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||||
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserReplaceHelper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class FromCorrector extends BaseSemanticCorrector {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doCorrect(QueryReq queryReq, SemanticParseInfo semanticParseInfo) {
|
||||||
|
String modelName = semanticParseInfo.getModel().getName();
|
||||||
|
SqlParserReplaceHelper.replaceTable(semanticParseInfo.getSqlInfo().getCorrectS2SQL(), modelName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,12 +9,13 @@ import com.tencent.supersonic.common.util.ContextUtils;
|
|||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserAddHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserAddHelper;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform SQL corrections on the "group by" section in S2SQL.
|
* Perform SQL corrections on the "group by" section in S2SQL.
|
||||||
@@ -30,14 +31,14 @@ public class GroupByCorrector extends BaseSemanticCorrector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addGroupByFields(SemanticParseInfo semanticParseInfo) {
|
private void addGroupByFields(SemanticParseInfo semanticParseInfo) {
|
||||||
Long modelId = semanticParseInfo.getModel().getModel();
|
Set<Long> modelIds = semanticParseInfo.getModel().getModelIds();
|
||||||
|
|
||||||
//add dimension group by
|
//add dimension group by
|
||||||
SqlInfo sqlInfo = semanticParseInfo.getSqlInfo();
|
SqlInfo sqlInfo = semanticParseInfo.getSqlInfo();
|
||||||
String correctS2SQL = sqlInfo.getCorrectS2SQL();
|
String correctS2SQL = sqlInfo.getCorrectS2SQL();
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
//add alias field name
|
//add alias field name
|
||||||
Set<String> dimensions = semanticSchema.getDimensions(modelId).stream()
|
Set<String> dimensions = semanticSchema.getDimensions(modelIds).stream()
|
||||||
.flatMap(
|
.flatMap(
|
||||||
schemaElement -> {
|
schemaElement -> {
|
||||||
Set<String> elements = new HashSet<>();
|
Set<String> elements = new HashSet<>();
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ import com.tencent.supersonic.common.util.jsqlparser.SqlParserRemoveHelper;
|
|||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform SQL corrections on the "Having" section in S2SQL.
|
* Perform SQL corrections on the "Having" section in S2SQL.
|
||||||
*/
|
*/
|
||||||
@@ -37,11 +38,11 @@ public class HavingCorrector extends BaseSemanticCorrector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addHaving(SemanticParseInfo semanticParseInfo) {
|
private void addHaving(SemanticParseInfo semanticParseInfo) {
|
||||||
Long modelId = semanticParseInfo.getModel().getModel();
|
Set<Long> modelIds = semanticParseInfo.getModel().getModelIds();
|
||||||
|
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
|
|
||||||
Set<String> metrics = semanticSchema.getMetrics(modelId).stream()
|
Set<String> metrics = semanticSchema.getMetrics(modelIds).stream()
|
||||||
.map(schemaElement -> schemaElement.getName()).collect(Collectors.toSet());
|
.map(schemaElement -> schemaElement.getName()).collect(Collectors.toSet());
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(metrics)) {
|
if (CollectionUtils.isEmpty(metrics)) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class SchemaCorrector extends BaseSemanticCorrector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void correctFieldName(SemanticParseInfo semanticParseInfo) {
|
private void correctFieldName(SemanticParseInfo semanticParseInfo) {
|
||||||
Map<String, String> fieldNameMap = getFieldNameMap(semanticParseInfo.getModelId());
|
Map<String, String> fieldNameMap = getFieldNameMap(semanticParseInfo.getModel().getModelIds());
|
||||||
SqlInfo sqlInfo = semanticParseInfo.getSqlInfo();
|
SqlInfo sqlInfo = semanticParseInfo.getSqlInfo();
|
||||||
String sql = SqlParserReplaceHelper.replaceFields(sqlInfo.getCorrectS2SQL(), fieldNameMap);
|
String sql = SqlParserReplaceHelper.replaceFields(sqlInfo.getCorrectS2SQL(), fieldNameMap);
|
||||||
sqlInfo.setCorrectS2SQL(sql);
|
sqlInfo.setCorrectS2SQL(sql);
|
||||||
|
|||||||
@@ -16,11 +16,6 @@ import com.tencent.supersonic.common.util.jsqlparser.SqlParserRemoveHelper;
|
|||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserReplaceHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserReplaceHelper;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.JSQLParserException;
|
import net.sf.jsqlparser.JSQLParserException;
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
@@ -29,6 +24,13 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform SQL corrections on the "Where" section in S2SQL.
|
* Perform SQL corrections on the "Where" section in S2SQL.
|
||||||
*/
|
*/
|
||||||
@@ -102,10 +104,8 @@ public class WhereCorrector extends BaseSemanticCorrector {
|
|||||||
|
|
||||||
private void updateFieldValueByTechName(SemanticParseInfo semanticParseInfo) {
|
private void updateFieldValueByTechName(SemanticParseInfo semanticParseInfo) {
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
Long modelId = semanticParseInfo.getModel().getId();
|
Set<Long> modelIds = semanticParseInfo.getModel().getModelIds();
|
||||||
List<SchemaElement> dimensions = semanticSchema.getDimensions().stream()
|
List<SchemaElement> dimensions = semanticSchema.getDimensions(modelIds);
|
||||||
.filter(schemaElement -> modelId.equals(schemaElement.getModel()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(dimensions)) {
|
if (CollectionUtils.isEmpty(dimensions)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ import dev.langchain4j.model.chat.ChatLanguageModel;
|
|||||||
import dev.langchain4j.model.input.Prompt;
|
import dev.langchain4j.model.input.Prompt;
|
||||||
import dev.langchain4j.model.input.PromptTemplate;
|
import dev.langchain4j.model.input.PromptTemplate;
|
||||||
import dev.langchain4j.model.output.Response;
|
import dev.langchain4j.model.output.Response;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class EmbedLLMInterpreter implements LLMInterpreter {
|
public class EmbedLLMInterpreter implements LLMInterpreter {
|
||||||
|
|
||||||
public LLMResp query2sql(LLMReq llmReq, Long modelId) {
|
public LLMResp query2sql(LLMReq llmReq, String modelClusterKey) {
|
||||||
|
|
||||||
ChatLanguageModel chatLanguageModel = ContextUtils.getBean(ChatLanguageModel.class);
|
ChatLanguageModel chatLanguageModel = ContextUtils.getBean(ChatLanguageModel.class);
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
|||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -19,14 +17,16 @@ import org.springframework.http.MediaType;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HttpLLMInterpreter implements LLMInterpreter {
|
public class HttpLLMInterpreter implements LLMInterpreter {
|
||||||
|
|
||||||
public LLMResp query2sql(LLMReq llmReq, Long modelId) {
|
public LLMResp query2sql(LLMReq llmReq, String modelClusterKey) {
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
log.info("requestLLM request, modelId:{},llmReq:{}", modelId, llmReq);
|
log.info("requestLLM request, modelId:{},llmReq:{}", modelClusterKey, llmReq);
|
||||||
try {
|
try {
|
||||||
LLMParserConfig llmParserConfig = ContextUtils.getBean(LLMParserConfig.class);
|
LLMParserConfig llmParserConfig = ContextUtils.getBean(LLMParserConfig.class);
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
|||||||
public interface LLMInterpreter {
|
public interface LLMInterpreter {
|
||||||
|
|
||||||
|
|
||||||
LLMResp query2sql(LLMReq llmReq, Long modelId);
|
LLMResp query2sql(LLMReq llmReq, String modelClusterKey);
|
||||||
|
|
||||||
FunctionResp requestFunction(FunctionReq functionReq);
|
FunctionResp requestFunction(FunctionReq functionReq);
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
|
import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
|
||||||
import com.tencent.supersonic.chat.service.SemanticService;
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapper capable of converting the VALUE of entity dimension values into ID types.
|
* A mapper capable of converting the VALUE of entity dimension values into ID types.
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +34,8 @@ public class EntityMapper extends BaseMapper {
|
|||||||
if (entity == null || entity.getId() == null) {
|
if (entity == null || entity.getId() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<SchemaElementMatch> valueSchemaElements = schemaElementMatchList.stream().filter(schemaElementMatch ->
|
List<SchemaElementMatch> valueSchemaElements = schemaElementMatchList.stream()
|
||||||
|
.filter(schemaElementMatch ->
|
||||||
SchemaElementType.VALUE.equals(schemaElementMatch.getElement().getType()))
|
SchemaElementType.VALUE.equals(schemaElementMatch.getElement().getType()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
for (SchemaElementMatch schemaElementMatch : valueSchemaElements) {
|
for (SchemaElementMatch schemaElementMatch : valueSchemaElements) {
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.tencent.supersonic.chat.mapper;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.chat.api.component.SchemaMapper;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaModelClusterMapInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
|
import com.tencent.supersonic.chat.utils.ModelClusterBuilder;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ModelClusterMapper implements SchemaMapper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void map(QueryContext queryContext) {
|
||||||
|
SchemaService schemaService = ContextUtils.getBean(SchemaService.class);
|
||||||
|
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
||||||
|
SchemaMapInfo schemaMapInfo = queryContext.getMapInfo();
|
||||||
|
List<ModelCluster> modelClusters = buildModelClusterMatched(schemaMapInfo, semanticSchema);
|
||||||
|
Map<String, List<SchemaElementMatch>> modelClusterElementMatches = new HashMap<>();
|
||||||
|
for (ModelCluster modelCluster : modelClusters) {
|
||||||
|
for (Long modelId : schemaMapInfo.getMatchedModels()) {
|
||||||
|
if (modelCluster.getModelIds().contains(modelId)) {
|
||||||
|
modelClusterElementMatches.computeIfAbsent(modelCluster.getKey(), k -> new ArrayList<>())
|
||||||
|
.addAll(schemaMapInfo.getMatchedElements(modelId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SchemaModelClusterMapInfo modelClusterMapInfo = new SchemaModelClusterMapInfo();
|
||||||
|
modelClusterMapInfo.setModelElementMatches(modelClusterElementMatches);
|
||||||
|
queryContext.setModelClusterMapInfo(modelClusterMapInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ModelCluster> buildModelClusterMatched(SchemaMapInfo schemaMapInfo,
|
||||||
|
SemanticSchema semanticSchema) {
|
||||||
|
Set<Long> matchedModels = schemaMapInfo.getMatchedModels();
|
||||||
|
List<ModelCluster> modelClusters = ModelClusterBuilder.buildModelClusters(semanticSchema);
|
||||||
|
return modelClusters.stream().map(ModelCluster::getModelIds).peek(modelCluster -> {
|
||||||
|
modelCluster.removeIf(model -> !matchedModels.contains(model));
|
||||||
|
}).filter(modelCluster -> modelCluster.size() > 0).map(ModelCluster::build).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
|||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
@@ -17,13 +16,14 @@ import com.tencent.supersonic.common.pojo.QueryType;
|
|||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
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 lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query type parser, determine if the query is a metric query, an entity query,
|
* Query type parser, determine if the query is a metric query, an entity query,
|
||||||
@@ -58,11 +58,10 @@ public class QueryTypeParser implements SemanticParser {
|
|||||||
//If all the fields in the SELECT statement are of tag type.
|
//If all the fields in the SELECT statement are of tag type.
|
||||||
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getS2SQL());
|
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getS2SQL());
|
||||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
ModelSchema modelSchema = semanticService.getModelSchema(parseInfo.getModelId());
|
SemanticSchema semanticSchema = semanticService.getSemanticSchema();
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(selectFields) && Objects.nonNull(modelSchema) && CollectionUtils.isNotEmpty(
|
if (CollectionUtils.isNotEmpty(selectFields)) {
|
||||||
modelSchema.getTags())) {
|
Set<String> tags = semanticSchema.getTags().stream().map(SchemaElement::getName)
|
||||||
Set<String> tags = modelSchema.getTags().stream().map(schemaElement -> schemaElement.getName())
|
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
if (tags.containsAll(selectFields)) {
|
if (tags.containsAll(selectFields)) {
|
||||||
return QueryType.TAG;
|
return QueryType.TAG;
|
||||||
@@ -72,10 +71,10 @@ public class QueryTypeParser implements SemanticParser {
|
|||||||
//2. metric queryType
|
//2. metric queryType
|
||||||
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getS2SQL());
|
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getS2SQL());
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
List<SchemaElement> metrics = semanticSchema.getMetrics(parseInfo.getModelId());
|
List<SchemaElement> metrics = semanticSchema.getMetrics(parseInfo.getModel().getModelIds());
|
||||||
if (CollectionUtils.isNotEmpty(metrics)) {
|
if (CollectionUtils.isNotEmpty(metrics)) {
|
||||||
Set<String> metricNameSet = metrics.stream().map(metric -> metric.getName()).collect(Collectors.toSet());
|
Set<String> metricNameSet = metrics.stream().map(SchemaElement::getName).collect(Collectors.toSet());
|
||||||
boolean containMetric = selectFields.stream().anyMatch(selectField -> metricNameSet.contains(selectField));
|
boolean containMetric = selectFields.stream().anyMatch(metricNameSet::contains);
|
||||||
if (containMetric) {
|
if (containMetric) {
|
||||||
return QueryType.METRIC;
|
return QueryType.METRIC;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,8 @@ import com.google.common.collect.Sets;
|
|||||||
import com.tencent.supersonic.chat.agent.Agent;
|
import com.tencent.supersonic.chat.agent.Agent;
|
||||||
import com.tencent.supersonic.chat.agent.tool.AgentToolType;
|
import com.tencent.supersonic.chat.agent.tool.AgentToolType;
|
||||||
import com.tencent.supersonic.chat.agent.tool.MetricInterpretTool;
|
import com.tencent.supersonic.chat.agent.tool.MetricInterpretTool;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
@@ -21,18 +19,19 @@ import com.tencent.supersonic.chat.query.QueryManager;
|
|||||||
import com.tencent.supersonic.chat.query.llm.LLMSemanticQuery;
|
import com.tencent.supersonic.chat.query.llm.LLMSemanticQuery;
|
||||||
import com.tencent.supersonic.chat.query.llm.interpret.MetricInterpretQuery;
|
import com.tencent.supersonic.chat.query.llm.interpret.MetricInterpretQuery;
|
||||||
import com.tencent.supersonic.chat.service.AgentService;
|
import com.tencent.supersonic.chat.service.AgentService;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class MetricInterpretParser implements SemanticParser {
|
public class MetricInterpretParser implements SemanticParser {
|
||||||
@@ -81,9 +80,8 @@ public class MetricInterpretParser implements SemanticParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<SchemaElement> getMetrics(List<Long> metricIds, Long modelId) {
|
public Set<SchemaElement> getMetrics(List<Long> metricIds, Long modelId) {
|
||||||
SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
ModelSchema modelSchema = semanticInterpreter.getModelSchema(modelId, true);
|
List<SchemaElement> metrics = semanticService.getSemanticSchema().getMetrics();
|
||||||
Set<SchemaElement> metrics = modelSchema.getMetrics();
|
|
||||||
return metrics.stream().filter(schemaElement -> metricIds.contains(schemaElement.getId()))
|
return metrics.stream().filter(schemaElement -> metricIds.contains(schemaElement.getId()))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
@@ -112,16 +110,13 @@ public class MetricInterpretParser implements SemanticParser {
|
|||||||
|
|
||||||
private SemanticParseInfo buildSemanticParseInfo(Long modelId, QueryReq queryReq, Set<SchemaElement> metrics,
|
private SemanticParseInfo buildSemanticParseInfo(Long modelId, QueryReq queryReq, Set<SchemaElement> metrics,
|
||||||
List<SchemaElementMatch> schemaElementMatches, String toolName) {
|
List<SchemaElementMatch> schemaElementMatches, String toolName) {
|
||||||
SchemaElement model = new SchemaElement();
|
|
||||||
model.setModel(modelId);
|
|
||||||
model.setId(modelId);
|
|
||||||
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
||||||
semanticParseInfo.setMetrics(metrics);
|
semanticParseInfo.setMetrics(metrics);
|
||||||
SchemaElement dimension = new SchemaElement();
|
SchemaElement dimension = new SchemaElement();
|
||||||
dimension.setBizName(TimeDimensionEnum.DAY.getName());
|
dimension.setBizName(TimeDimensionEnum.DAY.getName());
|
||||||
semanticParseInfo.setDimensions(Sets.newHashSet(dimension));
|
semanticParseInfo.setDimensions(Sets.newHashSet(dimension));
|
||||||
semanticParseInfo.setElementMatches(schemaElementMatches);
|
semanticParseInfo.setElementMatches(schemaElementMatches);
|
||||||
semanticParseInfo.setModel(model);
|
semanticParseInfo.setModel(ModelCluster.build(Sets.newHashSet(modelId)));
|
||||||
semanticParseInfo.setScore(queryReq.getQueryText().length());
|
semanticParseInfo.setScore(queryReq.getQueryText().length());
|
||||||
DateConf dateConf = new DateConf();
|
DateConf dateConf = new DateConf();
|
||||||
dateConf.setDateMode(DateConf.DateMode.RECENT);
|
dateConf.setDateMode(DateConf.DateMode.RECENT);
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
|
import com.tencent.supersonic.chat.api.pojo.SchemaModelClusterMapInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -17,31 +19,28 @@ import java.util.Map.Entry;
|
|||||||
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 lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HeuristicModelResolver implements ModelResolver {
|
public class HeuristicModelResolver implements ModelResolver {
|
||||||
|
|
||||||
protected static Long selectModelBySchemaElementMatchScore(Map<Long, SemanticQuery> modelQueryModes,
|
protected static String selectModelBySchemaElementMatchScore(Map<String, SemanticQuery> modelQueryModes,
|
||||||
SchemaMapInfo schemaMap) {
|
SchemaModelClusterMapInfo schemaMap) {
|
||||||
//model count priority
|
//model count priority
|
||||||
Long modelIdByModelCount = getModelIdByMatchModelScore(schemaMap);
|
String modelIdByModelCount = getModelIdByMatchModelScore(schemaMap);
|
||||||
if (Objects.nonNull(modelIdByModelCount)) {
|
if (Objects.nonNull(modelIdByModelCount)) {
|
||||||
log.info("selectModel by model count:{}", modelIdByModelCount);
|
log.info("selectModel by model count:{}", modelIdByModelCount);
|
||||||
return modelIdByModelCount;
|
return modelIdByModelCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Long, ModelMatchResult> modelTypeMap = getModelTypeMap(schemaMap);
|
Map<String, ModelMatchResult> modelTypeMap = getModelTypeMap(schemaMap);
|
||||||
if (modelTypeMap.size() == 1) {
|
if (modelTypeMap.size() == 1) {
|
||||||
Long modelSelect = modelTypeMap.entrySet().stream().collect(Collectors.toList()).get(0).getKey();
|
String modelSelect = modelTypeMap.entrySet().stream().collect(Collectors.toList()).get(0).getKey();
|
||||||
if (modelQueryModes.containsKey(modelSelect)) {
|
if (modelQueryModes.containsKey(modelSelect)) {
|
||||||
log.info("selectModel with only one Model [{}]", modelSelect);
|
log.info("selectModel with only one Model [{}]", modelSelect);
|
||||||
return modelSelect;
|
return modelSelect;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Map.Entry<String, ModelMatchResult> maxModel = modelTypeMap.entrySet().stream()
|
||||||
Map.Entry<Long, ModelMatchResult> maxModel = modelTypeMap.entrySet().stream()
|
|
||||||
.filter(entry -> modelQueryModes.containsKey(entry.getKey()))
|
.filter(entry -> modelQueryModes.containsKey(entry.getKey()))
|
||||||
.sorted((o1, o2) -> {
|
.sorted((o1, o2) -> {
|
||||||
int difference = o2.getValue().getCount() - o1.getValue().getCount();
|
int difference = o2.getValue().getCount() - o1.getValue().getCount();
|
||||||
@@ -56,16 +55,16 @@ public class HeuristicModelResolver implements ModelResolver {
|
|||||||
return maxModel.getKey();
|
return maxModel.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0L;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Long getModelIdByMatchModelScore(SchemaMapInfo schemaMap) {
|
private static String getModelIdByMatchModelScore(SchemaModelClusterMapInfo schemaMap) {
|
||||||
Map<Long, List<SchemaElementMatch>> modelElementMatches = schemaMap.getModelElementMatches();
|
Map<String, List<SchemaElementMatch>> modelElementMatches = schemaMap.getModelElementMatches();
|
||||||
// calculate model match score, matched element gets 1.0 point, and inherit element gets 0.5 point
|
// calculate model match score, matched element gets 1.0 point, and inherit element gets 0.5 point
|
||||||
Map<Long, Double> modelIdToModelScore = new HashMap<>();
|
Map<String, Double> modelIdToModelScore = new HashMap<>();
|
||||||
if (Objects.nonNull(modelElementMatches)) {
|
if (Objects.nonNull(modelElementMatches)) {
|
||||||
for (Entry<Long, List<SchemaElementMatch>> modelElementMatch : modelElementMatches.entrySet()) {
|
for (Entry<String, List<SchemaElementMatch>> modelElementMatch : modelElementMatches.entrySet()) {
|
||||||
Long modelId = modelElementMatch.getKey();
|
String modelId = modelElementMatch.getKey();
|
||||||
List<Double> modelMatchesScore = modelElementMatch.getValue().stream()
|
List<Double> modelMatchesScore = modelElementMatch.getValue().stream()
|
||||||
.filter(elementMatch -> elementMatch.getSimilarity() >= 1)
|
.filter(elementMatch -> elementMatch.getSimilarity() >= 1)
|
||||||
.filter(elementMatch -> SchemaElementType.MODEL.equals(elementMatch.getElement().getType()))
|
.filter(elementMatch -> SchemaElementType.MODEL.equals(elementMatch.getElement().getType()))
|
||||||
@@ -77,7 +76,7 @@ public class HeuristicModelResolver implements ModelResolver {
|
|||||||
modelIdToModelScore.put(modelId, score);
|
modelIdToModelScore.put(modelId, score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Entry<Long, Double> maxModelScore = modelIdToModelScore.entrySet().stream()
|
Entry<String, Double> maxModelScore = modelIdToModelScore.entrySet().stream()
|
||||||
.max(Comparator.comparingDouble(o -> o.getValue())).orElse(null);
|
.max(Comparator.comparingDouble(o -> o.getValue())).orElse(null);
|
||||||
log.info("maxModelCount:{},modelIdToModelCount:{}", maxModelScore, modelIdToModelScore);
|
log.info("maxModelCount:{},modelIdToModelCount:{}", maxModelScore, modelIdToModelScore);
|
||||||
if (Objects.nonNull(maxModelScore)) {
|
if (Objects.nonNull(maxModelScore)) {
|
||||||
@@ -87,64 +86,10 @@ public class HeuristicModelResolver implements ModelResolver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* to check can switch Model if context exit Model
|
|
||||||
*
|
|
||||||
* @return false will use context Model, true will use other Model , maybe include context Model
|
|
||||||
*/
|
|
||||||
protected static boolean isAllowSwitch(Map<Long, SemanticQuery> modelQueryModes, SchemaMapInfo schemaMap,
|
|
||||||
ChatContext chatCtx, QueryReq searchCtx,
|
|
||||||
Long modelId, Set<Long> restrictiveModels) {
|
|
||||||
if (!Objects.nonNull(modelId) || modelId <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// except content Model, calculate the number of types for each Model, if numbers<=1 will not switch
|
|
||||||
Map<Long, ModelMatchResult> modelTypeMap = getModelTypeMap(schemaMap);
|
|
||||||
log.info("isAllowSwitch ModelTypeMap [{}]", modelTypeMap);
|
|
||||||
long otherModelTypeNumBigOneCount = modelTypeMap.entrySet().stream()
|
|
||||||
.filter(entry -> modelQueryModes.containsKey(entry.getKey()) && !entry.getKey().equals(modelId))
|
|
||||||
.filter(entry -> entry.getValue().getCount() > 1).count();
|
|
||||||
if (otherModelTypeNumBigOneCount >= 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// if query text only contain time , will not switch
|
|
||||||
if (!CollectionUtils.isEmpty(modelQueryModes.values())) {
|
|
||||||
for (SemanticQuery semanticQuery : modelQueryModes.values()) {
|
|
||||||
if (semanticQuery == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SemanticParseInfo semanticParseInfo = semanticQuery.getParseInfo();
|
|
||||||
if (semanticParseInfo == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (searchCtx.getQueryText() != null && semanticParseInfo.getDateInfo() != null) {
|
|
||||||
if (semanticParseInfo.getDateInfo().getDetectWord() != null) {
|
|
||||||
if (semanticParseInfo.getDateInfo().getDetectWord()
|
|
||||||
.equalsIgnoreCase(searchCtx.getQueryText())) {
|
|
||||||
log.info("timeParseResults is not null , can not switch context , timeParseResults:{},",
|
|
||||||
semanticParseInfo.getDateInfo());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(restrictiveModels) && !restrictiveModels.contains(modelId)) {
|
public static Map<String, ModelMatchResult> getModelTypeMap(SchemaModelClusterMapInfo schemaMap) {
|
||||||
return true;
|
Map<String, ModelMatchResult> modelCount = new HashMap<>();
|
||||||
}
|
for (Map.Entry<String, List<SchemaElementMatch>> entry : schemaMap.getModelElementMatches().entrySet()) {
|
||||||
// if context Model not in schemaMap , will switch
|
|
||||||
if (schemaMap.getMatchedElements(modelId) == null || schemaMap.getMatchedElements(modelId).size() <= 0) {
|
|
||||||
log.info("modelId not in schemaMap ");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// other will not switch
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<Long, ModelMatchResult> getModelTypeMap(SchemaMapInfo schemaMap) {
|
|
||||||
Map<Long, ModelMatchResult> modelCount = new HashMap<>();
|
|
||||||
for (Map.Entry<Long, List<SchemaElementMatch>> entry : schemaMap.getModelElementMatches().entrySet()) {
|
|
||||||
List<SchemaElementMatch> schemaElementMatches = schemaMap.getMatchedElements(entry.getKey());
|
List<SchemaElementMatch> schemaElementMatches = schemaMap.getMatchedElements(entry.getKey());
|
||||||
if (schemaElementMatches != null && schemaElementMatches.size() > 0) {
|
if (schemaElementMatches != null && schemaElementMatches.size() > 0) {
|
||||||
if (!modelCount.containsKey(entry.getKey())) {
|
if (!modelCount.containsKey(entry.getKey())) {
|
||||||
@@ -170,65 +115,34 @@ public class HeuristicModelResolver implements ModelResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Long resolve(QueryContext queryContext, ChatContext chatCtx, Set<Long> restrictiveModels) {
|
public String resolve(QueryContext queryContext, ChatContext chatCtx, Set<Long> restrictiveModels) {
|
||||||
|
SchemaModelClusterMapInfo mapInfo = queryContext.getModelClusterMapInfo();
|
||||||
|
Set<String> matchedModelClusters = mapInfo.getElementMatchesByModelIds(restrictiveModels).keySet();
|
||||||
Long modelId = queryContext.getRequest().getModelId();
|
Long modelId = queryContext.getRequest().getModelId();
|
||||||
if (Objects.nonNull(modelId) && modelId > 0) {
|
if (Objects.nonNull(modelId) && modelId > 0) {
|
||||||
if (CollectionUtils.isEmpty(restrictiveModels)) {
|
if (CollectionUtils.isEmpty(restrictiveModels) || restrictiveModels.contains(modelId)) {
|
||||||
return modelId;
|
return getModelClusterByModelId(modelId, matchedModelClusters);
|
||||||
}
|
|
||||||
if (restrictiveModels.contains(modelId)) {
|
|
||||||
return modelId;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
SchemaMapInfo mapInfo = queryContext.getMapInfo();
|
|
||||||
Set<Long> matchedModels = mapInfo.getMatchedModels();
|
Map<String, SemanticQuery> modelQueryModes = new HashMap<>();
|
||||||
if (CollectionUtils.isNotEmpty(restrictiveModels)) {
|
for (String matchedModel : matchedModelClusters) {
|
||||||
matchedModels = matchedModels.stream()
|
|
||||||
.filter(restrictiveModels::contains)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
Map<Long, SemanticQuery> modelQueryModes = new HashMap<>();
|
|
||||||
for (Long matchedModel : matchedModels) {
|
|
||||||
modelQueryModes.put(matchedModel, null);
|
modelQueryModes.put(matchedModel, null);
|
||||||
}
|
}
|
||||||
if (modelQueryModes.size() == 1) {
|
if (modelQueryModes.size() == 1) {
|
||||||
return modelQueryModes.keySet().stream().findFirst().get();
|
return modelQueryModes.keySet().stream().findFirst().get();
|
||||||
}
|
}
|
||||||
return resolve(modelQueryModes, queryContext, chatCtx,
|
return selectModelBySchemaElementMatchScore(modelQueryModes, mapInfo);
|
||||||
queryContext.getMapInfo(), restrictiveModels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long resolve(Map<Long, SemanticQuery> modelQueryModes, QueryContext queryContext,
|
private String getModelClusterByModelId(Long modelId, Set<String> modelClusterKeySet) {
|
||||||
ChatContext chatCtx, SchemaMapInfo schemaMap, Set<Long> restrictiveModels) {
|
for (String modelClusterKey : modelClusterKeySet) {
|
||||||
Long selectModel = selectModel(modelQueryModes, queryContext.getRequest(),
|
if (ModelCluster.build(modelClusterKey).getModelIds().contains(modelId)) {
|
||||||
chatCtx, schemaMap, restrictiveModels);
|
return modelClusterKey;
|
||||||
if (selectModel > 0) {
|
|
||||||
log.info("selectModel {} ", selectModel);
|
|
||||||
return selectModel;
|
|
||||||
}
|
|
||||||
// get the max SchemaElementType match score
|
|
||||||
return selectModelBySchemaElementMatchScore(modelQueryModes, schemaMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long selectModel(Map<Long, SemanticQuery> modelQueryModes, QueryReq queryContext,
|
|
||||||
ChatContext chatCtx,
|
|
||||||
SchemaMapInfo schemaMap, Set<Long> restrictiveModels) {
|
|
||||||
// if QueryContext has modelId and in ModelQueryModes
|
|
||||||
if (modelQueryModes.containsKey(queryContext.getModelId())) {
|
|
||||||
log.info("selectModel from QueryContext [{}]", queryContext.getModelId());
|
|
||||||
return queryContext.getModelId();
|
|
||||||
}
|
|
||||||
// if ChatContext has modelId and in ModelQueryModes
|
|
||||||
if (chatCtx.getParseInfo().getModelId() > 0) {
|
|
||||||
Long modelId = chatCtx.getParseInfo().getModelId();
|
|
||||||
if (!isAllowSwitch(modelQueryModes, schemaMap, chatCtx, queryContext, modelId, restrictiveModels)) {
|
|
||||||
log.info("selectModel from ChatContext [{}]", modelId);
|
|
||||||
return modelId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// default 0
|
return null;
|
||||||
return 0L;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,21 +12,28 @@ import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||||
import com.tencent.supersonic.chat.config.LLMParserConfig;
|
import com.tencent.supersonic.chat.config.LLMParserConfig;
|
||||||
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
||||||
|
import com.tencent.supersonic.chat.llm.LLMInterpreter;
|
||||||
import com.tencent.supersonic.chat.parser.SatisfactionChecker;
|
import com.tencent.supersonic.chat.parser.SatisfactionChecker;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
||||||
import com.tencent.supersonic.chat.service.AgentService;
|
import com.tencent.supersonic.chat.service.AgentService;
|
||||||
import com.tencent.supersonic.chat.llm.LLMInterpreter;
|
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.pojo.enums.DataFormatTypeEnum;
|
import com.tencent.supersonic.common.pojo.enums.DataFormatTypeEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.common.util.DateUtils;
|
import com.tencent.supersonic.common.util.DateUtils;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -35,12 +42,6 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -72,18 +73,18 @@ public class LLMRequestService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getModelId(QueryContext queryCtx, ChatContext chatCtx, Integer agentId) {
|
public ModelCluster getModelCluster(QueryContext queryCtx, ChatContext chatCtx, Integer agentId) {
|
||||||
Set<Long> distinctModelIds = agentService.getModelIds(agentId, AgentToolType.LLM_S2SQL);
|
Set<Long> distinctModelIds = agentService.getModelIds(agentId, AgentToolType.LLM_S2SQL);
|
||||||
if (agentService.containsAllModel(distinctModelIds)) {
|
if (agentService.containsAllModel(distinctModelIds)) {
|
||||||
distinctModelIds = new HashSet<>();
|
distinctModelIds = new HashSet<>();
|
||||||
}
|
}
|
||||||
ModelResolver modelResolver = ComponentFactory.getModelResolver();
|
ModelResolver modelResolver = ComponentFactory.getModelResolver();
|
||||||
Long modelId = modelResolver.resolve(queryCtx, chatCtx, distinctModelIds);
|
String modelCluster = modelResolver.resolve(queryCtx, chatCtx, distinctModelIds);
|
||||||
log.info("resolve modelId:{},llmParser Models:{}", modelId, distinctModelIds);
|
log.info("resolve modelId:{},llmParser Models:{}", modelCluster, distinctModelIds);
|
||||||
return modelId;
|
return ModelCluster.build(modelCluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommonAgentTool getParserTool(QueryReq request, Long modelId) {
|
public CommonAgentTool getParserTool(QueryReq request, Set<Long> modelIdSet) {
|
||||||
List<CommonAgentTool> commonAgentTools = agentService.getParserTools(request.getAgentId(),
|
List<CommonAgentTool> commonAgentTools = agentService.getParserTools(request.getAgentId(),
|
||||||
AgentToolType.LLM_S2SQL);
|
AgentToolType.LLM_S2SQL);
|
||||||
Optional<CommonAgentTool> llmParserTool = commonAgentTools.stream()
|
Optional<CommonAgentTool> llmParserTool = commonAgentTools.stream()
|
||||||
@@ -92,31 +93,36 @@ public class LLMRequestService {
|
|||||||
if (agentService.containsAllModel(new HashSet<>(modelIds))) {
|
if (agentService.containsAllModel(new HashSet<>(modelIds))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return modelIds.contains(modelId);
|
for (Long modelId : modelIdSet) {
|
||||||
|
if (modelIds.contains(modelId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
})
|
})
|
||||||
.findFirst();
|
.findFirst();
|
||||||
return llmParserTool.orElse(null);
|
return llmParserTool.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LLMReq getLlmReq(QueryContext queryCtx, Long modelId, List<ElementValue> linkingValues) {
|
public LLMReq getLlmReq(QueryContext queryCtx, SemanticSchema semanticSchema,
|
||||||
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
ModelCluster modelCluster, List<ElementValue> linkingValues) {
|
||||||
Map<Long, String> modelIdToName = semanticSchema.getModelIdToName();
|
Map<Long, String> modelIdToName = semanticSchema.getModelIdToName();
|
||||||
String queryText = queryCtx.getRequest().getQueryText();
|
String queryText = queryCtx.getRequest().getQueryText();
|
||||||
|
|
||||||
LLMReq llmReq = new LLMReq();
|
LLMReq llmReq = new LLMReq();
|
||||||
llmReq.setQueryText(queryText);
|
llmReq.setQueryText(queryText);
|
||||||
|
Long firstModelId = modelCluster.getFirstModel();
|
||||||
LLMReq.FilterCondition filterCondition = new LLMReq.FilterCondition();
|
LLMReq.FilterCondition filterCondition = new LLMReq.FilterCondition();
|
||||||
filterCondition.setTableName(modelIdToName.get(modelId));
|
filterCondition.setTableName(modelIdToName.get(firstModelId));
|
||||||
llmReq.setFilterCondition(filterCondition);
|
llmReq.setFilterCondition(filterCondition);
|
||||||
|
|
||||||
LLMReq.LLMSchema llmSchema = new LLMReq.LLMSchema();
|
LLMReq.LLMSchema llmSchema = new LLMReq.LLMSchema();
|
||||||
llmSchema.setModelName(modelIdToName.get(modelId));
|
llmSchema.setModelName(modelIdToName.get(firstModelId));
|
||||||
llmSchema.setDomainName(modelIdToName.get(modelId));
|
llmSchema.setDomainName(modelIdToName.get(firstModelId));
|
||||||
|
|
||||||
List<String> fieldNameList = getFieldNameList(queryCtx, modelId, llmParserConfig);
|
List<String> fieldNameList = getFieldNameList(queryCtx, modelCluster, llmParserConfig);
|
||||||
|
|
||||||
String priorExts = getPriorExts(modelId, fieldNameList);
|
String priorExts = getPriorExts(modelCluster.getModelIds(), fieldNameList);
|
||||||
llmReq.setPriorExts(priorExts);
|
llmReq.setPriorExts(priorExts);
|
||||||
|
|
||||||
fieldNameList.add(TimeDimensionEnum.DAY.getChName());
|
fieldNameList.add(TimeDimensionEnum.DAY.getChName());
|
||||||
@@ -129,7 +135,7 @@ public class LLMRequestService {
|
|||||||
}
|
}
|
||||||
llmReq.setLinking(linking);
|
llmReq.setLinking(linking);
|
||||||
|
|
||||||
String currentDate = S2SQLDateHelper.getReferenceDate(modelId);
|
String currentDate = S2SQLDateHelper.getReferenceDate(firstModelId);
|
||||||
if (StringUtils.isEmpty(currentDate)) {
|
if (StringUtils.isEmpty(currentDate)) {
|
||||||
currentDate = DateUtils.getBeforeDate(0);
|
currentDate = DateUtils.getBeforeDate(0);
|
||||||
}
|
}
|
||||||
@@ -137,24 +143,25 @@ public class LLMRequestService {
|
|||||||
return llmReq;
|
return llmReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LLMResp requestLLM(LLMReq llmReq, Long modelId) {
|
public LLMResp requestLLM(LLMReq llmReq, String modelClusterKey) {
|
||||||
return llmInterpreter.query2sql(llmReq, modelId);
|
return llmInterpreter.query2sql(llmReq, modelClusterKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> getFieldNameList(QueryContext queryCtx, Long modelId, LLMParserConfig llmParserConfig) {
|
protected List<String> getFieldNameList(QueryContext queryCtx, ModelCluster modelCluster,
|
||||||
|
LLMParserConfig llmParserConfig) {
|
||||||
|
|
||||||
Set<String> results = getTopNFieldNames(modelId, llmParserConfig);
|
Set<String> results = getTopNFieldNames(modelCluster, llmParserConfig);
|
||||||
|
|
||||||
Set<String> fieldNameList = getMatchedFieldNames(queryCtx, modelId);
|
Set<String> fieldNameList = getMatchedFieldNames(queryCtx, modelCluster);
|
||||||
|
|
||||||
results.addAll(fieldNameList);
|
results.addAll(fieldNameList);
|
||||||
return new ArrayList<>(results);
|
return new ArrayList<>(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPriorExts(Long modelId, List<String> fieldNameList) {
|
private String getPriorExts(Set<Long> modelIds, List<String> fieldNameList) {
|
||||||
StringBuilder extraInfoSb = new StringBuilder();
|
StringBuilder extraInfoSb = new StringBuilder();
|
||||||
List<ModelSchemaResp> modelSchemaResps = semanticInterpreter.fetchModelSchema(
|
List<ModelSchemaResp> modelSchemaResps = semanticInterpreter.fetchModelSchema(
|
||||||
Collections.singletonList(modelId), true);
|
new ArrayList<>(modelIds), true);
|
||||||
if (!CollectionUtils.isEmpty(modelSchemaResps)) {
|
if (!CollectionUtils.isEmpty(modelSchemaResps)) {
|
||||||
|
|
||||||
ModelSchemaResp modelSchemaResp = modelSchemaResps.get(0);
|
ModelSchemaResp modelSchemaResp = modelSchemaResps.get(0);
|
||||||
@@ -187,10 +194,11 @@ public class LLMRequestService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected List<ElementValue> getValueList(QueryContext queryCtx, Long modelId) {
|
protected List<ElementValue> getValueList(QueryContext queryCtx, ModelCluster modelCluster) {
|
||||||
Map<Long, String> itemIdToName = getItemIdToName(modelId);
|
Map<Long, String> itemIdToName = getItemIdToName(modelCluster);
|
||||||
|
|
||||||
List<SchemaElementMatch> matchedElements = queryCtx.getMapInfo().getMatchedElements(modelId);
|
List<SchemaElementMatch> matchedElements = queryCtx.getModelClusterMapInfo()
|
||||||
|
.getMatchedElements(modelCluster.getKey());
|
||||||
if (CollectionUtils.isEmpty(matchedElements)) {
|
if (CollectionUtils.isEmpty(matchedElements)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -210,22 +218,22 @@ public class LLMRequestService {
|
|||||||
return new ArrayList<>(valueMatches);
|
return new ArrayList<>(valueMatches);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<Long, String> getItemIdToName(Long modelId) {
|
protected Map<Long, String> getItemIdToName(ModelCluster modelCluster) {
|
||||||
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
||||||
return semanticSchema.getDimensions(modelId).stream()
|
return semanticSchema.getDimensions(modelCluster.getModelIds()).stream()
|
||||||
.collect(Collectors.toMap(SchemaElement::getId, SchemaElement::getName, (value1, value2) -> value2));
|
.collect(Collectors.toMap(SchemaElement::getId, SchemaElement::getName, (value1, value2) -> value2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Set<String> getTopNFieldNames(Long modelId, LLMParserConfig llmParserConfig) {
|
private Set<String> getTopNFieldNames(ModelCluster modelCluster, LLMParserConfig llmParserConfig) {
|
||||||
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
||||||
Set<String> results = semanticSchema.getDimensions(modelId).stream()
|
Set<String> results = semanticSchema.getDimensions(modelCluster.getModelIds()).stream()
|
||||||
.sorted(Comparator.comparing(SchemaElement::getUseCnt).reversed())
|
.sorted(Comparator.comparing(SchemaElement::getUseCnt).reversed())
|
||||||
.limit(llmParserConfig.getDimensionTopN())
|
.limit(llmParserConfig.getDimensionTopN())
|
||||||
.map(entry -> entry.getName())
|
.map(entry -> entry.getName())
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
Set<String> metrics = semanticSchema.getMetrics(modelId).stream()
|
Set<String> metrics = semanticSchema.getMetrics(modelCluster.getModelIds()).stream()
|
||||||
.sorted(Comparator.comparing(SchemaElement::getUseCnt).reversed())
|
.sorted(Comparator.comparing(SchemaElement::getUseCnt).reversed())
|
||||||
.limit(llmParserConfig.getMetricTopN())
|
.limit(llmParserConfig.getMetricTopN())
|
||||||
.map(entry -> entry.getName())
|
.map(entry -> entry.getName())
|
||||||
@@ -236,9 +244,10 @@ public class LLMRequestService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Set<String> getMatchedFieldNames(QueryContext queryCtx, Long modelId) {
|
protected Set<String> getMatchedFieldNames(QueryContext queryCtx, ModelCluster modelCluster) {
|
||||||
Map<Long, String> itemIdToName = getItemIdToName(modelId);
|
Map<Long, String> itemIdToName = getItemIdToName(modelCluster);
|
||||||
List<SchemaElementMatch> matchedElements = queryCtx.getMapInfo().getMatchedElements(modelId);
|
List<SchemaElementMatch> matchedElements = queryCtx.getModelClusterMapInfo()
|
||||||
|
.getMatchedElements(modelCluster.getKey());
|
||||||
if (CollectionUtils.isEmpty(matchedElements)) {
|
if (CollectionUtils.isEmpty(matchedElements)) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,21 @@ package com.tencent.supersonic.chat.parser.llm.s2sql;
|
|||||||
|
|
||||||
import com.tencent.supersonic.chat.agent.tool.CommonAgentTool;
|
import com.tencent.supersonic.chat.agent.tool.CommonAgentTool;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
|
||||||
import com.tencent.supersonic.chat.query.QueryManager;
|
import com.tencent.supersonic.chat.query.QueryManager;
|
||||||
import com.tencent.supersonic.chat.query.llm.LLMSemanticQuery;
|
import com.tencent.supersonic.chat.query.llm.LLMSemanticQuery;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.S2SQLQuery;
|
import com.tencent.supersonic.chat.query.llm.s2sql.S2SQLQuery;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserEqualHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserEqualHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class LLMResponseService {
|
public class LLMResponseService {
|
||||||
@@ -30,9 +27,10 @@ public class LLMResponseService {
|
|||||||
}
|
}
|
||||||
LLMSemanticQuery semanticQuery = QueryManager.createLLMQuery(S2SQLQuery.QUERY_MODE);
|
LLMSemanticQuery semanticQuery = QueryManager.createLLMQuery(S2SQLQuery.QUERY_MODE);
|
||||||
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
||||||
Long modelId = parseResult.getModelId();
|
parseInfo.setModel(parseResult.getModelCluster());
|
||||||
CommonAgentTool commonAgentTool = parseResult.getCommonAgentTool();
|
CommonAgentTool commonAgentTool = parseResult.getCommonAgentTool();
|
||||||
parseInfo.getElementMatches().addAll(queryCtx.getMapInfo().getMatchedElements(modelId));
|
parseInfo.getElementMatches().addAll(queryCtx.getModelClusterMapInfo()
|
||||||
|
.getMatchedElements(parseInfo.getModelClusterKey()));
|
||||||
|
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put(Constants.CONTEXT, parseResult);
|
properties.put(Constants.CONTEXT, parseResult);
|
||||||
@@ -43,15 +41,7 @@ public class LLMResponseService {
|
|||||||
parseInfo.setScore(queryCtx.getRequest().getQueryText().length() * (1 + weight));
|
parseInfo.setScore(queryCtx.getRequest().getQueryText().length() * (1 + weight));
|
||||||
parseInfo.setQueryMode(semanticQuery.getQueryMode());
|
parseInfo.setQueryMode(semanticQuery.getQueryMode());
|
||||||
parseInfo.getSqlInfo().setS2SQL(s2SQL);
|
parseInfo.getSqlInfo().setS2SQL(s2SQL);
|
||||||
|
parseInfo.setModel(parseResult.getModelCluster());
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
|
||||||
Map<Long, String> modelIdToName = semanticSchema.getModelIdToName();
|
|
||||||
|
|
||||||
SchemaElement model = new SchemaElement();
|
|
||||||
model.setModel(modelId);
|
|
||||||
model.setId(modelId);
|
|
||||||
model.setName(modelIdToName.get(modelId));
|
|
||||||
parseInfo.setModel(model);
|
|
||||||
queryCtx.getCandidateQueries().add(semanticQuery);
|
queryCtx.getCandidateQueries().add(semanticQuery);
|
||||||
return parseInfo;
|
return parseInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,21 @@ import com.tencent.supersonic.chat.agent.tool.CommonAgentTool;
|
|||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
||||||
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
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 lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LLMS2SQLParser implements SemanticParser {
|
public class LLMS2SQLParser implements SemanticParser {
|
||||||
@@ -22,36 +27,39 @@ public class LLMS2SQLParser implements SemanticParser {
|
|||||||
public void parse(QueryContext queryCtx, ChatContext chatCtx) {
|
public void parse(QueryContext queryCtx, ChatContext chatCtx) {
|
||||||
QueryReq request = queryCtx.getRequest();
|
QueryReq request = queryCtx.getRequest();
|
||||||
LLMRequestService requestService = ContextUtils.getBean(LLMRequestService.class);
|
LLMRequestService requestService = ContextUtils.getBean(LLMRequestService.class);
|
||||||
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
//1.determine whether to skip this parser.
|
//1.determine whether to skip this parser.
|
||||||
if (requestService.check(queryCtx)) {
|
if (requestService.check(queryCtx)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
//2.get modelId from queryCtx and chatCtx.
|
//2.get modelId from queryCtx and chatCtx.
|
||||||
Long modelId = requestService.getModelId(queryCtx, chatCtx, request.getAgentId());
|
ModelCluster modelCluster = requestService.getModelCluster(queryCtx, chatCtx, request.getAgentId());
|
||||||
if (Objects.isNull(modelId) || modelId <= 0) {
|
if (StringUtils.isBlank(modelCluster.getKey())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//3.get agent tool and determine whether to skip this parser.
|
//3.get agent tool and determine whether to skip this parser.
|
||||||
CommonAgentTool commonAgentTool = requestService.getParserTool(request, modelId);
|
CommonAgentTool commonAgentTool = requestService.getParserTool(request, modelCluster.getModelIds());
|
||||||
if (Objects.isNull(commonAgentTool)) {
|
if (Objects.isNull(commonAgentTool)) {
|
||||||
log.info("no tool in this agent, skip {}", LLMS2SQLParser.class);
|
log.info("no tool in this agent, skip {}", LLMS2SQLParser.class);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//4.construct a request, call the API for the large model, and retrieve the results.
|
//4.construct a request, call the API for the large model, and retrieve the results.
|
||||||
List<ElementValue> linkingValues = requestService.getValueList(queryCtx, modelId);
|
List<ElementValue> linkingValues = requestService.getValueList(queryCtx, modelCluster);
|
||||||
LLMReq llmReq = requestService.getLlmReq(queryCtx, modelId, linkingValues);
|
SemanticSchema semanticSchema = semanticService.getSemanticSchema();
|
||||||
LLMResp llmResp = requestService.requestLLM(llmReq, modelId);
|
LLMReq llmReq = requestService.getLlmReq(queryCtx, semanticSchema, modelCluster, linkingValues);
|
||||||
|
LLMResp llmResp = requestService.requestLLM(llmReq, modelCluster.getKey());
|
||||||
|
|
||||||
if (Objects.isNull(llmResp)) {
|
if (Objects.isNull(llmResp)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//5. deduplicate the SQL result list and build parserInfo
|
//5. deduplicate the SQL result list and build parserInfo
|
||||||
|
modelCluster.buildName(semanticSchema.getModelIdToName());
|
||||||
LLMResponseService responseService = ContextUtils.getBean(LLMResponseService.class);
|
LLMResponseService responseService = ContextUtils.getBean(LLMResponseService.class);
|
||||||
Map<String, Double> deduplicationSqlWeight = responseService.getDeduplicationSqlWeight(llmResp);
|
Map<String, Double> deduplicationSqlWeight = responseService.getDeduplicationSqlWeight(llmResp);
|
||||||
ParseResult parseResult = ParseResult.builder()
|
ParseResult parseResult = ParseResult.builder()
|
||||||
.request(request)
|
.request(request)
|
||||||
.modelId(modelId)
|
.modelCluster(modelCluster)
|
||||||
.commonAgentTool(commonAgentTool)
|
.commonAgentTool(commonAgentTool)
|
||||||
.llmReq(llmReq)
|
.llmReq(llmReq)
|
||||||
.llmResp(llmResp)
|
.llmResp(llmResp)
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import java.util.Set;
|
|||||||
|
|
||||||
public interface ModelResolver {
|
public interface ModelResolver {
|
||||||
|
|
||||||
Long resolve(QueryContext queryContext, ChatContext chatCtx, Set<Long> restrictiveModels);
|
String resolve(QueryContext queryContext, ChatContext chatCtx, Set<Long> restrictiveModels);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,21 @@ import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
|||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
||||||
import java.util.List;
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class ParseResult {
|
public class ParseResult {
|
||||||
|
|
||||||
private Long modelId;
|
private ModelCluster modelCluster;
|
||||||
|
|
||||||
private LLMReq llmReq;
|
private LLMReq llmReq;
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
|
||||||
import com.tencent.supersonic.chat.plugin.Plugin;
|
import com.tencent.supersonic.chat.plugin.Plugin;
|
||||||
import com.tencent.supersonic.chat.plugin.PluginManager;
|
import com.tencent.supersonic.chat.plugin.PluginManager;
|
||||||
import com.tencent.supersonic.chat.plugin.PluginParseResult;
|
import com.tencent.supersonic.chat.plugin.PluginParseResult;
|
||||||
@@ -19,8 +18,10 @@ import com.tencent.supersonic.chat.plugin.PluginRecallResult;
|
|||||||
import com.tencent.supersonic.chat.query.QueryManager;
|
import com.tencent.supersonic.chat.query.QueryManager;
|
||||||
import com.tencent.supersonic.chat.query.plugin.PluginSemanticQuery;
|
import com.tencent.supersonic.chat.query.plugin.PluginSemanticQuery;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -58,8 +59,10 @@ public abstract class PluginParser implements SemanticParser {
|
|||||||
}
|
}
|
||||||
for (Long modelId : modelIds) {
|
for (Long modelId : modelIds) {
|
||||||
PluginSemanticQuery pluginQuery = QueryManager.createPluginQuery(plugin.getType());
|
PluginSemanticQuery pluginQuery = QueryManager.createPluginQuery(plugin.getType());
|
||||||
SemanticParseInfo semanticParseInfo = buildSemanticParseInfo(modelId, plugin, queryContext.getRequest(),
|
SemanticParseInfo semanticParseInfo = buildSemanticParseInfo(modelId, plugin,
|
||||||
queryContext.getMapInfo().getMatchedElements(modelId), pluginRecallResult.getDistance());
|
queryContext.getRequest(),
|
||||||
|
queryContext.getModelClusterMapInfo().getMatchedElements(modelId),
|
||||||
|
pluginRecallResult.getDistance());
|
||||||
semanticParseInfo.setQueryMode(pluginQuery.getQueryMode());
|
semanticParseInfo.setQueryMode(pluginQuery.getQueryMode());
|
||||||
semanticParseInfo.setScore(pluginRecallResult.getScore());
|
semanticParseInfo.setScore(pluginRecallResult.getScore());
|
||||||
pluginQuery.setParseInfo(semanticParseInfo);
|
pluginQuery.setParseInfo(semanticParseInfo);
|
||||||
@@ -79,12 +82,9 @@ public abstract class PluginParser implements SemanticParser {
|
|||||||
if (schemaElementMatches == null) {
|
if (schemaElementMatches == null) {
|
||||||
schemaElementMatches = Lists.newArrayList();
|
schemaElementMatches = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
SchemaElement model = new SchemaElement();
|
|
||||||
model.setModel(modelId);
|
|
||||||
model.setId(modelId);
|
|
||||||
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
||||||
semanticParseInfo.setElementMatches(schemaElementMatches);
|
semanticParseInfo.setElementMatches(schemaElementMatches);
|
||||||
semanticParseInfo.setModel(model);
|
semanticParseInfo.setModel(ModelCluster.build(Sets.newHashSet(modelId)));
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
PluginParseResult pluginParseResult = new PluginParseResult();
|
PluginParseResult pluginParseResult = new PluginParseResult();
|
||||||
pluginParseResult.setPlugin(plugin);
|
pluginParseResult.setPlugin(plugin);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import com.tencent.supersonic.chat.service.AgentService;
|
|||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -47,7 +49,11 @@ public class AgentCheckParser implements SemanticParser {
|
|||||||
if (CollectionUtils.isEmpty(tool.getModelIds())) {
|
if (CollectionUtils.isEmpty(tool.getModelIds())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (tool.isContainsAllModel() || tool.getModelIds().contains(query.getParseInfo().getModelId())) {
|
if (tool.isContainsAllModel()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (new HashSet<>(tool.getModelIds())
|
||||||
|
.containsAll(query.getParseInfo().getModel().getModelIds())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,41 @@
|
|||||||
package com.tencent.supersonic.chat.parser.rule;
|
package com.tencent.supersonic.chat.parser.rule;
|
||||||
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.DIMENSION;
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.ENTITY;
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.ID;
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.METRIC;
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.MODEL;
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.VALUE;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import com.tencent.supersonic.chat.query.QueryManager;
|
import com.tencent.supersonic.chat.query.QueryManager;
|
||||||
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
||||||
import com.tencent.supersonic.chat.query.rule.metric.MetricTagQuery;
|
|
||||||
import com.tencent.supersonic.chat.query.rule.metric.MetricModelQuery;
|
import com.tencent.supersonic.chat.query.rule.metric.MetricModelQuery;
|
||||||
import com.tencent.supersonic.chat.query.rule.metric.MetricSemanticQuery;
|
import com.tencent.supersonic.chat.query.rule.metric.MetricSemanticQuery;
|
||||||
|
import com.tencent.supersonic.chat.query.rule.metric.MetricTagQuery;
|
||||||
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
|
import com.tencent.supersonic.chat.utils.ModelClusterBuilder;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
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.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.DIMENSION;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.ENTITY;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.ID;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.METRIC;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.MODEL;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.TAG;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContextInheritParser tries to inherit certain schema elements from context
|
* ContextInheritParser tries to inherit certain schema elements from context
|
||||||
@@ -41,20 +50,22 @@ public class ContextInheritParser implements SemanticParser {
|
|||||||
new AbstractMap.SimpleEntry<>(DIMENSION, Arrays.asList(DIMENSION, VALUE)),
|
new AbstractMap.SimpleEntry<>(DIMENSION, Arrays.asList(DIMENSION, VALUE)),
|
||||||
new AbstractMap.SimpleEntry<>(VALUE, Arrays.asList(VALUE, DIMENSION)),
|
new AbstractMap.SimpleEntry<>(VALUE, Arrays.asList(VALUE, DIMENSION)),
|
||||||
new AbstractMap.SimpleEntry<>(ENTITY, Arrays.asList(ENTITY)),
|
new AbstractMap.SimpleEntry<>(ENTITY, Arrays.asList(ENTITY)),
|
||||||
|
new AbstractMap.SimpleEntry<>(TAG, Arrays.asList(TAG)),
|
||||||
new AbstractMap.SimpleEntry<>(MODEL, Arrays.asList(MODEL)),
|
new AbstractMap.SimpleEntry<>(MODEL, Arrays.asList(MODEL)),
|
||||||
new AbstractMap.SimpleEntry<>(ID, Arrays.asList(ID))
|
new AbstractMap.SimpleEntry<>(ID, Arrays.asList(ID))
|
||||||
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse(QueryContext queryContext, ChatContext chatContext) {
|
public void parse(QueryContext queryContext, ChatContext chatContext) {
|
||||||
if (!shouldInherit(queryContext, chatContext)) {
|
if (!shouldInherit(queryContext)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ModelCluster modelCluster = getMatchedModelCluster(queryContext, chatContext);
|
||||||
Long modelId = chatContext.getParseInfo().getModelId();
|
if (modelCluster == null) {
|
||||||
List<SchemaElementMatch> elementMatches = queryContext.getMapInfo()
|
return;
|
||||||
.getMatchedElements(modelId);
|
}
|
||||||
|
List<SchemaElementMatch> elementMatches = queryContext.getModelClusterMapInfo()
|
||||||
|
.getMatchedElements(modelCluster.getKey());
|
||||||
List<SchemaElementMatch> matchesToInherit = new ArrayList<>();
|
List<SchemaElementMatch> matchesToInherit = new ArrayList<>();
|
||||||
for (SchemaElementMatch match : chatContext.getParseInfo().getElementMatches()) {
|
for (SchemaElementMatch match : chatContext.getParseInfo().getElementMatches()) {
|
||||||
SchemaElementType matchType = match.getElement().getType();
|
SchemaElementType matchType = match.getElement().getType();
|
||||||
@@ -69,18 +80,18 @@ public class ContextInheritParser implements SemanticParser {
|
|||||||
|
|
||||||
List<RuleSemanticQuery> queries = RuleSemanticQuery.resolve(elementMatches, queryContext);
|
List<RuleSemanticQuery> queries = RuleSemanticQuery.resolve(elementMatches, queryContext);
|
||||||
for (RuleSemanticQuery query : queries) {
|
for (RuleSemanticQuery query : queries) {
|
||||||
query.fillParseInfo(modelId, queryContext, chatContext);
|
query.fillParseInfo(chatContext);
|
||||||
if (existSameQuery(query.getParseInfo().getModelId(), query.getQueryMode(), queryContext)) {
|
if (existSameQuery(query.getParseInfo().getModelClusterKey(), query.getQueryMode(), queryContext)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
queryContext.getCandidateQueries().add(query);
|
queryContext.getCandidateQueries().add(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean existSameQuery(Long modelId, String queryMode, QueryContext queryContext) {
|
private boolean existSameQuery(String modelClusterKey, String queryMode, QueryContext queryContext) {
|
||||||
for (SemanticQuery semanticQuery : queryContext.getCandidateQueries()) {
|
for (SemanticQuery semanticQuery : queryContext.getCandidateQueries()) {
|
||||||
if (semanticQuery.getQueryMode().equals(queryMode)
|
if (semanticQuery.getQueryMode().equals(queryMode)
|
||||||
&& semanticQuery.getParseInfo().getModelId().equals(modelId)) {
|
&& semanticQuery.getParseInfo().getModelClusterKey().equals(modelClusterKey)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,23 +112,34 @@ public class ContextInheritParser implements SemanticParser {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean shouldInherit(QueryContext queryContext, ChatContext chatContext) {
|
protected boolean shouldInherit(QueryContext queryContext) {
|
||||||
Long contextModelId = chatContext.getParseInfo().getModelId();
|
|
||||||
// if map info doesn't contain the same Model of the context,
|
|
||||||
// no inheritance could be done
|
|
||||||
if (queryContext.getMapInfo().getMatchedElements(contextModelId) == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if candidates only have MetricModel mode, count in context
|
// if candidates only have MetricModel mode, count in context
|
||||||
List<SemanticQuery> metricModelQueries = queryContext.getCandidateQueries().stream()
|
List<SemanticQuery> metricModelQueries = queryContext.getCandidateQueries().stream()
|
||||||
.filter(query -> query instanceof MetricModelQuery).collect(
|
.filter(query -> query instanceof MetricModelQuery).collect(
|
||||||
Collectors.toList());
|
Collectors.toList());
|
||||||
if (metricModelQueries.size() == queryContext.getCandidateQueries().size()) {
|
return metricModelQueries.size() == queryContext.getCandidateQueries().size();
|
||||||
return true;
|
}
|
||||||
} else {
|
|
||||||
return queryContext.getCandidateQueries().size() == 0;
|
protected ModelCluster getMatchedModelCluster(QueryContext queryContext, ChatContext chatContext) {
|
||||||
|
String contextModelClusterKey = chatContext.getParseInfo().getModelClusterKey();
|
||||||
|
if (StringUtils.isBlank(contextModelClusterKey)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
|
SemanticSchema semanticSchema = semanticService.getSemanticSchema();
|
||||||
|
List<ModelCluster> allModelClusters = ModelClusterBuilder.buildModelClusters(semanticSchema);
|
||||||
|
Set<String> queryModelClusters = queryContext.getModelClusterMapInfo().getMatchedModelClusters();
|
||||||
|
ModelCluster contextModelCluster = ModelCluster.build(contextModelClusterKey);
|
||||||
|
for (String cluster : queryModelClusters) {
|
||||||
|
ModelCluster queryModelCluster = ModelCluster.build(cluster);
|
||||||
|
for (ModelCluster modelCluster : allModelClusters) {
|
||||||
|
if (modelCluster.getModelIds().containsAll(contextModelCluster.getModelIds())
|
||||||
|
&& modelCluster.getModelIds().containsAll(queryModelCluster.getModelIds())) {
|
||||||
|
return queryModelCluster;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package com.tencent.supersonic.chat.parser.rule;
|
package com.tencent.supersonic.chat.parser.rule;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
import com.tencent.supersonic.chat.api.component.SemanticParser;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaModelClusterMapInfo;
|
||||||
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QueryModeParser resolves a specific query mode according to co-appearance
|
* QueryModeParser resolves a specific query mode according to co-appearance
|
||||||
* of certain schema element types.
|
* of certain schema element types.
|
||||||
@@ -20,13 +19,13 @@ public class QueryModeParser implements SemanticParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse(QueryContext queryContext, ChatContext chatContext) {
|
public void parse(QueryContext queryContext, ChatContext chatContext) {
|
||||||
SchemaMapInfo mapInfo = queryContext.getMapInfo();
|
SchemaModelClusterMapInfo modelClusterMapInfo = queryContext.getModelClusterMapInfo();
|
||||||
// iterate all schemaElementMatches to resolve query mode
|
// iterate all schemaElementMatches to resolve query mode
|
||||||
for (Long modelId : mapInfo.getMatchedModels()) {
|
for (String modelClusterKey : modelClusterMapInfo.getMatchedModelClusters()) {
|
||||||
List<SchemaElementMatch> elementMatches = mapInfo.getMatchedElements(modelId);
|
List<SchemaElementMatch> elementMatches = modelClusterMapInfo.getMatchedElements(modelClusterKey);
|
||||||
List<RuleSemanticQuery> queries = RuleSemanticQuery.resolve(elementMatches, queryContext);
|
List<RuleSemanticQuery> queries = RuleSemanticQuery.resolve(elementMatches, queryContext);
|
||||||
for (RuleSemanticQuery query : queries) {
|
for (RuleSemanticQuery query : queries) {
|
||||||
query.fillParseInfo(modelId, queryContext, chatContext);
|
query.fillParseInfo(chatContext);
|
||||||
queryContext.getCandidateQueries().add(query);
|
queryContext.getCandidateQueries().add(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,24 +3,23 @@ package com.tencent.supersonic.chat.postprocessor;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.RelateSchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.RelateSchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
import com.tencent.supersonic.common.pojo.QueryType;
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserRemoveHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserRemoveHelper;
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
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;
|
||||||
@@ -34,17 +33,15 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public void process(QueryContext queryContext) {
|
public void process(QueryContext queryContext) {
|
||||||
List<SemanticQuery> semanticQueries = queryContext.getCandidateQueries();
|
List<SemanticQuery> semanticQueries = queryContext.getCandidateQueries();
|
||||||
Map<Long, ModelSchema> modelSchemaMap = new HashMap<>();
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
|
SemanticSchema semanticSchema = semanticService.getSemanticSchema();
|
||||||
for (SemanticQuery semanticQuery : semanticQueries) {
|
for (SemanticQuery semanticQuery : semanticQueries) {
|
||||||
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
||||||
if (!QueryType.METRIC.equals(parseInfo.getQueryType())) {
|
if (!QueryType.METRIC.equals(parseInfo.getQueryType())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SchemaService schemaService = ContextUtils.getBean(SchemaService.class);
|
String correctSqlProcessed = processCorrectSql(parseInfo, semanticSchema);
|
||||||
ModelSchema modelSchema = schemaService.getModelSchema(parseInfo.getModelId());
|
parseInfo.getSqlInfo().setCorrectS2SQL(correctSqlProcessed);
|
||||||
String processedSql = processCorrectSql(parseInfo.getSqlInfo().getCorrectS2SQL(), modelSchema);
|
|
||||||
parseInfo.getSqlInfo().setCorrectS2SQL(processedSql);
|
|
||||||
modelSchemaMap.put(modelSchema.getModel().getModel(), modelSchema);
|
|
||||||
}
|
}
|
||||||
semanticQueries.removeIf(semanticQuery -> {
|
semanticQueries.removeIf(semanticQuery -> {
|
||||||
if (!QueryType.METRIC.equals(semanticQuery.getParseInfo().getQueryType())) {
|
if (!QueryType.METRIC.equals(semanticQuery.getParseInfo().getQueryType())) {
|
||||||
@@ -54,14 +51,14 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
if (StringUtils.isBlank(correctSql)) {
|
if (StringUtils.isBlank(correctSql)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !checkHasMetric(correctSql, modelSchemaMap.get(semanticQuery.getParseInfo().getModelId()));
|
return !checkHasMetric(correctSql, semanticSchema);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String processCorrectSql(String correctSql, ModelSchema modelSchema) {
|
public String processCorrectSql(SemanticParseInfo parseInfo, SemanticSchema semanticSchema) {
|
||||||
|
String correctSql = parseInfo.getSqlInfo().getCorrectS2SQL();
|
||||||
List<String> groupByFields = SqlParserSelectHelper.getGroupByFields(correctSql);
|
List<String> groupByFields = SqlParserSelectHelper.getGroupByFields(correctSql);
|
||||||
List<String> metricFields = SqlParserSelectHelper.getAggregateFields(correctSql)
|
List<String> metricFields = SqlParserSelectHelper.getAggregateFields(correctSql);
|
||||||
.stream().filter(metricField -> !metricField.equals("*")).collect(Collectors.toList());
|
|
||||||
List<String> whereFields = SqlParserSelectHelper.getWhereFields(correctSql);
|
List<String> whereFields = SqlParserSelectHelper.getWhereFields(correctSql);
|
||||||
List<String> dimensionFields = getDimensionFields(groupByFields, whereFields);
|
List<String> dimensionFields = getDimensionFields(groupByFields, whereFields);
|
||||||
if (CollectionUtils.isEmpty(metricFields) || StringUtils.isBlank(correctSql)) {
|
if (CollectionUtils.isEmpty(metricFields) || StringUtils.isBlank(correctSql)) {
|
||||||
@@ -71,35 +68,33 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
Set<String> groupByToRemove = Sets.newHashSet();
|
Set<String> groupByToRemove = Sets.newHashSet();
|
||||||
Set<String> whereFieldsToRemove = Sets.newHashSet();
|
Set<String> whereFieldsToRemove = Sets.newHashSet();
|
||||||
for (String metricName : metricFields) {
|
for (String metricName : metricFields) {
|
||||||
SchemaElement metricElement = modelSchema.getElement(SchemaElementType.METRIC, metricName);
|
SchemaElement metricElement = semanticSchema.getElementByName(SchemaElementType.METRIC, metricName);
|
||||||
if (metricElement == null) {
|
if (metricElement == null) {
|
||||||
metricToRemove.add(metricName);
|
metricToRemove.add(metricName);
|
||||||
}
|
}
|
||||||
if (!checkNecessaryDimension(metricElement, modelSchema, dimensionFields)) {
|
if (!checkNecessaryDimension(metricElement, semanticSchema, dimensionFields)) {
|
||||||
metricToRemove.add(metricName);
|
metricToRemove.add(metricName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String dimensionName : whereFields) {
|
for (String dimensionName : whereFields) {
|
||||||
if (TimeDimensionEnum.getNameList().contains(dimensionName)
|
if (TimeDimensionEnum.getNameList().contains(dimensionName)) {
|
||||||
|| TimeDimensionEnum.getChNameList().contains(dimensionName)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!checkInModelSchema(dimensionName, SchemaElementType.DIMENSION, modelSchema)) {
|
if (!checkInModelSchema(dimensionName, SchemaElementType.DIMENSION, semanticSchema)) {
|
||||||
whereFieldsToRemove.add(dimensionName);
|
whereFieldsToRemove.add(dimensionName);
|
||||||
}
|
}
|
||||||
if (!checkDrillDownDimension(dimensionName, metricFields, modelSchema)) {
|
if (!checkDrillDownDimension(dimensionName, metricFields, semanticSchema)) {
|
||||||
whereFieldsToRemove.add(dimensionName);
|
whereFieldsToRemove.add(dimensionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String dimensionName : groupByFields) {
|
for (String dimensionName : groupByFields) {
|
||||||
if (TimeDimensionEnum.getNameList().contains(dimensionName)
|
if (TimeDimensionEnum.getNameList().contains(dimensionName)) {
|
||||||
|| TimeDimensionEnum.getChNameList().contains(dimensionName)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!checkInModelSchema(dimensionName, SchemaElementType.DIMENSION, modelSchema)) {
|
if (!checkInModelSchema(dimensionName, SchemaElementType.DIMENSION, semanticSchema)) {
|
||||||
groupByToRemove.add(dimensionName);
|
groupByToRemove.add(dimensionName);
|
||||||
}
|
}
|
||||||
if (!checkDrillDownDimension(dimensionName, metricFields, modelSchema)) {
|
if (!checkDrillDownDimension(dimensionName, metricFields, semanticSchema)) {
|
||||||
groupByToRemove.add(dimensionName);
|
groupByToRemove.add(dimensionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,9 +106,9 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
* To check whether the dimension bound to the metric exists,
|
* To check whether the dimension bound to the metric exists,
|
||||||
* eg: metric like UV is calculated in a certain dimension, it cannot be used on other dimensions.
|
* eg: metric like UV is calculated in a certain dimension, it cannot be used on other dimensions.
|
||||||
*/
|
*/
|
||||||
private boolean checkNecessaryDimension(SchemaElement metric, ModelSchema modelSchema,
|
private boolean checkNecessaryDimension(SchemaElement metric, SemanticSchema semanticSchema,
|
||||||
List<String> dimensionFields) {
|
List<String> dimensionFields) {
|
||||||
List<String> necessaryDimensions = getNecessaryDimensionNames(metric, modelSchema);
|
List<String> necessaryDimensions = getNecessaryDimensionNames(metric, semanticSchema);
|
||||||
if (CollectionUtils.isEmpty(necessaryDimensions)) {
|
if (CollectionUtils.isEmpty(necessaryDimensions)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -130,8 +125,8 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
* eg: some descriptive dimensions are not suitable as drill-down dimensions
|
* eg: some descriptive dimensions are not suitable as drill-down dimensions
|
||||||
*/
|
*/
|
||||||
private boolean checkDrillDownDimension(String dimensionName, List<String> metrics,
|
private boolean checkDrillDownDimension(String dimensionName, List<String> metrics,
|
||||||
ModelSchema modelSchema) {
|
SemanticSchema semanticSchema) {
|
||||||
List<SchemaElement> metricElements = modelSchema.getMetrics().stream()
|
List<SchemaElement> metricElements = semanticSchema.getMetrics().stream()
|
||||||
.filter(schemaElement -> metrics.contains(schemaElement.getName()))
|
.filter(schemaElement -> metrics.contains(schemaElement.getName()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (CollectionUtils.isEmpty(metricElements)) {
|
if (CollectionUtils.isEmpty(metricElements)) {
|
||||||
@@ -142,7 +137,7 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
.map(schemaElement -> schemaElement.getRelateSchemaElements().stream()
|
.map(schemaElement -> schemaElement.getRelateSchemaElements().stream()
|
||||||
.map(RelateSchemaElement::getDimensionId).collect(Collectors.toList()))
|
.map(RelateSchemaElement::getDimensionId).collect(Collectors.toList()))
|
||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.map(id -> convertDimensionIdToName(id, modelSchema))
|
.map(id -> convertDimensionIdToName(id, semanticSchema))
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
//if no metric has drill down dimension, return true
|
//if no metric has drill down dimension, return true
|
||||||
@@ -153,9 +148,9 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
return relateDimensions.contains(dimensionName);
|
return relateDimensions.contains(dimensionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getNecessaryDimensionNames(SchemaElement metric, ModelSchema modelSchema) {
|
private List<String> getNecessaryDimensionNames(SchemaElement metric, SemanticSchema semanticSchema) {
|
||||||
List<Long> necessaryDimensionIds = getNecessaryDimensions(metric);
|
List<Long> necessaryDimensionIds = getNecessaryDimensions(metric);
|
||||||
return necessaryDimensionIds.stream().map(id -> convertDimensionIdToName(id, modelSchema))
|
return necessaryDimensionIds.stream().map(id -> convertDimensionIdToName(id, semanticSchema))
|
||||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
.filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,23 +178,23 @@ public class MetricCheckPostProcessor implements PostProcessor {
|
|||||||
return dimensionFields;
|
return dimensionFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String convertDimensionIdToName(Long id, ModelSchema modelSchema) {
|
private String convertDimensionIdToName(Long id, SemanticSchema semanticSchema) {
|
||||||
SchemaElement schemaElement = modelSchema.getElement(SchemaElementType.DIMENSION, id);
|
SchemaElement schemaElement = semanticSchema.getElement(SchemaElementType.DIMENSION, id);
|
||||||
if (schemaElement == null) {
|
if (schemaElement == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return schemaElement.getName();
|
return schemaElement.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkInModelSchema(String name, SchemaElementType type, ModelSchema modelSchema) {
|
private boolean checkInModelSchema(String name, SchemaElementType type, SemanticSchema semanticSchema) {
|
||||||
SchemaElement schemaElement = modelSchema.getElement(type, name);
|
SchemaElement schemaElement = semanticSchema.getElementByName(type, name);
|
||||||
return schemaElement != null;
|
return schemaElement != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkHasMetric(String correctSql, ModelSchema modelSchema) {
|
private boolean checkHasMetric(String correctSql, SemanticSchema semanticSchema) {
|
||||||
List<String> selectFields = SqlParserSelectHelper.getSelectFields(correctSql);
|
List<String> selectFields = SqlParserSelectHelper.getSelectFields(correctSql);
|
||||||
List<String> aggFields = SqlParserSelectHelper.getAggregateFields(correctSql);
|
List<String> aggFields = SqlParserSelectHelper.getAggregateFields(correctSql);
|
||||||
List<String> collect = modelSchema.getMetrics().stream()
|
List<String> collect = semanticSchema.getMetrics().stream()
|
||||||
.map(SchemaElement::getName).collect(Collectors.toList());
|
.map(SchemaElement::getName).collect(Collectors.toList());
|
||||||
for (String field : selectFields) {
|
for (String field : selectFields) {
|
||||||
if (collect.contains(field)) {
|
if (collect.contains(field)) {
|
||||||
|
|||||||
@@ -1,17 +1,40 @@
|
|||||||
package com.tencent.supersonic.chat.postprocessor;
|
package com.tencent.supersonic.chat.postprocessor;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.service.ParseInfoService;
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.response.SqlInfo;
|
||||||
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import com.tencent.supersonic.common.util.jsqlparser.FieldExpression;
|
||||||
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
||||||
|
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
||||||
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update parse info from correct sql
|
* update parse info from correct sql
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class ParseInfoUpdateProcessor implements PostProcessor {
|
public class ParseInfoUpdateProcessor implements PostProcessor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -20,10 +43,174 @@ public class ParseInfoUpdateProcessor implements PostProcessor {
|
|||||||
if (CollectionUtils.isEmpty(candidateQueries)) {
|
if (CollectionUtils.isEmpty(candidateQueries)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ParseInfoService parseInfoService = ContextUtils.getBean(ParseInfoService.class);
|
|
||||||
List<SemanticParseInfo> candidateParses = candidateQueries.stream()
|
List<SemanticParseInfo> candidateParses = candidateQueries.stream()
|
||||||
.map(SemanticQuery::getParseInfo).collect(Collectors.toList());
|
.map(SemanticQuery::getParseInfo).collect(Collectors.toList());
|
||||||
candidateParses.forEach(parseInfoService::updateParseInfo);
|
candidateParses.forEach(this::updateParseInfo);
|
||||||
|
}
|
||||||
|
public void updateParseInfo(SemanticParseInfo parseInfo) {
|
||||||
|
SqlInfo sqlInfo = parseInfo.getSqlInfo();
|
||||||
|
String correctS2SQL = sqlInfo.getCorrectS2SQL();
|
||||||
|
if (StringUtils.isBlank(correctS2SQL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// if S2SQL equals correctS2SQL, than not update the parseInfo.
|
||||||
|
if (correctS2SQL.equals(sqlInfo.getS2SQL())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FieldExpression> expressions = SqlParserSelectHelper.getFilterExpression(correctS2SQL);
|
||||||
|
//set dataInfo
|
||||||
|
try {
|
||||||
|
if (!org.apache.commons.collections.CollectionUtils.isEmpty(expressions)) {
|
||||||
|
DateConf dateInfo = getDateInfo(expressions);
|
||||||
|
if (dateInfo != null && parseInfo.getDateInfo() == null) {
|
||||||
|
parseInfo.setDateInfo(dateInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("set dateInfo error :", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//set filter
|
||||||
|
try {
|
||||||
|
Map<String, SchemaElement> fieldNameToElement = getNameToElement(parseInfo.getModel().getModelIds());
|
||||||
|
List<QueryFilter> result = getDimensionFilter(fieldNameToElement, expressions);
|
||||||
|
parseInfo.getDimensionFilters().addAll(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("set dimensionFilter error :", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
|
|
||||||
|
if (Objects.isNull(semanticSchema)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> allFields = getFieldsExceptDate(SqlParserSelectHelper.getAllFields(sqlInfo.getCorrectS2SQL()));
|
||||||
|
Set<SchemaElement> metrics = getElements(parseInfo.getModel().getModelIds(),
|
||||||
|
allFields, semanticSchema.getMetrics());
|
||||||
|
parseInfo.setMetrics(metrics);
|
||||||
|
|
||||||
|
if (SqlParserSelectFunctionHelper.hasAggregateFunction(sqlInfo.getCorrectS2SQL())) {
|
||||||
|
parseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
List<String> groupByFields = SqlParserSelectHelper.getGroupByFields(sqlInfo.getCorrectS2SQL());
|
||||||
|
List<String> groupByDimensions = getFieldsExceptDate(groupByFields);
|
||||||
|
parseInfo.setDimensions(
|
||||||
|
getElements(parseInfo.getModel().getModelIds(), groupByDimensions, semanticSchema.getDimensions()));
|
||||||
|
} else {
|
||||||
|
parseInfo.setQueryType(QueryType.TAG);
|
||||||
|
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getCorrectS2SQL());
|
||||||
|
List<String> selectDimensions = getFieldsExceptDate(selectFields);
|
||||||
|
parseInfo.setDimensions(
|
||||||
|
getElements(parseInfo.getModel().getModelIds(), selectDimensions, semanticSchema.getDimensions()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<SchemaElement> getElements(Set<Long> modelIds, List<String> allFields, List<SchemaElement> elements) {
|
||||||
|
return elements.stream()
|
||||||
|
.filter(schemaElement -> modelIds.contains(schemaElement.getModel())
|
||||||
|
&& allFields.contains(schemaElement.getName())
|
||||||
|
).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getFieldsExceptDate(List<String> allFields) {
|
||||||
|
if (org.springframework.util.CollectionUtils.isEmpty(allFields)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return allFields.stream()
|
||||||
|
.filter(entry -> !TimeDimensionEnum.DAY.getChName().equalsIgnoreCase(entry))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<QueryFilter> getDimensionFilter(Map<String, SchemaElement> fieldNameToElement,
|
||||||
|
List<FieldExpression> fieldExpressions) {
|
||||||
|
List<QueryFilter> result = Lists.newArrayList();
|
||||||
|
for (FieldExpression expression : fieldExpressions) {
|
||||||
|
QueryFilter dimensionFilter = new QueryFilter();
|
||||||
|
dimensionFilter.setValue(expression.getFieldValue());
|
||||||
|
SchemaElement schemaElement = fieldNameToElement.get(expression.getFieldName());
|
||||||
|
if (Objects.isNull(schemaElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
dimensionFilter.setName(schemaElement.getName());
|
||||||
|
dimensionFilter.setBizName(schemaElement.getBizName());
|
||||||
|
dimensionFilter.setElementID(schemaElement.getId());
|
||||||
|
|
||||||
|
FilterOperatorEnum operatorEnum = FilterOperatorEnum.getSqlOperator(expression.getOperator());
|
||||||
|
dimensionFilter.setOperator(operatorEnum);
|
||||||
|
dimensionFilter.setFunction(expression.getFunction());
|
||||||
|
result.add(dimensionFilter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateConf getDateInfo(List<FieldExpression> fieldExpressions) {
|
||||||
|
List<FieldExpression> dateExpressions = fieldExpressions.stream()
|
||||||
|
.filter(expression -> TimeDimensionEnum.DAY.getChName().equalsIgnoreCase(expression.getFieldName()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (org.apache.commons.collections.CollectionUtils.isEmpty(dateExpressions)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DateConf dateInfo = new DateConf();
|
||||||
|
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
||||||
|
FieldExpression firstExpression = dateExpressions.get(0);
|
||||||
|
|
||||||
|
FilterOperatorEnum firstOperator = FilterOperatorEnum.getSqlOperator(firstExpression.getOperator());
|
||||||
|
if (FilterOperatorEnum.EQUALS.equals(firstOperator) && Objects.nonNull(firstExpression.getFieldValue())) {
|
||||||
|
dateInfo.setStartDate(firstExpression.getFieldValue().toString());
|
||||||
|
dateInfo.setEndDate(firstExpression.getFieldValue().toString());
|
||||||
|
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
||||||
|
return dateInfo;
|
||||||
|
}
|
||||||
|
if (containOperators(firstExpression, firstOperator, FilterOperatorEnum.GREATER_THAN,
|
||||||
|
FilterOperatorEnum.GREATER_THAN_EQUALS)) {
|
||||||
|
dateInfo.setStartDate(firstExpression.getFieldValue().toString());
|
||||||
|
if (hasSecondDate(dateExpressions)) {
|
||||||
|
dateInfo.setEndDate(dateExpressions.get(1).getFieldValue().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (containOperators(firstExpression, firstOperator, FilterOperatorEnum.MINOR_THAN,
|
||||||
|
FilterOperatorEnum.MINOR_THAN_EQUALS)) {
|
||||||
|
dateInfo.setEndDate(firstExpression.getFieldValue().toString());
|
||||||
|
if (hasSecondDate(dateExpressions)) {
|
||||||
|
dateInfo.setStartDate(dateExpressions.get(1).getFieldValue().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dateInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containOperators(FieldExpression expression, FilterOperatorEnum firstOperator,
|
||||||
|
FilterOperatorEnum... operatorEnums) {
|
||||||
|
return (Arrays.asList(operatorEnums).contains(firstOperator) && Objects.nonNull(expression.getFieldValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasSecondDate(List<FieldExpression> dateExpressions) {
|
||||||
|
return dateExpressions.size() > 1 && Objects.nonNull(dateExpressions.get(1).getFieldValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, SchemaElement> getNameToElement(Set<Long> modelIds) {
|
||||||
|
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
||||||
|
List<SchemaElement> dimensions = semanticSchema.getDimensions(modelIds);
|
||||||
|
List<SchemaElement> metrics = semanticSchema.getMetrics(modelIds);
|
||||||
|
|
||||||
|
List<SchemaElement> allElements = Lists.newArrayList();
|
||||||
|
allElements.addAll(dimensions);
|
||||||
|
allElements.addAll(metrics);
|
||||||
|
//support alias
|
||||||
|
return allElements.stream()
|
||||||
|
.flatMap(schemaElement -> {
|
||||||
|
Set<Pair<String, SchemaElement>> result = new HashSet<>();
|
||||||
|
result.add(Pair.of(schemaElement.getName(), schemaElement));
|
||||||
|
List<String> aliasList = schemaElement.getAlias();
|
||||||
|
if (!org.springframework.util.CollectionUtils.isEmpty(aliasList)) {
|
||||||
|
for (String alias : aliasList) {
|
||||||
|
result.add(Pair.of(alias, schemaElement));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.stream();
|
||||||
|
})
|
||||||
|
.collect(Collectors.toMap(pair -> pair.getLeft(), pair -> pair.getRight(), (value1, value2) -> value2));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,15 +20,16 @@ import com.tencent.supersonic.semantic.api.model.response.ExplainResp;
|
|||||||
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
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.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ToString
|
@ToString
|
||||||
@@ -49,7 +50,7 @@ public abstract class BaseSemanticQuery implements SemanticQuery, Serializable {
|
|||||||
explainSqlReq = ExplainSqlReq.builder()
|
explainSqlReq = ExplainSqlReq.builder()
|
||||||
.queryTypeEnum(QueryTypeEnum.SQL)
|
.queryTypeEnum(QueryTypeEnum.SQL)
|
||||||
.queryReq(QueryReqBuilder.buildS2SQLReq(
|
.queryReq(QueryReqBuilder.buildS2SQLReq(
|
||||||
sqlInfo.getCorrectS2SQL(), parseInfo.getModelId()
|
sqlInfo.getCorrectS2SQL(), parseInfo.getModel().getModelIds()
|
||||||
))
|
))
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
@@ -86,7 +87,7 @@ public abstract class BaseSemanticQuery implements SemanticQuery, Serializable {
|
|||||||
protected void convertBizNameToName(QueryStructReq queryStructReq) {
|
protected void convertBizNameToName(QueryStructReq queryStructReq) {
|
||||||
SchemaService schemaService = ContextUtils.getBean(SchemaService.class);
|
SchemaService schemaService = ContextUtils.getBean(SchemaService.class);
|
||||||
Map<String, String> bizNameToName = schemaService.getSemanticSchema()
|
Map<String, String> bizNameToName = schemaService.getSemanticSchema()
|
||||||
.getBizNameToName(queryStructReq.getModelId());
|
.getBizNameToName(queryStructReq.getModelIdSet());
|
||||||
bizNameToName.putAll(TimeDimensionEnum.getNameToNameMap());
|
bizNameToName.putAll(TimeDimensionEnum.getNameToNameMap());
|
||||||
|
|
||||||
List<Order> orders = queryStructReq.getOrders();
|
List<Order> orders = queryStructReq.getOrders();
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
package com.tencent.supersonic.chat.query;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
|
||||||
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class QueryRanker {
|
|
||||||
|
|
||||||
@Value("${candidate.top.size:5}")
|
|
||||||
private int candidateTopSize;
|
|
||||||
|
|
||||||
public List<SemanticQuery> rank(List<SemanticQuery> candidateQueries) {
|
|
||||||
log.debug("pick before [{}]", candidateQueries);
|
|
||||||
if (CollectionUtils.isEmpty(candidateQueries)) {
|
|
||||||
return candidateQueries;
|
|
||||||
}
|
|
||||||
List<SemanticQuery> selectedQueries = new ArrayList<>();
|
|
||||||
if (candidateQueries.size() == 1) {
|
|
||||||
selectedQueries.addAll(candidateQueries);
|
|
||||||
} else {
|
|
||||||
selectedQueries = getTopCandidateQuery(candidateQueries);
|
|
||||||
}
|
|
||||||
generateParseInfoId(selectedQueries);
|
|
||||||
log.debug("pick after [{}]", selectedQueries);
|
|
||||||
return selectedQueries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SemanticQuery> getTopCandidateQuery(List<SemanticQuery> semanticQueries) {
|
|
||||||
return semanticQueries.stream()
|
|
||||||
.filter(query -> !checkFullyInherited(query))
|
|
||||||
.sorted((o1, o2) -> {
|
|
||||||
if (o1.getParseInfo().getScore() < o2.getParseInfo().getScore()) {
|
|
||||||
return 1;
|
|
||||||
} else if (o1.getParseInfo().getScore() > o2.getParseInfo().getScore()) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}).limit(candidateTopSize)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateParseInfoId(List<SemanticQuery> semanticQueries) {
|
|
||||||
for (int i = 0; i < semanticQueries.size(); i++) {
|
|
||||||
SemanticQuery query = semanticQueries.get(i);
|
|
||||||
query.getParseInfo().setId(i + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkFullyInherited(SemanticQuery query) {
|
|
||||||
SemanticParseInfo parseInfo = query.getParseInfo();
|
|
||||||
if (!(query instanceof RuleSemanticQuery)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (SchemaElementMatch match : parseInfo.getElementMatches()) {
|
|
||||||
if (!match.isInherited()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parseInfo.getDateInfo() == null || parseInfo.getDateInfo().isInherited();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,12 +12,13 @@ import com.tencent.supersonic.chat.utils.QueryReqBuilder;
|
|||||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
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 lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -40,7 +41,7 @@ public class S2SQLQuery extends LLMSemanticQuery {
|
|||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
String querySql = parseInfo.getSqlInfo().getCorrectS2SQL();
|
String querySql = parseInfo.getSqlInfo().getCorrectS2SQL();
|
||||||
QueryS2SQLReq queryS2SQLReq = QueryReqBuilder.buildS2SQLReq(querySql, parseInfo.getModelId());
|
QueryS2SQLReq queryS2SQLReq = QueryReqBuilder.buildS2SQLReq(querySql, parseInfo.getModel().getModelIds());
|
||||||
QueryResultWithSchemaResp queryResp = semanticInterpreter.queryByS2SQL(queryS2SQLReq, user);
|
QueryResultWithSchemaResp queryResp = semanticInterpreter.queryByS2SQL(queryS2SQLReq, user);
|
||||||
|
|
||||||
log.info("queryByS2SQL cost:{},querySql:{}", System.currentTimeMillis() - startTime, querySql);
|
log.info("queryByS2SQL cost:{},querySql:{}", System.currentTimeMillis() - startTime, querySql);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.tencent.supersonic.chat.query.plugin.webpage;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
||||||
@@ -17,17 +16,15 @@ import com.tencent.supersonic.chat.query.plugin.ParamOption;
|
|||||||
import com.tencent.supersonic.chat.query.plugin.PluginSemanticQuery;
|
import com.tencent.supersonic.chat.query.plugin.PluginSemanticQuery;
|
||||||
import com.tencent.supersonic.chat.query.plugin.WebBase;
|
import com.tencent.supersonic.chat.query.plugin.WebBase;
|
||||||
import com.tencent.supersonic.chat.query.plugin.WebBaseResult;
|
import com.tencent.supersonic.chat.query.plugin.WebBaseResult;
|
||||||
import com.tencent.supersonic.chat.service.SemanticService;
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -53,9 +50,6 @@ public class WebPageQuery extends PluginSemanticQuery {
|
|||||||
PluginParseResult.class);
|
PluginParseResult.class);
|
||||||
WebPageResponse webPageResponse = buildResponse(pluginParseResult);
|
WebPageResponse webPageResponse = buildResponse(pluginParseResult);
|
||||||
queryResult.setResponse(webPageResponse);
|
queryResult.setResponse(webPageResponse);
|
||||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
|
||||||
ModelSchema modelSchema = semanticService.getModelSchema(parseInfo.getModelId());
|
|
||||||
parseInfo.setModel(modelSchema.getModel());
|
|
||||||
queryResult.setQueryState(QueryState.SUCCESS);
|
queryResult.setQueryState(QueryState.SUCCESS);
|
||||||
return queryResult;
|
return queryResult;
|
||||||
}
|
}
|
||||||
@@ -79,7 +73,8 @@ public class WebPageQuery extends PluginSemanticQuery {
|
|||||||
List<ParamOption> paramOptions = Lists.newArrayList();
|
List<ParamOption> paramOptions = Lists.newArrayList();
|
||||||
if (!CollectionUtils.isEmpty(webPage.getParamOptions()) && !CollectionUtils.isEmpty(elementValueMap)) {
|
if (!CollectionUtils.isEmpty(webPage.getParamOptions()) && !CollectionUtils.isEmpty(elementValueMap)) {
|
||||||
for (ParamOption paramOption : webPage.getParamOptions()) {
|
for (ParamOption paramOption : webPage.getParamOptions()) {
|
||||||
if (paramOption.getModelId() != null && !paramOption.getModelId().equals(parseInfo.getModelId())) {
|
if (paramOption.getModelId() != null
|
||||||
|
&& !parseInfo.getModel().getModelIds().contains(paramOption.getModelId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
paramOptions.add(paramOption);
|
paramOptions.add(paramOption);
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ package com.tencent.supersonic.chat.query.rule;
|
|||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryState;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryState;
|
||||||
@@ -19,21 +19,25 @@ import com.tencent.supersonic.chat.query.QueryManager;
|
|||||||
import com.tencent.supersonic.chat.service.SemanticService;
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
import com.tencent.supersonic.chat.utils.QueryReqBuilder;
|
import com.tencent.supersonic.chat.utils.QueryReqBuilder;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import lombok.ToString;
|
import java.util.Set;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import java.util.stream.Collectors;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ToString
|
@ToString
|
||||||
@@ -56,13 +60,13 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
initS2SqlByStruct();
|
initS2SqlByStruct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillParseInfo(Long modelId, QueryContext queryContext, ChatContext chatContext) {
|
public void fillParseInfo(ChatContext chatContext) {
|
||||||
parseInfo.setQueryMode(getQueryMode());
|
parseInfo.setQueryMode(getQueryMode());
|
||||||
|
|
||||||
SemanticService schemaService = ContextUtils.getBean(SemanticService.class);
|
SemanticService schemaService = ContextUtils.getBean(SemanticService.class);
|
||||||
ModelSchema modelSchema = schemaService.getModelSchema(modelId);
|
SemanticSchema semanticSchema = schemaService.getSemanticSchema();
|
||||||
|
|
||||||
fillSchemaElement(parseInfo, modelSchema);
|
fillSchemaElement(parseInfo, semanticSchema);
|
||||||
fillScore(parseInfo);
|
fillScore(parseInfo);
|
||||||
fillDateConf(parseInfo, chatContext.getParseInfo());
|
fillDateConf(parseInfo, chatContext.getParseInfo());
|
||||||
}
|
}
|
||||||
@@ -101,9 +105,12 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
parseInfo.setScore(parseInfo.getScore() + totalScore);
|
parseInfo.setScore(parseInfo.getScore() + totalScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillSchemaElement(SemanticParseInfo parseInfo, ModelSchema modelSchema) {
|
private void fillSchemaElement(SemanticParseInfo parseInfo, SemanticSchema semanticSchema) {
|
||||||
parseInfo.setModel(modelSchema.getModel());
|
Set<Long> modelIds = parseInfo.getElementMatches().stream().map(SchemaElementMatch::getElement)
|
||||||
|
.map(SchemaElement::getModel).collect(Collectors.toSet());
|
||||||
|
ModelCluster modelCluster = ModelCluster.build(modelIds);
|
||||||
|
modelCluster.buildName(semanticSchema.getModelIdToName());
|
||||||
|
parseInfo.setModel(modelCluster);
|
||||||
Map<Long, List<SchemaElementMatch>> dim2Values = new HashMap<>();
|
Map<Long, List<SchemaElementMatch>> dim2Values = new HashMap<>();
|
||||||
Map<Long, List<SchemaElementMatch>> id2Values = new HashMap<>();
|
Map<Long, List<SchemaElementMatch>> id2Values = new HashMap<>();
|
||||||
|
|
||||||
@@ -112,7 +119,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
element.setOrder(1 - schemaMatch.getSimilarity());
|
element.setOrder(1 - schemaMatch.getSimilarity());
|
||||||
switch (element.getType()) {
|
switch (element.getType()) {
|
||||||
case ID:
|
case ID:
|
||||||
SchemaElement entityElement = modelSchema.getElement(SchemaElementType.ENTITY, element.getId());
|
SchemaElement entityElement = semanticSchema.getElement(SchemaElementType.ENTITY, element.getId());
|
||||||
if (entityElement != null) {
|
if (entityElement != null) {
|
||||||
if (id2Values.containsKey(element.getId())) {
|
if (id2Values.containsKey(element.getId())) {
|
||||||
id2Values.get(element.getId()).add(schemaMatch);
|
id2Values.get(element.getId()).add(schemaMatch);
|
||||||
@@ -122,7 +129,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VALUE:
|
case VALUE:
|
||||||
SchemaElement dimElement = modelSchema.getElement(SchemaElementType.DIMENSION, element.getId());
|
SchemaElement dimElement = semanticSchema.getElement(SchemaElementType.DIMENSION, element.getId());
|
||||||
if (dimElement != null) {
|
if (dimElement != null) {
|
||||||
if (dim2Values.containsKey(element.getId())) {
|
if (dim2Values.containsKey(element.getId())) {
|
||||||
dim2Values.get(element.getId()).add(schemaMatch);
|
dim2Values.get(element.getId()).add(schemaMatch);
|
||||||
@@ -146,20 +153,20 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
|
|
||||||
if (!id2Values.isEmpty()) {
|
if (!id2Values.isEmpty()) {
|
||||||
for (Map.Entry<Long, List<SchemaElementMatch>> entry : id2Values.entrySet()) {
|
for (Map.Entry<Long, List<SchemaElementMatch>> entry : id2Values.entrySet()) {
|
||||||
addFilters(parseInfo, modelSchema, entry, SchemaElementType.ENTITY);
|
addFilters(parseInfo, semanticSchema, entry, SchemaElementType.ENTITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dim2Values.isEmpty()) {
|
if (!dim2Values.isEmpty()) {
|
||||||
for (Map.Entry<Long, List<SchemaElementMatch>> entry : dim2Values.entrySet()) {
|
for (Map.Entry<Long, List<SchemaElementMatch>> entry : dim2Values.entrySet()) {
|
||||||
addFilters(parseInfo, modelSchema, entry, SchemaElementType.DIMENSION);
|
addFilters(parseInfo, semanticSchema, entry, SchemaElementType.DIMENSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFilters(SemanticParseInfo parseInfo, ModelSchema modelSchema,
|
private void addFilters(SemanticParseInfo parseInfo, SemanticSchema semanticSchema,
|
||||||
Entry<Long, List<SchemaElementMatch>> entry, SchemaElementType dimension1) {
|
Entry<Long, List<SchemaElementMatch>> entry, SchemaElementType elementType) {
|
||||||
SchemaElement dimension = modelSchema.getElement(dimension1, entry.getKey());
|
SchemaElement dimension = semanticSchema.getElement(elementType, entry.getKey());
|
||||||
|
|
||||||
if (entry.getValue().size() == 1) {
|
if (entry.getValue().size() == 1) {
|
||||||
SchemaElementMatch schemaMatch = entry.getValue().get(0);
|
SchemaElementMatch schemaMatch = entry.getValue().get(0);
|
||||||
@@ -170,7 +177,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
dimensionFilter.setOperator(FilterOperatorEnum.EQUALS);
|
dimensionFilter.setOperator(FilterOperatorEnum.EQUALS);
|
||||||
dimensionFilter.setElementID(schemaMatch.getElement().getId());
|
dimensionFilter.setElementID(schemaMatch.getElement().getId());
|
||||||
parseInfo.getDimensionFilters().add(dimensionFilter);
|
parseInfo.getDimensionFilters().add(dimensionFilter);
|
||||||
parseInfo.setEntity(modelSchema.getEntity());
|
parseInfo.setEntity(semanticSchema.getElement(SchemaElementType.ENTITY, entry.getKey()));
|
||||||
} else {
|
} else {
|
||||||
QueryFilter dimensionFilter = new QueryFilter();
|
QueryFilter dimensionFilter = new QueryFilter();
|
||||||
List<String> vals = new ArrayList<>();
|
List<String> vals = new ArrayList<>();
|
||||||
@@ -189,7 +196,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
public QueryResult execute(User user) {
|
public QueryResult execute(User user) {
|
||||||
String queryMode = parseInfo.getQueryMode();
|
String queryMode = parseInfo.getQueryMode();
|
||||||
|
|
||||||
if (parseInfo.getModelId() < 0 || StringUtils.isEmpty(queryMode)
|
if (StringUtils.isBlank(parseInfo.getModelClusterKey()) || StringUtils.isEmpty(queryMode)
|
||||||
|| !QueryManager.containsRuleQuery(queryMode)) {
|
|| !QueryManager.containsRuleQuery(queryMode)) {
|
||||||
// reach here some error may happen
|
// reach here some error may happen
|
||||||
log.error("not find QueryMode");
|
log.error("not find QueryMode");
|
||||||
@@ -230,7 +237,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
public QueryResult multiStructExecute(User user) {
|
public QueryResult multiStructExecute(User user) {
|
||||||
String queryMode = parseInfo.getQueryMode();
|
String queryMode = parseInfo.getQueryMode();
|
||||||
|
|
||||||
if (parseInfo.getModelId() < 0 || StringUtils.isEmpty(queryMode)
|
if (StringUtils.isBlank(parseInfo.getModelClusterKey()) || StringUtils.isEmpty(queryMode)
|
||||||
|| !QueryManager.containsRuleQuery(queryMode)) {
|
|| !QueryManager.containsRuleQuery(queryMode)) {
|
||||||
// reach here some error may happen
|
// reach here some error may happen
|
||||||
log.error("not find QueryMode");
|
log.error("not find QueryMode");
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package com.tencent.supersonic.chat.query.rule.metric;
|
package com.tencent.supersonic.chat.query.rule.metric;
|
||||||
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.METRIC;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.REQUIRED;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNumberType.AT_LEAST;
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
@@ -20,12 +17,17 @@ import com.tencent.supersonic.chat.service.SemanticService;
|
|||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.METRIC;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.REQUIRED;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNumberType.AT_LEAST;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class MetricSemanticQuery extends RuleSemanticQuery {
|
public abstract class MetricSemanticQuery extends RuleSemanticQuery {
|
||||||
@@ -82,8 +84,8 @@ public abstract class MetricSemanticQuery extends RuleSemanticQuery {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillParseInfo(Long modelId, QueryContext queryContext, ChatContext chatContext) {
|
public void fillParseInfo(ChatContext chatContext) {
|
||||||
super.fillParseInfo(modelId, queryContext, chatContext);
|
super.fillParseInfo(chatContext);
|
||||||
|
|
||||||
parseInfo.setLimit(METRIC_MAX_RESULTS);
|
parseInfo.setLimit(METRIC_MAX_RESULTS);
|
||||||
if (parseInfo.getDateInfo() == null) {
|
if (parseInfo.getDateInfo() == null) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNum
|
|||||||
@Component
|
@Component
|
||||||
public class MetricTagQuery extends MetricSemanticQuery {
|
public class MetricTagQuery extends MetricSemanticQuery {
|
||||||
|
|
||||||
public static final String QUERY_MODE = "TAG_ENTITY";
|
public static final String QUERY_MODE = "METRIC_ENTITY";
|
||||||
|
|
||||||
public MetricTagQuery() {
|
public MetricTagQuery() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
package com.tencent.supersonic.chat.query.rule.metric;
|
package com.tencent.supersonic.chat.query.rule.metric;
|
||||||
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.DIMENSION;
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.VALUE;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.OPTIONAL;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNumberType.AT_LEAST;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.REQUIRED;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DESC_UPPER;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
@@ -20,6 +13,13 @@ import java.util.List;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.DIMENSION;
|
||||||
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.VALUE;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.OPTIONAL;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.REQUIRED;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNumberType.AT_LEAST;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.DESC_UPPER;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class MetricTopNQuery extends MetricSemanticQuery {
|
public class MetricTopNQuery extends MetricSemanticQuery {
|
||||||
|
|
||||||
@@ -50,8 +50,8 @@ public class MetricTopNQuery extends MetricSemanticQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillParseInfo(Long modelId, QueryContext queryContext, ChatContext chatContext) {
|
public void fillParseInfo(ChatContext chatContext) {
|
||||||
super.fillParseInfo(modelId, queryContext, chatContext);
|
super.fillParseInfo(chatContext);
|
||||||
|
|
||||||
parseInfo.setLimit(ORDERBY_MAX_RESULTS);
|
parseInfo.setLimit(ORDERBY_MAX_RESULTS);
|
||||||
parseInfo.setScore(parseInfo.getScore() + 2.0);
|
parseInfo.setScore(parseInfo.getScore() + 2.0);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.tencent.supersonic.chat.query.rule.tag;
|
|||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
||||||
@@ -12,16 +11,17 @@ import com.tencent.supersonic.chat.service.SemanticService;
|
|||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
import com.tencent.supersonic.common.pojo.Order;
|
import com.tencent.supersonic.common.pojo.Order;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
|
|
||||||
public abstract class TagListQuery extends TagSemanticQuery {
|
public abstract class TagListQuery extends TagSemanticQuery {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillParseInfo(Long modelId, QueryContext queryContext, ChatContext chatContext) {
|
public void fillParseInfo(ChatContext chatContext) {
|
||||||
super.fillParseInfo(modelId, queryContext, chatContext);
|
super.fillParseInfo(chatContext);
|
||||||
this.addEntityDetailAndOrderByMetric(parseInfo);
|
this.addEntityDetailAndOrderByMetric(parseInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,13 +29,12 @@ public abstract class TagListQuery extends TagSemanticQuery {
|
|||||||
Long modelId = parseInfo.getModelId();
|
Long modelId = parseInfo.getModelId();
|
||||||
if (Objects.nonNull(modelId) && modelId > 0L) {
|
if (Objects.nonNull(modelId) && modelId > 0L) {
|
||||||
ConfigService configService = ContextUtils.getBean(ConfigService.class);
|
ConfigService configService = ContextUtils.getBean(ConfigService.class);
|
||||||
ChatConfigRichResp chaConfigRichDesc = configService.getConfigRichInfo(parseInfo.getModelId());
|
ChatConfigRichResp chaConfigRichDesc = configService.getConfigRichInfo(modelId);
|
||||||
SemanticService schemaService = ContextUtils.getBean(SemanticService.class);
|
SemanticService schemaService = ContextUtils.getBean(SemanticService.class);
|
||||||
ModelSchema modelSchema = schemaService.getModelSchema(modelId);
|
ModelSchema modelSchema = schemaService.getModelSchema(parseInfo.getModelId());
|
||||||
|
|
||||||
if (chaConfigRichDesc != null && chaConfigRichDesc.getChatDetailRichConfig() != null
|
if (chaConfigRichDesc != null && chaConfigRichDesc.getChatDetailRichConfig() != null
|
||||||
&& Objects.nonNull(modelSchema) && Objects.nonNull(modelSchema.getEntity())) {
|
&& Objects.nonNull(modelSchema) && Objects.nonNull(modelSchema.getEntity())) {
|
||||||
Set<SchemaElement> dimensions = new LinkedHashSet();
|
Set<SchemaElement> dimensions = new LinkedHashSet<>();
|
||||||
Set<SchemaElement> metrics = new LinkedHashSet();
|
Set<SchemaElement> metrics = new LinkedHashSet();
|
||||||
Set<Order> orders = new LinkedHashSet();
|
Set<Order> orders = new LinkedHashSet();
|
||||||
ChatDefaultRichConfigResp chatDefaultConfig = chaConfigRichDesc
|
ChatDefaultRichConfigResp chatDefaultConfig = chaConfigRichDesc
|
||||||
@@ -52,9 +51,7 @@ public abstract class TagListQuery extends TagSemanticQuery {
|
|||||||
chatDefaultConfig.getDimensions().stream()
|
chatDefaultConfig.getDimensions().stream()
|
||||||
.forEach(dimension -> dimensions.add(dimension));
|
.forEach(dimension -> dimensions.add(dimension));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseInfo.setDimensions(dimensions);
|
parseInfo.setDimensions(dimensions);
|
||||||
parseInfo.setMetrics(metrics);
|
parseInfo.setMetrics(metrics);
|
||||||
parseInfo.setOrders(orders);
|
parseInfo.setOrders(orders);
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
package com.tencent.supersonic.chat.query.rule.tag;
|
package com.tencent.supersonic.chat.query.rule.tag;
|
||||||
|
|
||||||
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.ENTITY;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.REQUIRED;
|
|
||||||
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNumberType.AT_LEAST;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.common.pojo.QueryType;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||||
@@ -15,13 +10,19 @@ import com.tencent.supersonic.chat.api.pojo.response.ChatDefaultRichConfigResp;
|
|||||||
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
||||||
import com.tencent.supersonic.chat.service.ConfigService;
|
import com.tencent.supersonic.chat.service.ConfigService;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import static com.tencent.supersonic.chat.api.pojo.SchemaElementType.ENTITY;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.OptionType.REQUIRED;
|
||||||
|
import static com.tencent.supersonic.chat.query.rule.QueryMatchOption.RequireNumberType.AT_LEAST;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class TagSemanticQuery extends RuleSemanticQuery {
|
public abstract class TagSemanticQuery extends RuleSemanticQuery {
|
||||||
@@ -78,8 +79,8 @@ public abstract class TagSemanticQuery extends RuleSemanticQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillParseInfo(Long modelId, QueryContext queryContext, ChatContext chatContext) {
|
public void fillParseInfo(ChatContext chatContext) {
|
||||||
super.fillParseInfo(modelId, queryContext, chatContext);
|
super.fillParseInfo(chatContext);
|
||||||
|
|
||||||
parseInfo.setQueryType(QueryType.TAG);
|
parseInfo.setQueryType(QueryType.TAG);
|
||||||
parseInfo.setLimit(TAG_MAX_RESULTS);
|
parseInfo.setLimit(TAG_MAX_RESULTS);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class EntityInfoExecuteResponder implements ExecuteResponder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillResponse(QueryResult queryResult, SemanticParseInfo semanticParseInfo, ExecuteQueryReq queryReq) {
|
public void fillResponse(QueryResult queryResult, SemanticParseInfo semanticParseInfo, ExecuteQueryReq queryReq) {
|
||||||
if (semanticParseInfo == null || semanticParseInfo.getModelId() <= 0L) {
|
if (semanticParseInfo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String queryMode = semanticParseInfo.getQueryMode();
|
String queryMode = semanticParseInfo.getQueryMode();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class SimilarMetricExecuteResponder implements ExecuteResponder {
|
|||||||
}
|
}
|
||||||
List<String> metricNames = Collections.singletonList(parseInfo.getMetrics().iterator().next().getName());
|
List<String> metricNames = Collections.singletonList(parseInfo.getMetrics().iterator().next().getName());
|
||||||
Map<String, String> filterCondition = new HashMap<>();
|
Map<String, String> filterCondition = new HashMap<>();
|
||||||
filterCondition.put("modelId", parseInfo.getModelId().toString());
|
filterCondition.put("modelId", parseInfo.getMetrics().iterator().next().getModel().toString());
|
||||||
filterCondition.put("type", SchemaElementType.METRIC.name());
|
filterCondition.put("type", SchemaElementType.METRIC.name());
|
||||||
RetrieveQuery retrieveQuery = RetrieveQuery.builder().queryTextsList(metricNames)
|
RetrieveQuery retrieveQuery = RetrieveQuery.builder().queryTextsList(metricNames)
|
||||||
.filterCondition(filterCondition).queryEmbeddings(null).build();
|
.filterCondition(filterCondition).queryEmbeddings(null).build();
|
||||||
|
|||||||
@@ -3,22 +3,80 @@ package com.tencent.supersonic.chat.responder.parse;
|
|||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
||||||
import com.tencent.supersonic.chat.query.QueryRanker;
|
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rank queries by score.
|
* Rank queries by score.
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class QueryRankParseResponder implements ParseResponder {
|
public class QueryRankParseResponder implements ParseResponder {
|
||||||
|
|
||||||
|
private static final int candidateTopSize = 5;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillResponse(ParseResp parseResp, QueryContext queryContext, ChatContext chatContext) {
|
public void fillResponse(ParseResp parseResp, QueryContext queryContext, ChatContext chatContext) {
|
||||||
List<SemanticQuery> candidateQueries = queryContext.getCandidateQueries();
|
List<SemanticQuery> candidateQueries = queryContext.getCandidateQueries();
|
||||||
QueryRanker queryRanker = ContextUtils.getBean(QueryRanker.class);
|
candidateQueries = rank(candidateQueries);
|
||||||
candidateQueries = queryRanker.rank(candidateQueries);
|
|
||||||
queryContext.setCandidateQueries(candidateQueries);
|
queryContext.setCandidateQueries(candidateQueries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<SemanticQuery> rank(List<SemanticQuery> candidateQueries) {
|
||||||
|
log.debug("pick before [{}]", candidateQueries);
|
||||||
|
if (CollectionUtils.isEmpty(candidateQueries)) {
|
||||||
|
return candidateQueries;
|
||||||
|
}
|
||||||
|
List<SemanticQuery> selectedQueries = new ArrayList<>();
|
||||||
|
if (candidateQueries.size() == 1) {
|
||||||
|
selectedQueries.addAll(candidateQueries);
|
||||||
|
} else {
|
||||||
|
selectedQueries = getTopCandidateQuery(candidateQueries);
|
||||||
|
}
|
||||||
|
generateParseInfoId(selectedQueries);
|
||||||
|
log.debug("pick after [{}]", selectedQueries);
|
||||||
|
return selectedQueries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SemanticQuery> getTopCandidateQuery(List<SemanticQuery> semanticQueries) {
|
||||||
|
return semanticQueries.stream()
|
||||||
|
.filter(query -> !checkFullyInherited(query))
|
||||||
|
.sorted((o1, o2) -> {
|
||||||
|
if (o1.getParseInfo().getScore() < o2.getParseInfo().getScore()) {
|
||||||
|
return 1;
|
||||||
|
} else if (o1.getParseInfo().getScore() > o2.getParseInfo().getScore()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}).limit(candidateTopSize)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateParseInfoId(List<SemanticQuery> semanticQueries) {
|
||||||
|
for (int i = 0; i < semanticQueries.size(); i++) {
|
||||||
|
SemanticQuery query = semanticQueries.get(i);
|
||||||
|
query.getParseInfo().setId(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkFullyInherited(SemanticQuery query) {
|
||||||
|
SemanticParseInfo parseInfo = query.getParseInfo();
|
||||||
|
if (!(query instanceof RuleSemanticQuery)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SchemaElementMatch match : parseInfo.getElementMatches()) {
|
||||||
|
if (!match.isInherited()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parseInfo.getDateInfo() == null || parseInfo.getDateInfo().isInherited();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatConfigEditReqReq;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
||||||
|
import com.tencent.supersonic.chat.service.ConfigService;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.PageDimensionReq;
|
import com.tencent.supersonic.semantic.api.model.request.PageDimensionReq;
|
||||||
@@ -17,12 +18,6 @@ import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
|||||||
import com.tencent.supersonic.semantic.api.model.response.DomainResp;
|
import com.tencent.supersonic.semantic.api.model.response.DomainResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
||||||
import com.tencent.supersonic.chat.service.ConfigService;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@@ -32,6 +27,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping({"/api/chat/conf", "/openapi/chat/conf"})
|
@RequestMapping({"/api/chat/conf", "/openapi/chat/conf"})
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.tencent.supersonic.chat.persistence.dataobject.ChatDO;
|
|||||||
import com.tencent.supersonic.chat.persistence.dataobject.ChatParseDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.ChatParseDO;
|
||||||
import com.tencent.supersonic.chat.persistence.dataobject.ChatQueryDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.ChatQueryDO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface ChatService {
|
public interface ChatService {
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ public interface ChatService {
|
|||||||
* @param chatId
|
* @param chatId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Long getContextModel(Integer chatId);
|
Set<Long> getContextModel(Integer chatId);
|
||||||
|
|
||||||
ChatContext getOrCreateContext(int chatId);
|
ChatContext getOrCreateContext(int chatId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.tencent.supersonic.chat.service;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
|
||||||
|
|
||||||
public interface ParseInfoService {
|
|
||||||
|
|
||||||
void updateParseInfo(SemanticParseInfo parseInfo);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +1,14 @@
|
|||||||
package com.tencent.supersonic.chat.service;
|
package com.tencent.supersonic.chat.service;
|
||||||
|
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
import com.google.common.collect.Sets;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT_INT;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT_INT;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.TIMES_FORMAT;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.common.pojo.QueryType;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatAggConfigReq;
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatDefaultConfigReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatDefaultConfigReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatDetailConfigReq;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ItemVisibility;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.AggregateInfo;
|
import com.tencent.supersonic.chat.api.pojo.response.AggregateInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||||
@@ -35,7 +23,9 @@ import com.tencent.supersonic.chat.utils.ComponentFactory;
|
|||||||
import com.tencent.supersonic.chat.utils.QueryReqBuilder;
|
import com.tencent.supersonic.chat.utils.QueryReqBuilder;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf.DateMode;
|
import com.tencent.supersonic.common.pojo.DateConf.DateMode;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.RatioOverType;
|
import com.tencent.supersonic.common.pojo.enums.RatioOverType;
|
||||||
@@ -44,6 +34,13 @@ import com.tencent.supersonic.common.util.DateUtils;
|
|||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.DayOfWeek;
|
import java.time.DayOfWeek;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
@@ -63,12 +60,16 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
||||||
import org.springframework.beans.BeanUtils;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT_INT;
|
||||||
import org.springframework.stereotype.Service;
|
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
||||||
import org.springframework.util.CollectionUtils;
|
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT_INT;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.TIMES_FORMAT;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -83,45 +84,38 @@ public class SemanticService {
|
|||||||
|
|
||||||
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
private SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
|
||||||
|
|
||||||
public ModelSchema getModelSchema(Long id) {
|
public SemanticSchema getSemanticSchema() {
|
||||||
ModelSchema modelSchema = schemaService.getModelSchema(id);
|
return schemaService.getSemanticSchema();
|
||||||
if (!Objects.isNull(modelSchema) && !Objects.isNull(modelSchema.getModel())) {
|
}
|
||||||
ChatConfigResp chaConfigInfo =
|
|
||||||
configService.fetchConfigByModelId(modelSchema.getModel().getId());
|
|
||||||
// filter dimensions in blacklist
|
|
||||||
filterBlackDim(modelSchema, chaConfigInfo);
|
|
||||||
// filter metrics in blacklist
|
|
||||||
filterBlackMetric(modelSchema, chaConfigInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return modelSchema;
|
public ModelSchema getModelSchema(Long id) {
|
||||||
|
return schemaService.getModelSchema(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityInfo getEntityInfo(SemanticParseInfo parseInfo, User user) {
|
public EntityInfo getEntityInfo(SemanticParseInfo parseInfo, User user) {
|
||||||
if (parseInfo != null && parseInfo.getModelId() > 0) {
|
if (parseInfo != null && parseInfo.getModelId() > 0) {
|
||||||
EntityInfo entityInfo = getEntityInfo(parseInfo.getModelId());
|
EntityInfo entityInfo = getEntityInfo(parseInfo.getModelId());
|
||||||
if (parseInfo.getDimensionFilters().size() <= 0) {
|
if (parseInfo.getDimensionFilters().size() <= 0 || entityInfo.getModelInfo() == null) {
|
||||||
entityInfo.setMetrics(null);
|
entityInfo.setMetrics(null);
|
||||||
entityInfo.setDimensions(null);
|
entityInfo.setDimensions(null);
|
||||||
return entityInfo;
|
return entityInfo;
|
||||||
}
|
}
|
||||||
if (entityInfo.getModelInfo() != null && entityInfo.getModelInfo().getPrimaryEntityBizName() != null) {
|
String primaryKey = entityInfo.getModelInfo().getPrimaryKey();
|
||||||
String modelInfoPrimaryName = entityInfo.getModelInfo().getPrimaryEntityBizName();
|
if (StringUtils.isNotBlank(primaryKey)) {
|
||||||
String modelInfoId = "";
|
String modelInfoId = "";
|
||||||
for (QueryFilter chatFilter : parseInfo.getDimensionFilters()) {
|
for (QueryFilter chatFilter : parseInfo.getDimensionFilters()) {
|
||||||
if (chatFilter != null && chatFilter.getBizName() != null && chatFilter.getBizName()
|
if (chatFilter != null && chatFilter.getBizName() != null && chatFilter.getBizName()
|
||||||
.equals(modelInfoPrimaryName)) {
|
.equals(primaryKey)) {
|
||||||
if (chatFilter.getOperator().equals(FilterOperatorEnum.EQUALS)) {
|
if (chatFilter.getOperator().equals(FilterOperatorEnum.EQUALS)) {
|
||||||
modelInfoId = chatFilter.getValue().toString();
|
modelInfoId = chatFilter.getValue().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
setMainModel(entityInfo, parseInfo.getModelId(),
|
setMainModel(entityInfo, parseInfo, modelInfoId, user);
|
||||||
modelInfoId, user);
|
|
||||||
return entityInfo;
|
return entityInfo;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("setMainModel error {}", e);
|
log.error("setMainModel error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,8 +146,7 @@ public class SemanticService {
|
|||||||
modelInfo.setWords(modelSchema.getModel().getAlias());
|
modelInfo.setWords(modelSchema.getModel().getAlias());
|
||||||
modelInfo.setBizName(modelSchema.getModel().getBizName());
|
modelInfo.setBizName(modelSchema.getModel().getBizName());
|
||||||
if (Objects.nonNull(modelSchema.getEntity())) {
|
if (Objects.nonNull(modelSchema.getEntity())) {
|
||||||
modelInfo.setPrimaryEntityName(modelSchema.getEntity().getName());
|
modelInfo.setPrimaryKey(modelSchema.getEntity().getBizName());
|
||||||
modelInfo.setPrimaryEntityBizName(modelSchema.getEntity().getBizName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entityInfo.setModelInfo(modelInfo);
|
entityInfo.setModelInfo(modelInfo);
|
||||||
@@ -190,21 +183,14 @@ public class SemanticService {
|
|||||||
return entityInfo;
|
return entityInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrimaryEntityBizName(EntityInfo entityInfo) {
|
public void setMainModel(EntityInfo modelInfo, SemanticParseInfo parseInfo, String entity, User user) {
|
||||||
if (Objects.isNull(entityInfo) || Objects.isNull(entityInfo.getModelInfo())) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return entityInfo.getModelInfo().getPrimaryEntityBizName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMainModel(EntityInfo modelInfo, Long model, String entity, User user) {
|
|
||||||
if (StringUtils.isEmpty(entity)) {
|
if (StringUtils.isEmpty(entity)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> entities = Collections.singletonList(entity);
|
List<String> entities = Collections.singletonList(entity);
|
||||||
|
|
||||||
QueryResultWithSchemaResp queryResultWithColumns = getQueryResultWithSchemaResp(modelInfo, model, entities,
|
QueryResultWithSchemaResp queryResultWithColumns = getQueryResultWithSchemaResp(modelInfo, parseInfo, entities,
|
||||||
user);
|
user);
|
||||||
|
|
||||||
if (queryResultWithColumns != null) {
|
if (queryResultWithColumns != null) {
|
||||||
@@ -225,15 +211,15 @@ public class SemanticService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryResultWithSchemaResp getQueryResultWithSchemaResp(EntityInfo modelInfo, Long model,
|
public QueryResultWithSchemaResp getQueryResultWithSchemaResp(EntityInfo modelInfo, SemanticParseInfo parseInfo,
|
||||||
List<String> entities, User user) {
|
List<String> entities, User user) {
|
||||||
if (CollectionUtils.isEmpty(entities)) {
|
if (CollectionUtils.isEmpty(entities)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ModelSchema modelSchema = schemaService.getModelSchema(model);
|
ModelSchema modelSchema = schemaService.getModelSchema(parseInfo.getModelId());
|
||||||
modelInfo.setEntityId(entities.get(0));
|
modelInfo.setEntityId(entities.get(0));
|
||||||
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
||||||
semanticParseInfo.setModel(modelSchema.getModel());
|
semanticParseInfo.setModel(ModelCluster.build(Sets.newHashSet(parseInfo.getModelId())));
|
||||||
semanticParseInfo.setQueryType(QueryType.TAG);
|
semanticParseInfo.setQueryType(QueryType.TAG);
|
||||||
semanticParseInfo.setMetrics(getMetrics(modelInfo));
|
semanticParseInfo.setMetrics(getMetrics(modelInfo));
|
||||||
semanticParseInfo.setDimensions(getDimensions(modelInfo));
|
semanticParseInfo.setDimensions(getDimensions(modelInfo));
|
||||||
@@ -314,54 +300,7 @@ public class SemanticService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getEntityPrimaryName(EntityInfo modelInfo) {
|
private String getEntityPrimaryName(EntityInfo modelInfo) {
|
||||||
return modelInfo.getModelInfo().getPrimaryEntityBizName();
|
return modelInfo.getModelInfo().getPrimaryKey();
|
||||||
}
|
|
||||||
|
|
||||||
private void filterBlackMetric(ModelSchema modelSchema, ChatConfigResp chaConfigInfo) {
|
|
||||||
ItemVisibility visibility = generateFinalVisibility(chaConfigInfo);
|
|
||||||
if (Objects.nonNull(chaConfigInfo) && Objects.nonNull(visibility)
|
|
||||||
&& !CollectionUtils.isEmpty(visibility.getBlackMetricIdList())
|
|
||||||
&& !CollectionUtils.isEmpty(modelSchema.getMetrics())) {
|
|
||||||
Set<SchemaElement> metric4Chat = modelSchema.getMetrics().stream()
|
|
||||||
.filter(metric -> !visibility.getBlackMetricIdList().contains(metric.getId()))
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
modelSchema.setMetrics(metric4Chat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filterBlackDim(ModelSchema modelSchema, ChatConfigResp chatConfigInfo) {
|
|
||||||
ItemVisibility visibility = generateFinalVisibility(chatConfigInfo);
|
|
||||||
if (Objects.nonNull(chatConfigInfo) && Objects.nonNull(visibility)
|
|
||||||
&& !CollectionUtils.isEmpty(visibility.getBlackDimIdList())
|
|
||||||
&& !CollectionUtils.isEmpty(modelSchema.getDimensions())) {
|
|
||||||
Set<SchemaElement> dim4Chat = modelSchema.getDimensions().stream()
|
|
||||||
.filter(dim -> !visibility.getBlackDimIdList().contains(dim.getId()))
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
modelSchema.setDimensions(dim4Chat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemVisibility generateFinalVisibility(ChatConfigResp chatConfigInfo) {
|
|
||||||
ItemVisibility visibility = new ItemVisibility();
|
|
||||||
|
|
||||||
ChatAggConfigReq chatAggConfig = chatConfigInfo.getChatAggConfig();
|
|
||||||
ChatDetailConfigReq chatDetailConfig = chatConfigInfo.getChatDetailConfig();
|
|
||||||
|
|
||||||
// both black is exist
|
|
||||||
if (Objects.nonNull(chatAggConfig) && Objects.nonNull(chatAggConfig.getVisibility())
|
|
||||||
&& Objects.nonNull(chatDetailConfig) && Objects.nonNull(chatDetailConfig.getVisibility())) {
|
|
||||||
List<Long> blackDimIdList = new ArrayList<>();
|
|
||||||
blackDimIdList.addAll(chatAggConfig.getVisibility().getBlackDimIdList());
|
|
||||||
blackDimIdList.retainAll(chatDetailConfig.getVisibility().getBlackDimIdList());
|
|
||||||
List<Long> blackMetricIdList = new ArrayList<>();
|
|
||||||
|
|
||||||
blackMetricIdList.addAll(chatAggConfig.getVisibility().getBlackMetricIdList());
|
|
||||||
blackMetricIdList.retainAll(chatDetailConfig.getVisibility().getBlackMetricIdList());
|
|
||||||
|
|
||||||
visibility.setBlackDimIdList(blackDimIdList);
|
|
||||||
visibility.setBlackMetricIdList(blackMetricIdList);
|
|
||||||
}
|
|
||||||
return visibility;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AggregateInfo getAggregateInfo(User user, SemanticParseInfo semanticParseInfo,
|
public AggregateInfo getAggregateInfo(User user, SemanticParseInfo semanticParseInfo,
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import com.github.pagehelper.PageInfo;
|
|||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.PageQueryInfoReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ShowCaseResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ShowCaseResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.SolvedQueryRecallResp;
|
import com.tencent.supersonic.chat.api.pojo.response.SolvedQueryRecallResp;
|
||||||
@@ -13,11 +15,18 @@ import com.tencent.supersonic.chat.persistence.dataobject.ChatDO;
|
|||||||
import com.tencent.supersonic.chat.persistence.dataobject.ChatParseDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.ChatParseDO;
|
||||||
import com.tencent.supersonic.chat.persistence.dataobject.ChatQueryDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.ChatQueryDO;
|
||||||
import com.tencent.supersonic.chat.persistence.dataobject.QueryDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.QueryDO;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.PageQueryInfoReq;
|
|
||||||
import com.tencent.supersonic.chat.persistence.repository.ChatContextRepository;
|
import com.tencent.supersonic.chat.persistence.repository.ChatContextRepository;
|
||||||
import com.tencent.supersonic.chat.persistence.repository.ChatQueryRepository;
|
import com.tencent.supersonic.chat.persistence.repository.ChatQueryRepository;
|
||||||
import com.tencent.supersonic.chat.persistence.repository.ChatRepository;
|
import com.tencent.supersonic.chat.persistence.repository.ChatRepository;
|
||||||
|
import com.tencent.supersonic.chat.service.ChatService;
|
||||||
|
import com.tencent.supersonic.chat.utils.SolvedQueryManager;
|
||||||
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -28,14 +37,6 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import com.tencent.supersonic.chat.service.ChatService;
|
|
||||||
import com.tencent.supersonic.chat.utils.SolvedQueryManager;
|
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.compress.utils.Lists;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
@Service("ChatService")
|
@Service("ChatService")
|
||||||
@Primary
|
@Primary
|
||||||
@@ -56,7 +57,7 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getContextModel(Integer chatId) {
|
public Set<Long> getContextModel(Integer chatId) {
|
||||||
if (Objects.isNull(chatId)) {
|
if (Objects.isNull(chatId)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -65,8 +66,8 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SemanticParseInfo originalSemanticParse = chatContext.getParseInfo();
|
SemanticParseInfo originalSemanticParse = chatContext.getParseInfo();
|
||||||
if (Objects.nonNull(originalSemanticParse) && Objects.nonNull(originalSemanticParse.getModelId())) {
|
if (Objects.nonNull(originalSemanticParse) && Objects.nonNull(originalSemanticParse.getModel().getModelIds())) {
|
||||||
return originalSemanticParse.getModelId();
|
return originalSemanticParse.getModel().getModelIds();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,39 +6,31 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
|||||||
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ItemVisibility;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ItemNameVisibilityInfo;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatAggConfigReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatAggConfigReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatDetailConfigReq;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigBaseReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigBaseReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigEditReqReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigEditReqReq;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigFilter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatDefaultConfigReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatDefaultConfigReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeInfoReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatDetailConfigReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.Entity;
|
import com.tencent.supersonic.chat.api.pojo.request.Entity;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.ItemNameVisibilityInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.ItemVisibility;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeInfoReq;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.response.ChatAggRichConfigResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatDefaultRichConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatDefaultRichConfigResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatAggRichConfigResp;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatDetailRichConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatDetailRichConfigResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.EntityRichInfoResp;
|
import com.tencent.supersonic.chat.api.pojo.response.EntityRichInfoResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ItemVisibilityInfo;
|
import com.tencent.supersonic.chat.api.pojo.response.ItemVisibilityInfo;
|
||||||
import com.tencent.supersonic.chat.config.ChatConfig;
|
import com.tencent.supersonic.chat.config.ChatConfig;
|
||||||
|
import com.tencent.supersonic.chat.persistence.repository.ChatConfigRepository;
|
||||||
import com.tencent.supersonic.chat.service.ConfigService;
|
import com.tencent.supersonic.chat.service.ConfigService;
|
||||||
import com.tencent.supersonic.chat.service.SemanticService;
|
import com.tencent.supersonic.chat.service.SemanticService;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
|
||||||
import com.tencent.supersonic.chat.persistence.repository.ChatConfigRepository;
|
|
||||||
import com.tencent.supersonic.chat.utils.ChatConfigHelper;
|
import com.tencent.supersonic.chat.utils.ChatConfigHelper;
|
||||||
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
import com.tencent.supersonic.chat.utils.VisibilityEvent;
|
import com.tencent.supersonic.chat.utils.VisibilityEvent;
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
||||||
@@ -52,6 +44,13 @@ import org.springframework.context.ApplicationEventPublisher;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -83,7 +82,6 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
public Long addConfig(ChatConfigBaseReq configBaseCmd, User user) {
|
public Long addConfig(ChatConfigBaseReq configBaseCmd, User user) {
|
||||||
log.info("[create model extend] object:{}", JsonUtil.toString(configBaseCmd, true));
|
log.info("[create model extend] object:{}", JsonUtil.toString(configBaseCmd, true));
|
||||||
duplicateCheck(configBaseCmd.getModelId());
|
duplicateCheck(configBaseCmd.getModelId());
|
||||||
permissionCheckLogic(configBaseCmd.getModelId(), user.getName());
|
|
||||||
ChatConfig chaConfig = chatConfigHelper.newChatConfig(configBaseCmd, user);
|
ChatConfig chaConfig = chatConfigHelper.newChatConfig(configBaseCmd, user);
|
||||||
Long id = chatConfigRepository.createConfig(chaConfig);
|
Long id = chatConfigRepository.createConfig(chaConfig);
|
||||||
applicationEventPublisher.publishEvent(new VisibilityEvent(this, chaConfig));
|
applicationEventPublisher.publishEvent(new VisibilityEvent(this, chaConfig));
|
||||||
@@ -107,7 +105,6 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
configEditCmd.getModelId())) {
|
configEditCmd.getModelId())) {
|
||||||
throw new RuntimeException("editConfig, id and modelId are not allowed to be empty at the same time");
|
throw new RuntimeException("editConfig, id and modelId are not allowed to be empty at the same time");
|
||||||
}
|
}
|
||||||
permissionCheckLogic(configEditCmd.getModelId(), user.getName());
|
|
||||||
ChatConfig chaConfig = chatConfigHelper.editChatConfig(configEditCmd, user);
|
ChatConfig chaConfig = chatConfigHelper.editChatConfig(configEditCmd, user);
|
||||||
chatConfigRepository.updateConfig(chaConfig);
|
chatConfigRepository.updateConfig(chaConfig);
|
||||||
applicationEventPublisher.publishEvent(new VisibilityEvent(this, chaConfig));
|
applicationEventPublisher.publishEvent(new VisibilityEvent(this, chaConfig));
|
||||||
@@ -164,14 +161,6 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
return itemNameVisibility;
|
return itemNameVisibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* model administrators have the right to modify related configuration information.
|
|
||||||
*/
|
|
||||||
private Boolean permissionCheckLogic(Long modelId, String staffName) {
|
|
||||||
// todo
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ChatConfigResp> search(ChatConfigFilter filter, User user) {
|
public List<ChatConfigResp> search(ChatConfigFilter filter, User user) {
|
||||||
log.info("[search model extend] object:{}", JsonUtil.toString(filter, true));
|
log.info("[search model extend] object:{}", JsonUtil.toString(filter, true));
|
||||||
|
|||||||
@@ -1,205 +0,0 @@
|
|||||||
|
|
||||||
package com.tencent.supersonic.chat.service.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.tencent.supersonic.common.pojo.QueryType;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.SqlInfo;
|
|
||||||
import com.tencent.supersonic.chat.service.ParseInfoService;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf.DateMode;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.FieldExpression;
|
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectFunctionHelper;
|
|
||||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
|
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class ParserInfoServiceImpl implements ParseInfoService {
|
|
||||||
|
|
||||||
|
|
||||||
public void updateParseInfo(SemanticParseInfo parseInfo) {
|
|
||||||
SqlInfo sqlInfo = parseInfo.getSqlInfo();
|
|
||||||
String correctS2SQL = sqlInfo.getCorrectS2SQL();
|
|
||||||
if (StringUtils.isBlank(correctS2SQL)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// if S2SQL equals correctS2SQL, than not update the parseInfo.
|
|
||||||
if (correctS2SQL.equals(sqlInfo.getS2SQL())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FieldExpression> expressions = SqlParserSelectHelper.getFilterExpression(correctS2SQL);
|
|
||||||
//set dataInfo
|
|
||||||
try {
|
|
||||||
if (!CollectionUtils.isEmpty(expressions)) {
|
|
||||||
DateConf dateInfo = getDateInfo(expressions);
|
|
||||||
if (dateInfo != null && parseInfo.getDateInfo() == null) {
|
|
||||||
parseInfo.setDateInfo(dateInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("set dateInfo error :", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
//set filter
|
|
||||||
try {
|
|
||||||
Map<String, SchemaElement> fieldNameToElement = getNameToElement(parseInfo.getModelId());
|
|
||||||
List<QueryFilter> result = getDimensionFilter(fieldNameToElement, expressions);
|
|
||||||
parseInfo.getDimensionFilters().addAll(result);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("set dimensionFilter error :", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
|
||||||
|
|
||||||
if (Objects.isNull(semanticSchema)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<String> allFields = getFieldsExceptDate(SqlParserSelectHelper.getAllFields(sqlInfo.getCorrectS2SQL()));
|
|
||||||
Set<SchemaElement> metrics = getElements(parseInfo.getModelId(), allFields, semanticSchema.getMetrics());
|
|
||||||
parseInfo.setMetrics(metrics);
|
|
||||||
|
|
||||||
if (SqlParserSelectFunctionHelper.hasAggregateFunction(sqlInfo.getCorrectS2SQL())) {
|
|
||||||
parseInfo.setQueryType(QueryType.METRIC);
|
|
||||||
List<String> groupByFields = SqlParserSelectHelper.getGroupByFields(sqlInfo.getCorrectS2SQL());
|
|
||||||
List<String> groupByDimensions = getFieldsExceptDate(groupByFields);
|
|
||||||
parseInfo.setDimensions(
|
|
||||||
getElements(parseInfo.getModelId(), groupByDimensions, semanticSchema.getDimensions()));
|
|
||||||
} else {
|
|
||||||
parseInfo.setQueryType(QueryType.TAG);
|
|
||||||
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sqlInfo.getCorrectS2SQL());
|
|
||||||
List<String> selectDimensions = getFieldsExceptDate(selectFields);
|
|
||||||
parseInfo.setDimensions(
|
|
||||||
getElements(parseInfo.getModelId(), selectDimensions, semanticSchema.getDimensions()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Set<SchemaElement> getElements(Long modelId, List<String> allFields, List<SchemaElement> elements) {
|
|
||||||
return elements.stream()
|
|
||||||
.filter(schemaElement -> modelId.equals(schemaElement.getModel())
|
|
||||||
&& allFields.contains(schemaElement.getName())
|
|
||||||
).collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getFieldsExceptDate(List<String> allFields) {
|
|
||||||
if (org.springframework.util.CollectionUtils.isEmpty(allFields)) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
return allFields.stream()
|
|
||||||
.filter(entry -> !TimeDimensionEnum.DAY.getChName().equalsIgnoreCase(entry))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private List<QueryFilter> getDimensionFilter(Map<String, SchemaElement> fieldNameToElement,
|
|
||||||
List<FieldExpression> fieldExpressions) {
|
|
||||||
List<QueryFilter> result = Lists.newArrayList();
|
|
||||||
for (FieldExpression expression : fieldExpressions) {
|
|
||||||
QueryFilter dimensionFilter = new QueryFilter();
|
|
||||||
dimensionFilter.setValue(expression.getFieldValue());
|
|
||||||
SchemaElement schemaElement = fieldNameToElement.get(expression.getFieldName());
|
|
||||||
if (Objects.isNull(schemaElement)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
dimensionFilter.setName(schemaElement.getName());
|
|
||||||
dimensionFilter.setBizName(schemaElement.getBizName());
|
|
||||||
dimensionFilter.setElementID(schemaElement.getId());
|
|
||||||
|
|
||||||
FilterOperatorEnum operatorEnum = FilterOperatorEnum.getSqlOperator(expression.getOperator());
|
|
||||||
dimensionFilter.setOperator(operatorEnum);
|
|
||||||
dimensionFilter.setFunction(expression.getFunction());
|
|
||||||
result.add(dimensionFilter);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DateConf getDateInfo(List<FieldExpression> fieldExpressions) {
|
|
||||||
List<FieldExpression> dateExpressions = fieldExpressions.stream()
|
|
||||||
.filter(expression -> TimeDimensionEnum.DAY.getChName().equalsIgnoreCase(expression.getFieldName()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (CollectionUtils.isEmpty(dateExpressions)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
DateConf dateInfo = new DateConf();
|
|
||||||
dateInfo.setDateMode(DateMode.BETWEEN);
|
|
||||||
FieldExpression firstExpression = dateExpressions.get(0);
|
|
||||||
|
|
||||||
FilterOperatorEnum firstOperator = FilterOperatorEnum.getSqlOperator(firstExpression.getOperator());
|
|
||||||
if (FilterOperatorEnum.EQUALS.equals(firstOperator) && Objects.nonNull(firstExpression.getFieldValue())) {
|
|
||||||
dateInfo.setStartDate(firstExpression.getFieldValue().toString());
|
|
||||||
dateInfo.setEndDate(firstExpression.getFieldValue().toString());
|
|
||||||
dateInfo.setDateMode(DateMode.BETWEEN);
|
|
||||||
return dateInfo;
|
|
||||||
}
|
|
||||||
if (containOperators(firstExpression, firstOperator, FilterOperatorEnum.GREATER_THAN,
|
|
||||||
FilterOperatorEnum.GREATER_THAN_EQUALS)) {
|
|
||||||
dateInfo.setStartDate(firstExpression.getFieldValue().toString());
|
|
||||||
if (hasSecondDate(dateExpressions)) {
|
|
||||||
dateInfo.setEndDate(dateExpressions.get(1).getFieldValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (containOperators(firstExpression, firstOperator, FilterOperatorEnum.MINOR_THAN,
|
|
||||||
FilterOperatorEnum.MINOR_THAN_EQUALS)) {
|
|
||||||
dateInfo.setEndDate(firstExpression.getFieldValue().toString());
|
|
||||||
if (hasSecondDate(dateExpressions)) {
|
|
||||||
dateInfo.setStartDate(dateExpressions.get(1).getFieldValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dateInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean containOperators(FieldExpression expression, FilterOperatorEnum firstOperator,
|
|
||||||
FilterOperatorEnum... operatorEnums) {
|
|
||||||
return (Arrays.asList(operatorEnums).contains(firstOperator) && Objects.nonNull(expression.getFieldValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasSecondDate(List<FieldExpression> dateExpressions) {
|
|
||||||
return dateExpressions.size() > 1 && Objects.nonNull(dateExpressions.get(1).getFieldValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, SchemaElement> getNameToElement(Long modelId) {
|
|
||||||
SemanticSchema semanticSchema = ContextUtils.getBean(SchemaService.class).getSemanticSchema();
|
|
||||||
List<SchemaElement> dimensions = semanticSchema.getDimensions();
|
|
||||||
List<SchemaElement> metrics = semanticSchema.getMetrics();
|
|
||||||
|
|
||||||
List<SchemaElement> allElements = Lists.newArrayList();
|
|
||||||
allElements.addAll(dimensions);
|
|
||||||
allElements.addAll(metrics);
|
|
||||||
//support alias
|
|
||||||
return allElements.stream()
|
|
||||||
.filter(schemaElement -> schemaElement.getModel().equals(modelId))
|
|
||||||
.flatMap(schemaElement -> {
|
|
||||||
Set<Pair<String, SchemaElement>> result = new HashSet<>();
|
|
||||||
result.add(Pair.of(schemaElement.getName(), schemaElement));
|
|
||||||
List<String> aliasList = schemaElement.getAlias();
|
|
||||||
if (!org.springframework.util.CollectionUtils.isEmpty(aliasList)) {
|
|
||||||
for (String alias : aliasList) {
|
|
||||||
result.add(Pair.of(alias, schemaElement));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.stream();
|
|
||||||
})
|
|
||||||
.collect(Collectors.toMap(pair -> pair.getLeft(), pair -> pair.getRight(), (value1, value2) -> value2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,9 +14,15 @@ import com.tencent.supersonic.chat.plugin.event.PluginDelEvent;
|
|||||||
import com.tencent.supersonic.chat.plugin.event.PluginUpdateEvent;
|
import com.tencent.supersonic.chat.plugin.event.PluginUpdateEvent;
|
||||||
import com.tencent.supersonic.chat.service.PluginService;
|
import com.tencent.supersonic.chat.service.PluginService;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||||
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -25,13 +31,6 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PluginServiceImpl implements PluginService {
|
public class PluginServiceImpl implements PluginService {
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ public class QueryServiceImpl implements QueryService {
|
|||||||
solvedQueryManager.saveSolvedQuery(SolvedQueryReq.builder().parseId(queryReq.getParseId())
|
solvedQueryManager.saveSolvedQuery(SolvedQueryReq.builder().parseId(queryReq.getParseId())
|
||||||
.queryId(queryReq.getQueryId())
|
.queryId(queryReq.getQueryId())
|
||||||
.agentId(chatQueryDO.getAgentId())
|
.agentId(chatQueryDO.getAgentId())
|
||||||
.modelId(parseInfo.getModelId())
|
.modelId(parseInfo.getModelClusterKey())
|
||||||
.queryText(queryReq.getQueryText()).build());
|
.queryText(queryReq.getQueryText()).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,21 +14,27 @@ import com.tencent.supersonic.chat.api.pojo.request.QueryFilters;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.SearchResult;
|
import com.tencent.supersonic.chat.api.pojo.response.SearchResult;
|
||||||
import com.tencent.supersonic.chat.mapper.MapperHelper;
|
import com.tencent.supersonic.chat.mapper.MapperHelper;
|
||||||
import com.tencent.supersonic.chat.service.ConfigService;
|
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
|
||||||
import com.tencent.supersonic.knowledge.dictionary.ModelInfoStat;
|
|
||||||
import com.tencent.supersonic.chat.mapper.ModelWithSemanticType;
|
|
||||||
import com.tencent.supersonic.chat.mapper.MatchText;
|
import com.tencent.supersonic.chat.mapper.MatchText;
|
||||||
|
import com.tencent.supersonic.chat.mapper.ModelWithSemanticType;
|
||||||
import com.tencent.supersonic.chat.mapper.SearchMatchStrategy;
|
import com.tencent.supersonic.chat.mapper.SearchMatchStrategy;
|
||||||
import com.tencent.supersonic.chat.service.AgentService;
|
import com.tencent.supersonic.chat.service.AgentService;
|
||||||
import com.tencent.supersonic.chat.service.ChatService;
|
import com.tencent.supersonic.chat.service.ChatService;
|
||||||
|
import com.tencent.supersonic.chat.service.ConfigService;
|
||||||
import com.tencent.supersonic.chat.service.SearchService;
|
import com.tencent.supersonic.chat.service.SearchService;
|
||||||
import com.tencent.supersonic.knowledge.utils.NatureHelper;
|
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
||||||
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
||||||
import com.tencent.supersonic.knowledge.dictionary.HanlpMapResult;
|
import com.tencent.supersonic.knowledge.dictionary.HanlpMapResult;
|
||||||
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
import com.tencent.supersonic.knowledge.dictionary.ModelInfoStat;
|
||||||
import com.tencent.supersonic.knowledge.service.SchemaService;
|
import com.tencent.supersonic.knowledge.service.SchemaService;
|
||||||
import com.tencent.supersonic.knowledge.utils.HanlpHelper;
|
import com.tencent.supersonic.knowledge.utils.HanlpHelper;
|
||||||
|
import com.tencent.supersonic.knowledge.utils.NatureHelper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -41,11 +47,6 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,15 +153,13 @@ public class SearchServiceImpl implements SearchService {
|
|||||||
|
|
||||||
List<Long> possibleModels = NatureHelper.selectPossibleModels(originals);
|
List<Long> possibleModels = NatureHelper.selectPossibleModels(originals);
|
||||||
|
|
||||||
Long contextModel = chatService.getContextModel(queryCtx.getChatId());
|
Set<Long> contextModel = chatService.getContextModel(queryCtx.getChatId());
|
||||||
|
|
||||||
log.debug("possibleModels:{},modelStat:{},contextModel:{}", possibleModels, modelStat, contextModel);
|
log.debug("possibleModels:{},modelStat:{},contextModel:{}", possibleModels, modelStat, contextModel);
|
||||||
|
|
||||||
// If nothing is recognized or only metric are present, then add the contextModel.
|
// If nothing is recognized or only metric are present, then add the contextModel.
|
||||||
if (nothingOrOnlyMetric(modelStat) && effectiveModel(contextModel)) {
|
if (nothingOrOnlyMetric(modelStat)) {
|
||||||
List<Long> result = new ArrayList<>();
|
return contextModel.stream().filter(modelId -> modelId > 0).collect(Collectors.toList());
|
||||||
result.add(contextModel);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
return possibleModels;
|
return possibleModels;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package com.tencent.supersonic.chat.utils;
|
package com.tencent.supersonic.chat.utils;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
|
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
@@ -11,12 +8,20 @@ import com.tencent.supersonic.chat.api.pojo.request.KnowledgeAdvancedConfig;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeInfoReq;
|
import com.tencent.supersonic.chat.api.pojo.request.KnowledgeInfoReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatDefaultRichConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatDefaultRichConfigResp;
|
||||||
import com.tencent.supersonic.chat.config.Dim4Dict;
|
|
||||||
import com.tencent.supersonic.chat.config.DefaultMetric;
|
import com.tencent.supersonic.chat.config.DefaultMetric;
|
||||||
import com.tencent.supersonic.chat.service.ConfigService;
|
import com.tencent.supersonic.chat.config.Dim4Dict;
|
||||||
import com.tencent.supersonic.chat.persistence.dataobject.DimValueDO;
|
import com.tencent.supersonic.chat.persistence.dataobject.DimValueDO;
|
||||||
|
import com.tencent.supersonic.chat.service.ConfigService;
|
||||||
import com.tencent.supersonic.knowledge.dictionary.DictUpdateMode;
|
import com.tencent.supersonic.knowledge.dictionary.DictUpdateMode;
|
||||||
import com.tencent.supersonic.knowledge.dictionary.DimValue2DictCommand;
|
import com.tencent.supersonic.knowledge.dictionary.DimValue2DictCommand;
|
||||||
|
import com.tencent.supersonic.semantic.api.model.request.PageDimensionReq;
|
||||||
|
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -28,14 +33,8 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.tencent.supersonic.semantic.api.model.request.PageDimensionReq;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DictMetaHelper {
|
public class DictMetaHelper {
|
||||||
@@ -202,7 +201,7 @@ public class DictMetaHelper {
|
|||||||
if (Objects.nonNull(dimIdAndRespPair)
|
if (Objects.nonNull(dimIdAndRespPair)
|
||||||
&& dimIdAndRespPair.containsKey(dim4Dict.getDimId())) {
|
&& dimIdAndRespPair.containsKey(dim4Dict.getDimId())) {
|
||||||
String datasourceFilterSql = dimIdAndRespPair.get(
|
String datasourceFilterSql = dimIdAndRespPair.get(
|
||||||
dim4Dict.getDimId()).getDatasourceFilterSql();
|
dim4Dict.getDimId()).getModelFilterSql();
|
||||||
if (StringUtils.isNotEmpty(datasourceFilterSql)) {
|
if (StringUtils.isNotEmpty(datasourceFilterSql)) {
|
||||||
dim4Dict.getRuleList().add(datasourceFilterSql);
|
dim4Dict.getRuleList().add(datasourceFilterSql);
|
||||||
}
|
}
|
||||||
@@ -241,7 +240,7 @@ public class DictMetaHelper {
|
|||||||
PageInfo<DimensionResp> dimensionPage = semanticInterpreter.getDimensionPage(pageDimensionCmd);
|
PageInfo<DimensionResp> dimensionPage = semanticInterpreter.getDimensionPage(pageDimensionCmd);
|
||||||
if (Objects.nonNull(dimensionPage) && !CollectionUtils.isEmpty(dimensionPage.getList())) {
|
if (Objects.nonNull(dimensionPage) && !CollectionUtils.isEmpty(dimensionPage.getList())) {
|
||||||
List<DimensionResp> list = dimensionPage.getList();
|
List<DimensionResp> list = dimensionPage.getList();
|
||||||
return list.get(0).getDatasourceBizName();
|
return list.get(0).getModelBizName();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.tencent.supersonic.chat.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelCluster;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ModelClusterBuilder {
|
||||||
|
|
||||||
|
public static List<ModelCluster> buildModelClusters(SemanticSchema semanticSchema) {
|
||||||
|
Map<Long, ModelSchema> modelMap = semanticSchema.getModelSchemaMap();
|
||||||
|
Set<Long> visited = new HashSet<>();
|
||||||
|
List<Set<Long>> modelClusters = new ArrayList<>();
|
||||||
|
for (ModelSchema model : modelMap.values()) {
|
||||||
|
if (!visited.contains(model.getModel().getModel())) {
|
||||||
|
Set<Long> modelCluster = new HashSet<>();
|
||||||
|
dfs(model, modelMap, visited, modelCluster);
|
||||||
|
modelClusters.add(modelCluster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modelClusters.stream().map(ModelCluster::build).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dfs(ModelSchema model, Map<Long, ModelSchema> modelMap,
|
||||||
|
Set<Long> visited, Set<Long> modelCluster) {
|
||||||
|
visited.add(model.getModel().getModel());
|
||||||
|
modelCluster.add(model.getModel().getModel());
|
||||||
|
for (Long neighborId : model.getModelClusterSet()) {
|
||||||
|
if (!visited.contains(neighborId)) {
|
||||||
|
dfs(modelMap.get(neighborId), modelMap, visited, modelCluster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,6 +16,12 @@ import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
|||||||
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -25,18 +31,13 @@ import java.util.List;
|
|||||||
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 lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class QueryReqBuilder {
|
public class QueryReqBuilder {
|
||||||
|
|
||||||
public static QueryStructReq buildStructReq(SemanticParseInfo parseInfo) {
|
public static QueryStructReq buildStructReq(SemanticParseInfo parseInfo) {
|
||||||
QueryStructReq queryStructCmd = new QueryStructReq();
|
QueryStructReq queryStructCmd = new QueryStructReq();
|
||||||
queryStructCmd.setModelId(parseInfo.getModelId());
|
queryStructCmd.setModelIds(parseInfo.getModel().getModelIds());
|
||||||
queryStructCmd.setQueryType(parseInfo.getQueryType());
|
queryStructCmd.setQueryType(parseInfo.getQueryType());
|
||||||
queryStructCmd.setDateInfo(rewrite2Between(parseInfo.getDateInfo()));
|
queryStructCmd.setDateInfo(rewrite2Between(parseInfo.getDateInfo()));
|
||||||
|
|
||||||
@@ -128,15 +129,15 @@ public class QueryReqBuilder {
|
|||||||
* convert to QueryS2SQLReq
|
* convert to QueryS2SQLReq
|
||||||
*
|
*
|
||||||
* @param querySql
|
* @param querySql
|
||||||
* @param modelId
|
* @param modelIds
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static QueryS2SQLReq buildS2SQLReq(String querySql, Long modelId) {
|
public static QueryS2SQLReq buildS2SQLReq(String querySql, Set<Long> modelIds) {
|
||||||
QueryS2SQLReq queryS2SQLReq = new QueryS2SQLReq();
|
QueryS2SQLReq queryS2SQLReq = new QueryS2SQLReq();
|
||||||
if (Objects.nonNull(querySql)) {
|
if (Objects.nonNull(querySql)) {
|
||||||
queryS2SQLReq.setSql(querySql);
|
queryS2SQLReq.setSql(querySql);
|
||||||
}
|
}
|
||||||
queryS2SQLReq.setModelId(modelId);
|
queryS2SQLReq.setModelIds(modelIds);
|
||||||
return queryS2SQLReq;
|
return queryS2SQLReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ import com.tencent.supersonic.chat.api.pojo.ModelSchema;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.RelateSchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.RelateSchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -17,7 +20,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_necessaryDimension_groupBy() {
|
void testProcessCorrectSql_necessaryDimension_groupBy() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 用户名, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 用户名";
|
String correctSql = "select 用户名, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 用户名";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql, mockModelSchema());
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo, mockModelSchema());
|
||||||
String expectedProcessedSql = "SELECT 用户名, sum(访问次数) FROM 超音数 GROUP BY 用户名";
|
String expectedProcessedSql = "SELECT 用户名, sum(访问次数) FROM 超音数 GROUP BY 用户名";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
}
|
}
|
||||||
@@ -26,7 +30,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_necessaryDimension_where() {
|
void testProcessCorrectSql_necessaryDimension_where() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 用户名, sum(访问次数), count(distinct 访问用户数) from 超音数 where 部门 = 'HR' group by 用户名";
|
String correctSql = "select 用户名, sum(访问次数), count(distinct 访问用户数) from 超音数 where 部门 = 'HR' group by 用户名";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql, mockModelSchema());
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo, mockModelSchema());
|
||||||
String expectedProcessedSql = "SELECT 用户名, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 "
|
String expectedProcessedSql = "SELECT 用户名, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 "
|
||||||
+ "WHERE 部门 = 'HR' GROUP BY 用户名";
|
+ "WHERE 部门 = 'HR' GROUP BY 用户名";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
@@ -36,7 +41,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_dimensionNotDrillDown_groupBy() {
|
void testProcessCorrectSql_dimensionNotDrillDown_groupBy() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 页面, 部门, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 页面, 部门";
|
String correctSql = "select 页面, 部门, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 页面, 部门";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql, mockModelSchema());
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo, mockModelSchema());
|
||||||
String expectedProcessedSql = "SELECT 部门, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 部门";
|
String expectedProcessedSql = "SELECT 部门, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 部门";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
}
|
}
|
||||||
@@ -45,7 +51,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_dimensionNotDrillDown_where() {
|
void testProcessCorrectSql_dimensionNotDrillDown_where() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 部门, sum(访问次数), count(distinct 访问用户数) from 超音数 where 页面 = 'P1' group by 部门";
|
String correctSql = "select 部门, sum(访问次数), count(distinct 访问用户数) from 超音数 where 页面 = 'P1' group by 部门";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql, mockModelSchema());
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo, mockModelSchema());
|
||||||
String expectedProcessedSql = "SELECT 部门, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 部门";
|
String expectedProcessedSql = "SELECT 部门, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 部门";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
}
|
}
|
||||||
@@ -54,7 +61,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_dimensionNotDrillDown_necessaryDimension() {
|
void testProcessCorrectSql_dimensionNotDrillDown_necessaryDimension() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 页面, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 页面";
|
String correctSql = "select 页面, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 页面";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql, mockModelSchema());
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo, mockModelSchema());
|
||||||
String expectedProcessedSql = "SELECT sum(访问次数) FROM 超音数";
|
String expectedProcessedSql = "SELECT sum(访问次数) FROM 超音数";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
}
|
}
|
||||||
@@ -63,7 +71,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_dimensionDrillDown() {
|
void testProcessCorrectSql_dimensionDrillDown() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 用户名, 部门, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 用户名, 部门";
|
String correctSql = "select 用户名, 部门, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 用户名, 部门";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql, mockModelSchema());
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo, mockModelSchema());
|
||||||
String expectedProcessedSql = "SELECT 用户名, 部门, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 用户名, 部门";
|
String expectedProcessedSql = "SELECT 用户名, 部门, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 用户名, 部门";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
}
|
}
|
||||||
@@ -72,7 +81,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_noDrillDownDimensionSetting() {
|
void testProcessCorrectSql_noDrillDownDimensionSetting() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 页面, 用户名, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 页面, 用户名";
|
String correctSql = "select 页面, 用户名, sum(访问次数), count(distinct 访问用户数) from 超音数 group by 页面, 用户名";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql,
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo,
|
||||||
mockModelSchemaNoDimensionSetting());
|
mockModelSchemaNoDimensionSetting());
|
||||||
String expectedProcessedSql = "SELECT 页面, 用户名, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 页面, 用户名";
|
String expectedProcessedSql = "SELECT 页面, 用户名, sum(访问次数), count(DISTINCT 访问用户数) FROM 超音数 GROUP BY 页面, 用户名";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
@@ -82,7 +92,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_noDrillDownDimensionSetting_noAgg() {
|
void testProcessCorrectSql_noDrillDownDimensionSetting_noAgg() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 访问次数 from 超音数";
|
String correctSql = "select 访问次数 from 超音数";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql,
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo,
|
||||||
mockModelSchemaNoDimensionSetting());
|
mockModelSchemaNoDimensionSetting());
|
||||||
String expectedProcessedSql = "select 访问次数 from 超音数";
|
String expectedProcessedSql = "select 访问次数 from 超音数";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
@@ -92,7 +103,8 @@ class MetricCheckPostProcessorTest {
|
|||||||
void testProcessCorrectSql_noDrillDownDimensionSetting_count() {
|
void testProcessCorrectSql_noDrillDownDimensionSetting_count() {
|
||||||
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
MetricCheckPostProcessor metricCheckPostProcessor = new MetricCheckPostProcessor();
|
||||||
String correctSql = "select 部门, count(*) from 超音数 group by 部门";
|
String correctSql = "select 部门, count(*) from 超音数 group by 部门";
|
||||||
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(correctSql,
|
SemanticParseInfo parseInfo = mockParseInfo(correctSql);
|
||||||
|
String actualProcessedSql = metricCheckPostProcessor.processCorrectSql(parseInfo,
|
||||||
mockModelSchemaNoDimensionSetting());
|
mockModelSchemaNoDimensionSetting());
|
||||||
String expectedProcessedSql = "select 部门, count(*) from 超音数 group by 部门";
|
String expectedProcessedSql = "select 部门, count(*) from 超音数 group by 部门";
|
||||||
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
Assertions.assertEquals(expectedProcessedSql, actualProcessedSql);
|
||||||
@@ -102,7 +114,7 @@ class MetricCheckPostProcessorTest {
|
|||||||
* 访问次数 drill down dimension is 用户名 and 部门
|
* 访问次数 drill down dimension is 用户名 and 部门
|
||||||
* 访问用户数 drill down dimension is 部门, and 部门 is necessary, 部门 need in select and group by or where expressions
|
* 访问用户数 drill down dimension is 部门, and 部门 is necessary, 部门 need in select and group by or where expressions
|
||||||
*/
|
*/
|
||||||
private ModelSchema mockModelSchema() {
|
private SemanticSchema mockModelSchema() {
|
||||||
ModelSchema modelSchema = new ModelSchema();
|
ModelSchema modelSchema = new ModelSchema();
|
||||||
Set<SchemaElement> metrics = Sets.newHashSet(
|
Set<SchemaElement> metrics = Sets.newHashSet(
|
||||||
mockElement(1L, "访问次数", SchemaElementType.METRIC,
|
mockElement(1L, "访问次数", SchemaElementType.METRIC,
|
||||||
@@ -113,10 +125,10 @@ class MetricCheckPostProcessorTest {
|
|||||||
);
|
);
|
||||||
modelSchema.setMetrics(metrics);
|
modelSchema.setMetrics(metrics);
|
||||||
modelSchema.setDimensions(mockDimensions());
|
modelSchema.setDimensions(mockDimensions());
|
||||||
return modelSchema;
|
return new SemanticSchema(Lists.newArrayList(modelSchema));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelSchema mockModelSchemaNoDimensionSetting() {
|
private SemanticSchema mockModelSchemaNoDimensionSetting() {
|
||||||
ModelSchema modelSchema = new ModelSchema();
|
ModelSchema modelSchema = new ModelSchema();
|
||||||
Set<SchemaElement> metrics = Sets.newHashSet(
|
Set<SchemaElement> metrics = Sets.newHashSet(
|
||||||
mockElement(1L, "访问次数", SchemaElementType.METRIC, Lists.newArrayList()),
|
mockElement(1L, "访问次数", SchemaElementType.METRIC, Lists.newArrayList()),
|
||||||
@@ -124,7 +136,7 @@ class MetricCheckPostProcessorTest {
|
|||||||
);
|
);
|
||||||
modelSchema.setMetrics(metrics);
|
modelSchema.setMetrics(metrics);
|
||||||
modelSchema.setDimensions(mockDimensions());
|
modelSchema.setDimensions(mockDimensions());
|
||||||
return modelSchema;
|
return new SemanticSchema(Lists.newArrayList(modelSchema));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<SchemaElement> mockDimensions() {
|
private Set<SchemaElement> mockDimensions() {
|
||||||
@@ -141,4 +153,10 @@ class MetricCheckPostProcessorTest {
|
|||||||
.relateSchemaElements(relateSchemaElements).build();
|
.relateSchemaElements(relateSchemaElements).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SemanticParseInfo mockParseInfo(String correctSql) {
|
||||||
|
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
||||||
|
semanticParseInfo.getSqlInfo().setCorrectS2SQL(correctSql);
|
||||||
|
return semanticParseInfo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ import com.tencent.supersonic.chat.persistence.mapper.ChatContextMapper;
|
|||||||
import com.tencent.supersonic.knowledge.semantic.RemoteSemanticInterpreter;
|
import com.tencent.supersonic.knowledge.semantic.RemoteSemanticInterpreter;
|
||||||
import com.tencent.supersonic.chat.test.ChatBizLauncher;
|
import com.tencent.supersonic.chat.test.ChatBizLauncher;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
|
||||||
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
||||||
|
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||||
import com.tencent.supersonic.semantic.query.service.QueryService;
|
import com.tencent.supersonic.semantic.query.service.QueryService;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|||||||
@@ -1,32 +1,24 @@
|
|||||||
package com.tencent.supersonic.chat.test.context;
|
package com.tencent.supersonic.chat.test.context;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
||||||
import com.tencent.supersonic.chat.config.DefaultMetric;
|
import com.tencent.supersonic.chat.config.DefaultMetric;
|
||||||
import com.tencent.supersonic.chat.config.DefaultMetricInfo;
|
import com.tencent.supersonic.chat.config.DefaultMetricInfo;
|
||||||
import com.tencent.supersonic.chat.config.EntityInternalDetail;
|
import com.tencent.supersonic.chat.config.EntityInternalDetail;
|
||||||
|
import com.tencent.supersonic.chat.persistence.mapper.ChatContextMapper;
|
||||||
import com.tencent.supersonic.chat.persistence.repository.impl.ChatContextRepositoryImpl;
|
import com.tencent.supersonic.chat.persistence.repository.impl.ChatContextRepositoryImpl;
|
||||||
|
import com.tencent.supersonic.chat.service.ChatService;
|
||||||
import com.tencent.supersonic.chat.service.QueryService;
|
import com.tencent.supersonic.chat.service.QueryService;
|
||||||
|
import com.tencent.supersonic.chat.service.impl.ConfigServiceImpl;
|
||||||
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DimSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.DimSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
import com.tencent.supersonic.semantic.api.model.response.MetricResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.MetricSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.MetricSchemaResp;
|
||||||
import com.tencent.supersonic.chat.service.impl.ConfigServiceImpl;
|
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||||
import com.tencent.supersonic.chat.service.ChatService;
|
|
||||||
import com.tencent.supersonic.chat.persistence.mapper.ChatContextMapper;
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
|
||||||
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
||||||
import java.util.ArrayList;
|
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
|
import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
|
||||||
import com.tencent.supersonic.semantic.model.domain.pojo.MetaFilter;
|
import com.tencent.supersonic.semantic.model.domain.pojo.MetaFilter;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -34,6 +26,14 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class MockBeansConfiguration {
|
public class MockBeansConfiguration {
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,20 @@ import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
|||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryDimValueReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryDimValueReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
||||||
|
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
||||||
import com.tencent.supersonic.semantic.query.service.QueryService;
|
import com.tencent.supersonic.semantic.query.service.QueryService;
|
||||||
import com.tencent.supersonic.semantic.query.service.SchemaService;
|
import com.tencent.supersonic.semantic.query.service.SchemaService;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LocalSemanticInterpreter extends BaseSemanticInterpreter {
|
public class LocalSemanticInterpreter extends BaseSemanticInterpreter {
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public class LocalSemanticInterpreter extends BaseSemanticInterpreter {
|
|||||||
if (StringUtils.isNotBlank(queryStructReq.getCorrectS2SQL())) {
|
if (StringUtils.isNotBlank(queryStructReq.getCorrectS2SQL())) {
|
||||||
QueryS2SQLReq queryS2SQLReq = new QueryS2SQLReq();
|
QueryS2SQLReq queryS2SQLReq = new QueryS2SQLReq();
|
||||||
queryS2SQLReq.setSql(queryStructReq.getCorrectS2SQL());
|
queryS2SQLReq.setSql(queryStructReq.getCorrectS2SQL());
|
||||||
queryS2SQLReq.setModelId(queryStructReq.getModelId());
|
queryS2SQLReq.setModelIds(queryStructReq.getModelIdSet());
|
||||||
queryS2SQLReq.setVariables(new HashMap<>());
|
queryS2SQLReq.setVariables(new HashMap<>());
|
||||||
return queryByS2SQL(queryS2SQLReq, user);
|
return queryByS2SQL(queryS2SQLReq, user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaValueMap;
|
import com.tencent.supersonic.chat.api.pojo.SchemaValueMap;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.DimValueMap;
|
import com.tencent.supersonic.semantic.api.model.pojo.DimValueMap;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Entity;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.RelateDimension;
|
import com.tencent.supersonic.semantic.api.model.pojo.RelateDimension;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.DimSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.DimSchemaResp;
|
||||||
@@ -20,8 +19,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -38,6 +35,7 @@ public class ModelSchemaBuilder {
|
|||||||
.alias(SchemaItem.getAliasList(resp.getAlias()))
|
.alias(SchemaItem.getAliasList(resp.getAlias()))
|
||||||
.build();
|
.build();
|
||||||
modelSchema.setModel(domain);
|
modelSchema.setModel(domain);
|
||||||
|
modelSchema.setModelRelas(resp.getModelRelas());
|
||||||
|
|
||||||
Set<SchemaElement> metrics = new HashSet<>();
|
Set<SchemaElement> metrics = new HashSet<>();
|
||||||
for (MetricSchemaResp metric : resp.getMetrics()) {
|
for (MetricSchemaResp metric : resp.getMetrics()) {
|
||||||
@@ -124,23 +122,19 @@ public class ModelSchemaBuilder {
|
|||||||
modelSchema.getDimensionValues().addAll(dimensionValues);
|
modelSchema.getDimensionValues().addAll(dimensionValues);
|
||||||
modelSchema.getTags().addAll(tags);
|
modelSchema.getTags().addAll(tags);
|
||||||
|
|
||||||
Entity entity = resp.getEntity();
|
DimSchemaResp dim = resp.getPrimaryKey();
|
||||||
if (Objects.nonNull(entity)) {
|
if (dim != null) {
|
||||||
SchemaElement entityElement = new SchemaElement();
|
SchemaElement entity = SchemaElement.builder()
|
||||||
|
.model(resp.getId())
|
||||||
if (!CollectionUtils.isEmpty(entity.getNames()) && Objects.nonNull(entity.getEntityId())) {
|
.id(dim.getId())
|
||||||
Map<Long, SchemaElement> idAndDimPair = dimensions.stream()
|
.name(dim.getName())
|
||||||
.collect(
|
.bizName(dim.getBizName())
|
||||||
Collectors.toMap(SchemaElement::getId, schemaElement -> schemaElement, (k1, k2) -> k2));
|
.type(SchemaElementType.ENTITY)
|
||||||
if (idAndDimPair.containsKey(entity.getEntityId())) {
|
.useCnt(dim.getUseCnt())
|
||||||
BeanUtils.copyProperties(idAndDimPair.get(entity.getEntityId()), entityElement);
|
.alias(dim.getEntityAlias())
|
||||||
entityElement.setType(SchemaElementType.ENTITY);
|
.build();
|
||||||
}
|
modelSchema.setEntity(entity);
|
||||||
entityElement.setAlias(entity.getNames());
|
|
||||||
modelSchema.setEntity(entityElement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return modelSchema;
|
return modelSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package com.tencent.supersonic.knowledge.semantic;
|
package com.tencent.supersonic.knowledge.semantic;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.LIST_LOWER;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.PAGESIZE_LOWER;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.TOTAL_LOWER;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.TRUE_LOWER;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -31,15 +26,9 @@ import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
|||||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
import com.tencent.supersonic.semantic.api.query.request.ExplainSqlReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryDimValueReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryDimValueReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
|
||||||
|
import com.tencent.supersonic.semantic.api.query.request.QueryS2SQLReq;
|
||||||
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
@@ -53,6 +42,18 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.LIST_LOWER;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.PAGESIZE_LOWER;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.TOTAL_LOWER;
|
||||||
|
import static com.tencent.supersonic.common.pojo.Constants.TRUE_LOWER;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RemoteSemanticInterpreter extends BaseSemanticInterpreter {
|
public class RemoteSemanticInterpreter extends BaseSemanticInterpreter {
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ public class RemoteSemanticInterpreter extends BaseSemanticInterpreter {
|
|||||||
if (StringUtils.isNotBlank(queryStructReq.getCorrectS2SQL())) {
|
if (StringUtils.isNotBlank(queryStructReq.getCorrectS2SQL())) {
|
||||||
QueryS2SQLReq queryS2SQLReq = new QueryS2SQLReq();
|
QueryS2SQLReq queryS2SQLReq = new QueryS2SQLReq();
|
||||||
queryS2SQLReq.setSql(queryStructReq.getCorrectS2SQL());
|
queryS2SQLReq.setSql(queryStructReq.getCorrectS2SQL());
|
||||||
queryS2SQLReq.setModelId(queryStructReq.getModelId());
|
queryS2SQLReq.setModelIds(queryStructReq.getModelIdSet());
|
||||||
queryS2SQLReq.setVariables(new HashMap<>());
|
queryS2SQLReq.setVariables(new HashMap<>());
|
||||||
return queryByS2SQL(queryS2SQLReq, user);
|
return queryByS2SQL(queryS2SQLReq, user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.tencent.supersonic.common.pojo;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class JoinCondition {
|
||||||
|
|
||||||
|
private String leftField;
|
||||||
|
|
||||||
|
private String rightField;
|
||||||
|
|
||||||
|
private FilterOperatorEnum operator;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.tencent.supersonic.common.pojo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ModelCluster {
|
||||||
|
|
||||||
|
private static final String split = "_";
|
||||||
|
|
||||||
|
private Set<Long> modelIds = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public static ModelCluster build(Set<Long> modelIds) {
|
||||||
|
ModelCluster modelCluster = new ModelCluster();
|
||||||
|
modelCluster.setModelIds(modelIds);
|
||||||
|
modelCluster.setKey(StringUtils.join(modelIds, split));
|
||||||
|
return modelCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ModelCluster build(String key) {
|
||||||
|
ModelCluster modelCluster = new ModelCluster();
|
||||||
|
modelCluster.setModelIds(getModelIdFromKey(key));
|
||||||
|
modelCluster.setKey(key);
|
||||||
|
return modelCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildName(Map<Long, String> modelNameMap) {
|
||||||
|
name = modelNameMap.entrySet().stream().filter(entry ->
|
||||||
|
modelIds.contains(entry.getKey())).map(Map.Entry::getValue)
|
||||||
|
.collect(Collectors.joining(split));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<Long> getModelIdFromKey(String key) {
|
||||||
|
return Arrays.stream(key.split(split))
|
||||||
|
.map(Long::parseLong).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getFirstModel() {
|
||||||
|
return modelIds.stream().findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.tencent.supersonic.common.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ModelRela extends RecordInfo {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private Long domainId;
|
||||||
|
|
||||||
|
private Long fromModelId;
|
||||||
|
|
||||||
|
private Long toModelId;
|
||||||
|
|
||||||
|
//left join, inner join, right join, outer join
|
||||||
|
private String joinType;
|
||||||
|
|
||||||
|
private List<JoinCondition> joinConditions;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -42,4 +42,11 @@ public enum FilterOperatorEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isValueCompare(FilterOperatorEnum filterOperatorEnum) {
|
||||||
|
return EQUALS.equals(filterOperatorEnum) || GREATER_THAN.equals(filterOperatorEnum)
|
||||||
|
|| GREATER_THAN_EQUALS.equals(filterOperatorEnum) || MINOR_THAN.equals(filterOperatorEnum)
|
||||||
|
|| MINOR_THAN_EQUALS.equals(filterOperatorEnum) || NOT_EQUALS.equals(filterOperatorEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
package com.tencent.supersonic.common.util.jsqlparser;
|
package com.tencent.supersonic.common.util.jsqlparser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.JSQLParserException;
|
import net.sf.jsqlparser.JSQLParserException;
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
@@ -35,6 +29,13 @@ import net.sf.jsqlparser.statement.select.SubSelect;
|
|||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sql Parser Select Helper
|
* Sql Parser Select Helper
|
||||||
*/
|
*/
|
||||||
@@ -111,7 +112,7 @@ public class SqlParserSelectHelper {
|
|||||||
try {
|
try {
|
||||||
statement = CCJSqlParserUtil.parse(sql);
|
statement = CCJSqlParserUtil.parse(sql);
|
||||||
} catch (JSQLParserException e) {
|
} catch (JSQLParserException e) {
|
||||||
log.error("parse error", e);
|
log.error("parse error, sql:{}", sql, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -109,12 +110,12 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
|
|
||||||
public void addDemoChatConfig_1() {
|
public void addDemoChatConfig_1() {
|
||||||
ChatConfigBaseReq chatConfigBaseReq = new ChatConfigBaseReq();
|
ChatConfigBaseReq chatConfigBaseReq = new ChatConfigBaseReq();
|
||||||
chatConfigBaseReq.setModelId(1L);
|
chatConfigBaseReq.setModelId(2L);
|
||||||
|
|
||||||
ChatDetailConfigReq chatDetailConfig = new ChatDetailConfigReq();
|
ChatDetailConfigReq chatDetailConfig = new ChatDetailConfigReq();
|
||||||
ChatDefaultConfigReq chatDefaultConfigDetail = new ChatDefaultConfigReq();
|
ChatDefaultConfigReq chatDefaultConfigDetail = new ChatDefaultConfigReq();
|
||||||
List<Long> dimensionIds0 = Arrays.asList(1L, 2L);
|
List<Long> dimensionIds0 = Collections.singletonList(3L);
|
||||||
List<Long> metricIds0 = Arrays.asList(1L);
|
List<Long> metricIds0 = Arrays.asList(1L, 2L);
|
||||||
chatDefaultConfigDetail.setDimensionIds(dimensionIds0);
|
chatDefaultConfigDetail.setDimensionIds(dimensionIds0);
|
||||||
chatDefaultConfigDetail.setMetricIds(metricIds0);
|
chatDefaultConfigDetail.setMetricIds(metricIds0);
|
||||||
chatDefaultConfigDetail.setUnit(7);
|
chatDefaultConfigDetail.setUnit(7);
|
||||||
@@ -126,8 +127,8 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
|
|
||||||
ChatAggConfigReq chatAggConfig = new ChatAggConfigReq();
|
ChatAggConfigReq chatAggConfig = new ChatAggConfigReq();
|
||||||
ChatDefaultConfigReq chatDefaultConfigAgg = new ChatDefaultConfigReq();
|
ChatDefaultConfigReq chatDefaultConfigAgg = new ChatDefaultConfigReq();
|
||||||
List<Long> dimensionIds1 = Arrays.asList(1L, 2L);
|
List<Long> dimensionIds1 = Arrays.asList(3L);
|
||||||
List<Long> metricIds1 = Arrays.asList(1L);
|
List<Long> metricIds1 = Arrays.asList(1L, 2L);
|
||||||
chatDefaultConfigAgg.setDimensionIds(dimensionIds1);
|
chatDefaultConfigAgg.setDimensionIds(dimensionIds1);
|
||||||
chatDefaultConfigAgg.setMetricIds(metricIds1);
|
chatDefaultConfigAgg.setMetricIds(metricIds1);
|
||||||
chatDefaultConfigAgg.setUnit(7);
|
chatDefaultConfigAgg.setUnit(7);
|
||||||
@@ -138,34 +139,60 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
chatAggConfig.setVisibility(visibility1);
|
chatAggConfig.setVisibility(visibility1);
|
||||||
List<KnowledgeInfoReq> knowledgeInfos = new ArrayList<>();
|
List<KnowledgeInfoReq> knowledgeInfos = new ArrayList<>();
|
||||||
KnowledgeInfoReq knowledgeInfoReq = new KnowledgeInfoReq();
|
KnowledgeInfoReq knowledgeInfoReq = new KnowledgeInfoReq();
|
||||||
knowledgeInfoReq.setItemId(1L);
|
knowledgeInfoReq.setItemId(3L);
|
||||||
knowledgeInfoReq.setSearchEnable(true);
|
knowledgeInfoReq.setSearchEnable(true);
|
||||||
knowledgeInfos.add(knowledgeInfoReq);
|
knowledgeInfos.add(knowledgeInfoReq);
|
||||||
KnowledgeInfoReq knowledgeInfoReq2 = new KnowledgeInfoReq();
|
|
||||||
knowledgeInfoReq2.setItemId(2L);
|
|
||||||
knowledgeInfoReq2.setSearchEnable(true);
|
|
||||||
knowledgeInfos.add(knowledgeInfoReq2);
|
|
||||||
chatAggConfig.setKnowledgeInfos(knowledgeInfos);
|
chatAggConfig.setKnowledgeInfos(knowledgeInfos);
|
||||||
chatConfigBaseReq.setChatAggConfig(chatAggConfig);
|
chatConfigBaseReq.setChatAggConfig(chatAggConfig);
|
||||||
|
|
||||||
List<RecommendedQuestionReq> recommendedQuestions = new ArrayList<>();
|
|
||||||
recommendedQuestions.add(new RecommendedQuestionReq("超音数访问次数"));
|
|
||||||
recommendedQuestions.add(new RecommendedQuestionReq("近15天超音数访问次数汇总"));
|
|
||||||
recommendedQuestions.add(new RecommendedQuestionReq("按部门统计超音数的访问人数"));
|
|
||||||
recommendedQuestions.add(new RecommendedQuestionReq("对比alice和lucy的停留时长"));
|
|
||||||
recommendedQuestions.add(new RecommendedQuestionReq("超音数访问次数最高的部门"));
|
|
||||||
chatConfigBaseReq.setRecommendedQuestions(recommendedQuestions);
|
|
||||||
|
|
||||||
configService.addConfig(chatConfigBaseReq, user);
|
configService.addConfig(chatConfigBaseReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDemoChatConfig_2() {
|
public void addDemoChatConfig_2() {
|
||||||
ChatConfigBaseReq chatConfigBaseReq = new ChatConfigBaseReq();
|
ChatConfigBaseReq chatConfigBaseReq = new ChatConfigBaseReq();
|
||||||
chatConfigBaseReq.setModelId(2L);
|
chatConfigBaseReq.setModelId(3L);
|
||||||
|
|
||||||
ChatDetailConfigReq chatDetailConfig = new ChatDetailConfigReq();
|
ChatDetailConfigReq chatDetailConfig = new ChatDetailConfigReq();
|
||||||
ChatDefaultConfigReq chatDefaultConfigDetail = new ChatDefaultConfigReq();
|
ChatDefaultConfigReq chatDefaultConfigDetail = new ChatDefaultConfigReq();
|
||||||
List<Long> dimensionIds0 = Arrays.asList(4L, 5L, 6L, 7L);
|
List<Long> dimensionIds0 = Arrays.asList(4L, 5L);
|
||||||
|
List<Long> metricIds0 = Arrays.asList(3L);
|
||||||
|
chatDefaultConfigDetail.setDimensionIds(dimensionIds0);
|
||||||
|
chatDefaultConfigDetail.setMetricIds(metricIds0);
|
||||||
|
chatDefaultConfigDetail.setUnit(7);
|
||||||
|
chatDefaultConfigDetail.setPeriod("DAY");
|
||||||
|
chatDetailConfig.setChatDefaultConfig(chatDefaultConfigDetail);
|
||||||
|
ItemVisibility visibility0 = new ItemVisibility();
|
||||||
|
chatDetailConfig.setVisibility(visibility0);
|
||||||
|
chatConfigBaseReq.setChatDetailConfig(chatDetailConfig);
|
||||||
|
|
||||||
|
ChatAggConfigReq chatAggConfig = new ChatAggConfigReq();
|
||||||
|
ChatDefaultConfigReq chatDefaultConfigAgg = new ChatDefaultConfigReq();
|
||||||
|
List<Long> dimensionIds1 = Arrays.asList(4L, 5L);
|
||||||
|
List<Long> metricIds1 = Arrays.asList(3L);
|
||||||
|
chatDefaultConfigAgg.setDimensionIds(dimensionIds1);
|
||||||
|
chatDefaultConfigAgg.setMetricIds(metricIds1);
|
||||||
|
chatDefaultConfigAgg.setUnit(7);
|
||||||
|
chatDefaultConfigAgg.setPeriod("DAY");
|
||||||
|
chatDefaultConfigAgg.setTimeMode(ChatDefaultConfigReq.TimeMode.RECENT);
|
||||||
|
chatAggConfig.setChatDefaultConfig(chatDefaultConfigAgg);
|
||||||
|
ItemVisibility visibility1 = new ItemVisibility();
|
||||||
|
chatAggConfig.setVisibility(visibility1);
|
||||||
|
List<KnowledgeInfoReq> knowledgeInfos = new ArrayList<>();
|
||||||
|
KnowledgeInfoReq knowledgeInfoReq = new KnowledgeInfoReq();
|
||||||
|
knowledgeInfoReq.setItemId(5L);
|
||||||
|
knowledgeInfoReq.setSearchEnable(true);
|
||||||
|
knowledgeInfos.add(knowledgeInfoReq);
|
||||||
|
chatAggConfig.setKnowledgeInfos(knowledgeInfos);
|
||||||
|
chatConfigBaseReq.setChatAggConfig(chatAggConfig);
|
||||||
|
configService.addConfig(chatConfigBaseReq, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDemoChatConfig_3() {
|
||||||
|
ChatConfigBaseReq chatConfigBaseReq = new ChatConfigBaseReq();
|
||||||
|
chatConfigBaseReq.setModelId(4L);
|
||||||
|
|
||||||
|
ChatDetailConfigReq chatDetailConfig = new ChatDetailConfigReq();
|
||||||
|
ChatDefaultConfigReq chatDefaultConfigDetail = new ChatDefaultConfigReq();
|
||||||
|
List<Long> dimensionIds0 = Arrays.asList(6L, 7L, 8L, 9L);
|
||||||
List<Long> metricIds0 = Arrays.asList(4L);
|
List<Long> metricIds0 = Arrays.asList(4L);
|
||||||
chatDefaultConfigDetail.setDimensionIds(dimensionIds0);
|
chatDefaultConfigDetail.setDimensionIds(dimensionIds0);
|
||||||
chatDefaultConfigDetail.setMetricIds(metricIds0);
|
chatDefaultConfigDetail.setMetricIds(metricIds0);
|
||||||
@@ -178,7 +205,7 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
|
|
||||||
ChatAggConfigReq chatAggConfig = new ChatAggConfigReq();
|
ChatAggConfigReq chatAggConfig = new ChatAggConfigReq();
|
||||||
ChatDefaultConfigReq chatDefaultConfigAgg = new ChatDefaultConfigReq();
|
ChatDefaultConfigReq chatDefaultConfigAgg = new ChatDefaultConfigReq();
|
||||||
List<Long> dimensionIds1 = Arrays.asList(4L, 5L, 6L, 7L);
|
List<Long> dimensionIds1 = Arrays.asList(6L, 7L, 8L, 9L);
|
||||||
List<Long> metricIds1 = Arrays.asList(4L);
|
List<Long> metricIds1 = Arrays.asList(4L);
|
||||||
chatDefaultConfigAgg.setDimensionIds(dimensionIds1);
|
chatDefaultConfigAgg.setDimensionIds(dimensionIds1);
|
||||||
chatDefaultConfigAgg.setMetricIds(metricIds1);
|
chatDefaultConfigAgg.setMetricIds(metricIds1);
|
||||||
@@ -255,8 +282,8 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
private void addAgent2() {
|
private void addAgent2() {
|
||||||
Agent agent = new Agent();
|
Agent agent = new Agent();
|
||||||
agent.setId(2);
|
agent.setId(2);
|
||||||
agent.setName("圈实体");
|
agent.setName("标签圈选");
|
||||||
agent.setDescription("帮助您用自然语言圈选实体,支持多条件组合筛选");
|
agent.setDescription("帮助您用自然语言进行圈选,支持多条件组合筛选");
|
||||||
agent.setStatus(1);
|
agent.setStatus(1);
|
||||||
agent.setEnableSearch(1);
|
agent.setEnableSearch(1);
|
||||||
agent.setExamples(Lists.newArrayList("国风风格艺人", "港台地区的艺人", "风格为流行的艺人"));
|
agent.setExamples(Lists.newArrayList("国风风格艺人", "港台地区的艺人", "风格为流行的艺人"));
|
||||||
@@ -266,7 +293,7 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
ruleQueryTool.setType(AgentToolType.RULE);
|
ruleQueryTool.setType(AgentToolType.RULE);
|
||||||
ruleQueryTool.setModelIds(Lists.newArrayList(-1L));
|
ruleQueryTool.setModelIds(Lists.newArrayList(-1L));
|
||||||
ruleQueryTool.setQueryModes(Lists.newArrayList(
|
ruleQueryTool.setQueryModes(Lists.newArrayList(
|
||||||
"ENTITY_DETAIL", "ENTITY_LIST_FILTER", "ENTITY_ID"));
|
"TAG_DETAIL", "TAG_LIST_FILTER", "TAG_ID"));
|
||||||
agentConfig.getTools().add(ruleQueryTool);
|
agentConfig.getTools().add(ruleQueryTool);
|
||||||
|
|
||||||
LLMParserTool llmParserTool = new LLMParserTool();
|
LLMParserTool llmParserTool = new LLMParserTool();
|
||||||
@@ -310,6 +337,7 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
addSysParameter();
|
addSysParameter();
|
||||||
addDemoChatConfig_1();
|
addDemoChatConfig_1();
|
||||||
addDemoChatConfig_2();
|
addDemoChatConfig_2();
|
||||||
|
addDemoChatConfig_3();
|
||||||
addPlugin_1();
|
addPlugin_1();
|
||||||
addAgent1();
|
addAgent1();
|
||||||
addAgent2();
|
addAgent2();
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
|||||||
import com.tencent.supersonic.semantic.api.model.pojo.DimensionTimeTypeParams;
|
import com.tencent.supersonic.semantic.api.model.pojo.DimensionTimeTypeParams;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.DatasourceReq;
|
import com.tencent.supersonic.semantic.api.model.pojo.ModelDetail;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.DomainReq;
|
import com.tencent.supersonic.semantic.api.model.request.DomainReq;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DatasourceService;
|
|
||||||
import com.tencent.supersonic.semantic.model.domain.DomainService;
|
import com.tencent.supersonic.semantic.model.domain.DomainService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -20,6 +19,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -39,8 +39,6 @@ public class LoadBenchMarkDemo implements CommandLineRunner {
|
|||||||
private DomainService domainService;
|
private DomainService domainService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ModelService modelService;
|
private ModelService modelService;
|
||||||
@Autowired
|
|
||||||
private DatasourceService datasourceService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) {
|
public void run(String... args) {
|
||||||
@@ -48,12 +46,11 @@ public class LoadBenchMarkDemo implements CommandLineRunner {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
addDomain();
|
//addDomain();
|
||||||
addModel_1();
|
//addModel_1();
|
||||||
addDatasource_1();
|
//addModel_2();
|
||||||
addDatasource_2();
|
//addModel_3();
|
||||||
addDatasource_3();
|
//addModel_4();
|
||||||
addDatasource_4();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to add bench mark demo data", e);
|
log.error("Failed to add bench mark demo data", e);
|
||||||
}
|
}
|
||||||
@@ -72,105 +69,97 @@ public class LoadBenchMarkDemo implements CommandLineRunner {
|
|||||||
domainService.createDomain(domainReq, user);
|
domainService.createDomain(domainReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModel_1() {
|
public void addModel_1() throws Exception {
|
||||||
ModelReq modelReq = new ModelReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
modelReq.setName("测评数据_音乐");
|
modelReq.setDomainId(3L);
|
||||||
modelReq.setBizName("music");
|
modelReq.setName("艺术类型");
|
||||||
modelReq.setDomainId(2L);
|
modelReq.setBizName("genre");
|
||||||
|
modelReq.setDescription("艺术类型");
|
||||||
|
modelReq.setDatabaseId(1L);
|
||||||
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
modelReq.setAdmins(Collections.singletonList("admin"));
|
modelReq.setAdmins(Collections.singletonList("admin"));
|
||||||
modelReq.setAdminOrgs(Collections.emptyList());
|
modelReq.setAdminOrgs(Collections.emptyList());
|
||||||
modelService.createModel(modelReq, user);
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
}
|
|
||||||
|
|
||||||
public void addDatasource_1() throws Exception {
|
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
|
||||||
datasourceReq.setModelId(3L);
|
|
||||||
datasourceReq.setName("艺术类型");
|
|
||||||
datasourceReq.setBizName("genre");
|
|
||||||
datasourceReq.setDescription("艺术类型");
|
|
||||||
datasourceReq.setDatabaseId(1L);
|
|
||||||
|
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
||||||
dimension1.setTypeParams(new DimensionTimeTypeParams());
|
dimension1.setTypeParams(new DimensionTimeTypeParams());
|
||||||
dimensions.add(dimension1);
|
dimensions.add(dimension1);
|
||||||
dimensions.add(new Dim("活跃区域", "most_popular_in", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("活跃区域", "most_popular_in", DimensionTypeEnum.categorical.name(), 1));
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("音乐类型名称", IdentifyTypeEnum.primary.name(), "g_name"));
|
identifiers.add(new Identify("音乐类型名称", IdentifyTypeEnum.primary.name(), "g_name"));
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
List<Measure> measures = new ArrayList<>();
|
List<Measure> measures = new ArrayList<>();
|
||||||
Measure measure = new Measure("评分", "rating", AggOperatorEnum.SUM.name(), 0);
|
Measure measure = new Measure("评分", "rating", AggOperatorEnum.SUM.name(), 0);
|
||||||
measures.add(measure);
|
measures.add(measure);
|
||||||
datasourceReq.setMeasures(measures);
|
modelDetail.setMeasures(measures);
|
||||||
|
|
||||||
datasourceReq.setQueryType("sql_query");
|
modelDetail.setQueryType("sql_query");
|
||||||
datasourceReq.setSqlQuery("SELECT g_name, rating, most_popular_in FROM genre");
|
modelDetail.setSqlQuery("SELECT g_name, rating, most_popular_in FROM genre");
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDatasource_2() throws Exception {
|
public void addModel_2() throws Exception {
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
datasourceReq.setModelId(3L);
|
modelReq.setDomainId(3L);
|
||||||
datasourceReq.setName("艺术家");
|
modelReq.setName("艺术家");
|
||||||
datasourceReq.setBizName("artist");
|
modelReq.setBizName("artist");
|
||||||
datasourceReq.setDescription("艺术家");
|
modelReq.setDescription("艺术家");
|
||||||
datasourceReq.setDatabaseId(1L);
|
modelReq.setDatabaseId(1L);
|
||||||
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
dimensions.add(new Dim("国籍", "country", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("国籍", "country", DimensionTypeEnum.categorical.name(), 1));
|
||||||
dimensions.add(new Dim("性别", "gender", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("性别", "gender", DimensionTypeEnum.categorical.name(), 1));
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("艺术家名称", IdentifyTypeEnum.primary.name(), "artist_name"));
|
identifiers.add(new Identify("艺术家名称", IdentifyTypeEnum.primary.name(), "artist_name"));
|
||||||
identifiers.add(new Identify("音乐类型名称", IdentifyTypeEnum.foreign.name(), "g_name"));
|
identifiers.add(new Identify("音乐类型名称", IdentifyTypeEnum.foreign.name(), "g_name"));
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
datasourceReq.setMeasures(Collections.emptyList());
|
modelDetail.setMeasures(Collections.emptyList());
|
||||||
|
|
||||||
datasourceReq.setQueryType("sql_query");
|
modelDetail.setQueryType("sql_query");
|
||||||
datasourceReq.setSqlQuery("SELECT artist_name, country, gender, g_name FROM artist");
|
modelDetail.setSqlQuery("SELECT artist_name, country, gender, g_name FROM artist");
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDatasource_3() throws Exception {
|
public void addModel_3() throws Exception {
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
datasourceReq.setModelId(3L);
|
modelReq.setDomainId(3L);
|
||||||
datasourceReq.setName("文件");
|
modelReq.setName("文件");
|
||||||
datasourceReq.setBizName("files");
|
modelReq.setBizName("files");
|
||||||
datasourceReq.setDescription("文件");
|
modelReq.setDescription("文件");
|
||||||
datasourceReq.setDatabaseId(1L);
|
modelReq.setDatabaseId(1L);
|
||||||
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
dimensions.add(new Dim("持续时间", "duration", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("持续时间", "duration", DimensionTypeEnum.categorical.name(), 1));
|
||||||
dimensions.add(new Dim("文件格式", "formats", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("文件格式", "formats", DimensionTypeEnum.categorical.name(), 1));
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("歌曲ID", IdentifyTypeEnum.primary.name(), "f_id"));
|
identifiers.add(new Identify("歌曲ID", IdentifyTypeEnum.primary.name(), "f_id"));
|
||||||
identifiers.add(new Identify("艺术家名称", IdentifyTypeEnum.foreign.name(), "artist_name"));
|
identifiers.add(new Identify("艺术家名称", IdentifyTypeEnum.foreign.name(), "artist_name"));
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
datasourceReq.setMeasures(Collections.emptyList());
|
modelDetail.setMeasures(Collections.emptyList());
|
||||||
|
|
||||||
datasourceReq.setQueryType("sql_query");
|
modelDetail.setQueryType("sql_query");
|
||||||
datasourceReq.setSqlQuery("SELECT f_id, artist_name, file_size, duration, formats FROM files");
|
modelDetail.setSqlQuery("SELECT f_id, artist_name, file_size, duration, formats FROM files");
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDatasource_4() throws Exception {
|
public void addModel_4() throws Exception {
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
datasourceReq.setModelId(3L);
|
modelReq.setDomainId(3L);
|
||||||
datasourceReq.setName("歌曲");
|
modelReq.setName("歌曲");
|
||||||
datasourceReq.setBizName("song");
|
modelReq.setBizName("song");
|
||||||
datasourceReq.setDescription("歌曲");
|
modelReq.setDescription("歌曲");
|
||||||
datasourceReq.setDatabaseId(1L);
|
modelReq.setDatabaseId(1L);
|
||||||
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
||||||
dimension1.setTypeParams(new DimensionTimeTypeParams());
|
dimension1.setTypeParams(new DimensionTimeTypeParams());
|
||||||
@@ -178,22 +167,22 @@ public class LoadBenchMarkDemo implements CommandLineRunner {
|
|||||||
dimensions.add(new Dim("国家", "country", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("国家", "country", DimensionTypeEnum.categorical.name(), 1));
|
||||||
dimensions.add(new Dim("语种", "languages", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("语种", "languages", DimensionTypeEnum.categorical.name(), 1));
|
||||||
dimensions.add(new Dim("发行时间", "releasedate", DimensionTypeEnum.categorical.name(), 1));
|
dimensions.add(new Dim("发行时间", "releasedate", DimensionTypeEnum.categorical.name(), 1));
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("歌曲名称", IdentifyTypeEnum.primary.name(), "song_name"));
|
identifiers.add(new Identify("歌曲名称", IdentifyTypeEnum.primary.name(), "song_name"));
|
||||||
identifiers.add(new Identify("歌曲ID", IdentifyTypeEnum.foreign.name(), "f_id"));
|
identifiers.add(new Identify("歌曲ID", IdentifyTypeEnum.foreign.name(), "f_id"));
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
List<Measure> measures = new ArrayList<>();
|
List<Measure> measures = new ArrayList<>();
|
||||||
measures.add(new Measure("分辨率", "resolution", AggOperatorEnum.SUM.name(), 1));
|
measures.add(new Measure("分辨率", "resolution", AggOperatorEnum.SUM.name(), 1));
|
||||||
measures.add(new Measure("评分", "rating", AggOperatorEnum.SUM.name(), 1));
|
measures.add(new Measure("评分", "rating", AggOperatorEnum.SUM.name(), 1));
|
||||||
datasourceReq.setMeasures(measures);
|
modelDetail.setMeasures(measures);
|
||||||
|
|
||||||
datasourceReq.setQueryType("sql_query");
|
modelDetail.setQueryType("sql_query");
|
||||||
datasourceReq.setSqlQuery("SELECT imp_date, song_name, artist_name, country, f_id, g_name, "
|
modelDetail.setSqlQuery("SELECT imp_date, song_name, artist_name, country, f_id, g_name, "
|
||||||
+ " rating, languages, releasedate, resolution FROM song");
|
+ " rating, languages, releasedate, resolution FROM song");
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,30 +5,33 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
|||||||
import com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
|
import com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
|
||||||
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRule;
|
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRule;
|
||||||
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
|
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
|
||||||
|
import com.tencent.supersonic.common.pojo.JoinCondition;
|
||||||
|
import com.tencent.supersonic.common.pojo.ModelRela;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.SensitiveLevelEnum;
|
import com.tencent.supersonic.common.pojo.enums.SensitiveLevelEnum;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
|
||||||
import com.tencent.supersonic.semantic.api.model.enums.DataTypeEnum;
|
import com.tencent.supersonic.semantic.api.model.enums.DataTypeEnum;
|
||||||
import com.tencent.supersonic.semantic.api.model.enums.DimensionTypeEnum;
|
import com.tencent.supersonic.semantic.api.model.enums.DimensionTypeEnum;
|
||||||
import com.tencent.supersonic.semantic.api.model.enums.IdentifyTypeEnum;
|
import com.tencent.supersonic.semantic.api.model.enums.IdentifyTypeEnum;
|
||||||
import com.tencent.supersonic.semantic.api.model.enums.SemanticTypeEnum;
|
import com.tencent.supersonic.semantic.api.model.enums.SemanticTypeEnum;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.DimensionTimeTypeParams;
|
import com.tencent.supersonic.semantic.api.model.pojo.DimensionTimeTypeParams;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Entity;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams;
|
import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams;
|
||||||
|
import com.tencent.supersonic.semantic.api.model.pojo.ModelDetail;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.DatabaseReq;
|
import com.tencent.supersonic.semantic.api.model.request.DatabaseReq;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.DatasourceReq;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.request.DimensionReq;
|
import com.tencent.supersonic.semantic.api.model.request.DimensionReq;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.DomainReq;
|
import com.tencent.supersonic.semantic.api.model.request.DomainReq;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.MetricReq;
|
import com.tencent.supersonic.semantic.api.model.request.MetricReq;
|
||||||
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DatabaseService;
|
import com.tencent.supersonic.semantic.model.domain.DatabaseService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DatasourceService;
|
|
||||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.DomainService;
|
import com.tencent.supersonic.semantic.model.domain.DomainService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
||||||
|
import com.tencent.supersonic.semantic.model.domain.ModelRelaService;
|
||||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -36,6 +39,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -58,7 +62,7 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ModelService modelService;
|
private ModelService modelService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private DatasourceService datasourceService;
|
private ModelRelaService modelRelaService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private DimensionService dimensionService;
|
private DimensionService dimensionService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -75,11 +79,12 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
addDatabase();
|
addDatabase();
|
||||||
addDomain();
|
addDomain();
|
||||||
addModel_1();
|
addModel_1();
|
||||||
addDatasource_1();
|
|
||||||
addDatasource_2();
|
|
||||||
addDatasource_3();
|
|
||||||
addModel_2();
|
addModel_2();
|
||||||
addDatasource_4();
|
addModel_3();
|
||||||
|
addModelRela_1();
|
||||||
|
addModelRela_2();
|
||||||
|
addDomain_2();
|
||||||
|
addModel_4();
|
||||||
updateDimension();
|
updateDimension();
|
||||||
updateMetric();
|
updateMetric();
|
||||||
addAuthGroup_1();
|
addAuthGroup_1();
|
||||||
@@ -106,6 +111,7 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
domainReq.setName("超音数");
|
domainReq.setName("超音数");
|
||||||
domainReq.setBizName("supersonic");
|
domainReq.setBizName("supersonic");
|
||||||
domainReq.setParentId(0L);
|
domainReq.setParentId(0L);
|
||||||
|
domainReq.setStatus(StatusEnum.ONLINE.getCode());
|
||||||
domainReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
domainReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
domainReq.setViewOrgs(Collections.singletonList("admin"));
|
domainReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
domainReq.setAdmins(Collections.singletonList("admin"));
|
domainReq.setAdmins(Collections.singletonList("admin"));
|
||||||
@@ -113,51 +119,49 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
domainService.createDomain(domainReq, user);
|
domainService.createDomain(domainReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModel_1() {
|
public void addModel_1() throws Exception {
|
||||||
ModelReq modelReq = new ModelReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
modelReq.setName("超音数");
|
modelReq.setName("超音数用户部门");
|
||||||
modelReq.setBizName("supersonic");
|
modelReq.setBizName("user_department");
|
||||||
|
modelReq.setDescription("用户部门信息");
|
||||||
|
modelReq.setDatabaseId(1L);
|
||||||
modelReq.setDomainId(1L);
|
modelReq.setDomainId(1L);
|
||||||
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
modelReq.setAdmins(Collections.singletonList("admin"));
|
modelReq.setAdmins(Collections.singletonList("admin"));
|
||||||
modelReq.setAdminOrgs(Collections.emptyList());
|
modelReq.setAdminOrgs(Collections.emptyList());
|
||||||
modelService.createModel(modelReq, user);
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
}
|
|
||||||
|
|
||||||
public void addDatasource_1() throws Exception {
|
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
|
||||||
datasourceReq.setName("用户部门");
|
|
||||||
datasourceReq.setBizName("user_department");
|
|
||||||
datasourceReq.setDescription("用户部门");
|
|
||||||
datasourceReq.setDatabaseId(1L);
|
|
||||||
|
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("用户名", IdentifyTypeEnum.primary.name(), "user_name"));
|
identifiers.add(new Identify("用户", IdentifyTypeEnum.primary.name(), "user_name"));
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
dimensions.add(new Dim("部门", "department",
|
dimensions.add(new Dim("部门", "department",
|
||||||
DimensionTypeEnum.categorical.name(), 1));
|
DimensionTypeEnum.categorical.name(), 1));
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
datasourceReq.setMeasures(Collections.emptyList());
|
modelDetail.setMeasures(Collections.emptyList());
|
||||||
datasourceReq.setQueryType("table_query");
|
modelDetail.setQueryType("table_query");
|
||||||
datasourceReq.setTableQuery("PUBLIC.s2_user_department");
|
modelDetail.setSqlQuery("select user_name,department from PUBLIC.s2_user_department");
|
||||||
datasourceReq.setModelId(1L);
|
modelReq.setModelDetail(modelDetail);
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelReq.setDomainId(1L);
|
||||||
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDatasource_2() throws Exception {
|
public void addModel_2() throws Exception {
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
datasourceReq.setName("PVUV统计");
|
modelReq.setName("超音数PVUV统计");
|
||||||
datasourceReq.setBizName("s2_pv_uv_statis");
|
modelReq.setBizName("s2_pv_uv_statis");
|
||||||
datasourceReq.setDescription("PVUV统计");
|
modelReq.setDescription("超音数PVUV统计");
|
||||||
datasourceReq.setDatabaseId(1L);
|
modelReq.setDatabaseId(1L);
|
||||||
|
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
|
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
|
modelReq.setAdmins(Collections.singletonList("admin"));
|
||||||
|
modelReq.setAdminOrgs(Collections.emptyList());
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("用户名", IdentifyTypeEnum.primary.name(), "user_name"));
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
identifiers.add(new Identify("用户名", IdentifyTypeEnum.primary.name(), "s2_pv_uv_statis_user_name"));
|
||||||
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
||||||
@@ -166,7 +170,7 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
Dim dimension2 = new Dim("", "page", DimensionTypeEnum.categorical.name(), 0);
|
Dim dimension2 = new Dim("", "page", DimensionTypeEnum.categorical.name(), 0);
|
||||||
dimension2.setExpr("page");
|
dimension2.setExpr("page");
|
||||||
dimensions.add(dimension2);
|
dimensions.add(dimension2);
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
List<Measure> measures = new ArrayList<>();
|
List<Measure> measures = new ArrayList<>();
|
||||||
Measure measure1 = new Measure("访问次数", "pv", AggOperatorEnum.SUM.name(), 1);
|
Measure measure1 = new Measure("访问次数", "pv", AggOperatorEnum.SUM.name(), 1);
|
||||||
@@ -175,23 +179,29 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
Measure measure2 = new Measure("访问人数", "uv", AggOperatorEnum.COUNT_DISTINCT.name(), 1);
|
Measure measure2 = new Measure("访问人数", "uv", AggOperatorEnum.COUNT_DISTINCT.name(), 1);
|
||||||
measures.add(measure2);
|
measures.add(measure2);
|
||||||
|
|
||||||
datasourceReq.setMeasures(measures);
|
modelDetail.setMeasures(measures);
|
||||||
datasourceReq.setSqlQuery("SELECT imp_date, user_name, page, 1 as pv, user_name as uv FROM s2_pv_uv_statis");
|
modelDetail.setSqlQuery("SELECT imp_date, user_name as s2_pv_uv_statis_user_name, page, 1 as pv, "
|
||||||
datasourceReq.setQueryType("sql_query");
|
+ "user_name as uv FROM s2_pv_uv_statis");
|
||||||
datasourceReq.setModelId(1L);
|
modelDetail.setQueryType("sql_query");
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelReq.setDomainId(1L);
|
||||||
|
modelReq.setModelDetail(modelDetail);
|
||||||
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDatasource_3() throws Exception {
|
public void addModel_3() throws Exception {
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
datasourceReq.setName("停留时长统计");
|
modelReq.setName("停留时长统计");
|
||||||
datasourceReq.setBizName("s2_stay_time_statis");
|
modelReq.setBizName("s2_stay_time_statis");
|
||||||
datasourceReq.setDescription("停留时长统计");
|
modelReq.setDescription("停留时长统计");
|
||||||
datasourceReq.setDatabaseId(1L);
|
modelReq.setDatabaseId(1L);
|
||||||
|
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
|
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
|
modelReq.setAdmins(Collections.singletonList("admin"));
|
||||||
|
modelReq.setAdminOrgs(Collections.emptyList());
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
identifiers.add(new Identify("用户名", IdentifyTypeEnum.primary.name(), "user_name"));
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
identifiers.add(new Identify("用户名称", IdentifyTypeEnum.primary.name(), "stay_hours_user_name"));
|
||||||
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
||||||
@@ -200,44 +210,75 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
Dim dimension2 = new Dim("页面", "page", DimensionTypeEnum.categorical.name(), 1);
|
Dim dimension2 = new Dim("页面", "page", DimensionTypeEnum.categorical.name(), 1);
|
||||||
dimension2.setExpr("page");
|
dimension2.setExpr("page");
|
||||||
dimensions.add(dimension2);
|
dimensions.add(dimension2);
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
List<Measure> measures = new ArrayList<>();
|
List<Measure> measures = new ArrayList<>();
|
||||||
Measure measure1 = new Measure("停留时长", "stay_hours", AggregateTypeEnum.SUM.name(), 1);
|
Measure measure1 = new Measure("停留时长", "stay_hours", AggregateTypeEnum.SUM.name(), 1);
|
||||||
measures.add(measure1);
|
measures.add(measure1);
|
||||||
|
|
||||||
datasourceReq.setMeasures(measures);
|
modelDetail.setMeasures(measures);
|
||||||
datasourceReq.setTableQuery("PUBLIC.s2_stay_time_statis");
|
modelDetail.setSqlQuery(
|
||||||
datasourceReq.setQueryType("table_query");
|
"select imp_date,user_name as stay_hours_user_name,stay_hours,page from PUBLIC.s2_stay_time_statis");
|
||||||
datasourceReq.setModelId(1L);
|
modelDetail.setQueryType("table_query");
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelReq.setDomainId(1L);
|
||||||
|
modelReq.setModelDetail(modelDetail);
|
||||||
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModel_2() {
|
public void addModelRela_1() {
|
||||||
|
List<JoinCondition> joinConditions = Lists.newArrayList();
|
||||||
|
joinConditions.add(new JoinCondition("user_name", "s2_pv_uv_statis_user_name", FilterOperatorEnum.EQUALS));
|
||||||
|
ModelRela modelRelaReq = new ModelRela();
|
||||||
|
modelRelaReq.setDomainId(1L);
|
||||||
|
modelRelaReq.setFromModelId(1L);
|
||||||
|
modelRelaReq.setToModelId(2L);
|
||||||
|
modelRelaReq.setJoinType("left join");
|
||||||
|
modelRelaReq.setJoinConditions(joinConditions);
|
||||||
|
modelRelaService.save(modelRelaReq, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addModelRela_2() {
|
||||||
|
List<JoinCondition> joinConditions = Lists.newArrayList();
|
||||||
|
joinConditions.add(new JoinCondition("user_name", "stay_hours_user_name", FilterOperatorEnum.EQUALS));
|
||||||
|
ModelRela modelRelaReq = new ModelRela();
|
||||||
|
modelRelaReq.setDomainId(1L);
|
||||||
|
modelRelaReq.setFromModelId(1L);
|
||||||
|
modelRelaReq.setToModelId(3L);
|
||||||
|
modelRelaReq.setJoinType("left join");
|
||||||
|
modelRelaReq.setJoinConditions(joinConditions);
|
||||||
|
modelRelaService.save(modelRelaReq, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDomain_2() {
|
||||||
|
DomainReq domainReq = new DomainReq();
|
||||||
|
domainReq.setName("艺人库");
|
||||||
|
domainReq.setBizName("supersonic");
|
||||||
|
domainReq.setParentId(0L);
|
||||||
|
domainReq.setStatus(StatusEnum.ONLINE.getCode());
|
||||||
|
domainReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
|
domainReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
|
domainReq.setAdmins(Collections.singletonList("admin"));
|
||||||
|
domainReq.setAdminOrgs(Collections.emptyList());
|
||||||
|
domainService.createDomain(domainReq, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addModel_4() throws Exception {
|
||||||
ModelReq modelReq = new ModelReq();
|
ModelReq modelReq = new ModelReq();
|
||||||
modelReq.setName("艺人库");
|
modelReq.setName("艺人库");
|
||||||
modelReq.setBizName("singer");
|
modelReq.setBizName("singer");
|
||||||
modelReq.setDomainId(1L);
|
modelReq.setDescription("艺人库");
|
||||||
|
modelReq.setDatabaseId(1L);
|
||||||
|
modelReq.setDomainId(2L);
|
||||||
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
modelReq.setViewers(Arrays.asList("admin", "tom", "jack"));
|
||||||
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
modelReq.setViewOrgs(Collections.singletonList("admin"));
|
||||||
modelReq.setAdmins(Collections.singletonList("admin"));
|
modelReq.setAdmins(Collections.singletonList("admin"));
|
||||||
modelReq.setAdminOrgs(Collections.emptyList());
|
modelReq.setAdminOrgs(Collections.emptyList());
|
||||||
modelReq.setEntity(new Entity(7L, Arrays.asList("歌手", "艺人")));
|
ModelDetail modelDetail = new ModelDetail();
|
||||||
modelService.createModel(modelReq, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDatasource_4() throws Exception {
|
|
||||||
DatasourceReq datasourceReq = new DatasourceReq();
|
|
||||||
datasourceReq.setName("艺人库");
|
|
||||||
datasourceReq.setBizName("singer");
|
|
||||||
datasourceReq.setDescription("艺人库");
|
|
||||||
datasourceReq.setDatabaseId(1L);
|
|
||||||
|
|
||||||
List<Identify> identifiers = new ArrayList<>();
|
List<Identify> identifiers = new ArrayList<>();
|
||||||
Identify identify = new Identify("歌手名", IdentifyTypeEnum.primary.name(), "singer_name");
|
Identify identify = new Identify("歌手名", IdentifyTypeEnum.primary.name(), "singer_name");
|
||||||
identify.setEntityNames(Lists.newArrayList("歌手", "艺人"));
|
identify.setEntityNames(Lists.newArrayList("歌手", "艺人"));
|
||||||
identifiers.add(identify);
|
identifiers.add(identify);
|
||||||
datasourceReq.setIdentifiers(identifiers);
|
modelDetail.setIdentifiers(identifiers);
|
||||||
|
|
||||||
List<Dim> dimensions = new ArrayList<>();
|
List<Dim> dimensions = new ArrayList<>();
|
||||||
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
Dim dimension1 = new Dim("", "imp_date", DimensionTypeEnum.time.name(), 0);
|
||||||
@@ -249,26 +290,26 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
DimensionTypeEnum.categorical.name(), 1));
|
DimensionTypeEnum.categorical.name(), 1));
|
||||||
dimensions.add(new Dim("风格", "genre",
|
dimensions.add(new Dim("风格", "genre",
|
||||||
DimensionTypeEnum.categorical.name(), 1, 1));
|
DimensionTypeEnum.categorical.name(), 1, 1));
|
||||||
datasourceReq.setDimensions(dimensions);
|
modelDetail.setDimensions(dimensions);
|
||||||
|
|
||||||
Measure measure1 = new Measure("播放量", "js_play_cnt", "sum", 1);
|
Measure measure1 = new Measure("播放量", "js_play_cnt", "sum", 1);
|
||||||
Measure measure2 = new Measure("下载量", "down_cnt", "sum", 1);
|
Measure measure2 = new Measure("下载量", "down_cnt", "sum", 1);
|
||||||
Measure measure3 = new Measure("收藏量", "favor_cnt", "sum", 1);
|
Measure measure3 = new Measure("收藏量", "favor_cnt", "sum", 1);
|
||||||
datasourceReq.setMeasures(Lists.newArrayList(measure1, measure2, measure3));
|
modelDetail.setMeasures(Lists.newArrayList(measure1, measure2, measure3));
|
||||||
datasourceReq.setQueryType("table_query");
|
modelDetail.setQueryType("table_query");
|
||||||
datasourceReq.setTableQuery("PUBLIC.singer");
|
modelDetail.setTableQuery("PUBLIC.singer");
|
||||||
datasourceReq.setModelId(2L);
|
modelReq.setModelDetail(modelDetail);
|
||||||
datasourceService.createDatasource(datasourceReq, user);
|
modelService.createModel(modelReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDimension() throws Exception {
|
public void updateDimension() throws Exception {
|
||||||
DimensionReq dimensionReq = new DimensionReq();
|
DimensionReq dimensionReq = new DimensionReq();
|
||||||
dimensionReq.setModelId(1L);
|
dimensionReq.setModelId(1L);
|
||||||
dimensionReq.setType(DimensionTypeEnum.categorical.name());
|
dimensionReq.setType(DimensionTypeEnum.categorical.name());
|
||||||
dimensionReq.setId(3L);
|
dimensionReq.setId(4L);
|
||||||
dimensionReq.setName("页面");
|
dimensionReq.setName("页面");
|
||||||
dimensionReq.setBizName("page");
|
dimensionReq.setBizName("page");
|
||||||
dimensionReq.setDatasourceId(3L);
|
dimensionReq.setModelId(3L);
|
||||||
dimensionReq.setAlias("page");
|
dimensionReq.setAlias("page");
|
||||||
dimensionReq.setSemanticType(SemanticTypeEnum.CATEGORY.name());
|
dimensionReq.setSemanticType(SemanticTypeEnum.CATEGORY.name());
|
||||||
dimensionReq.setSensitiveLevel(2);
|
dimensionReq.setSensitiveLevel(2);
|
||||||
@@ -302,7 +343,7 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
|
|
||||||
public void addAuthGroup_1() {
|
public void addAuthGroup_1() {
|
||||||
AuthGroup authGroupReq = new AuthGroup();
|
AuthGroup authGroupReq = new AuthGroup();
|
||||||
authGroupReq.setModelId(1L);
|
authGroupReq.setModelId(3L);
|
||||||
authGroupReq.setName("admin-permission");
|
authGroupReq.setName("admin-permission");
|
||||||
|
|
||||||
List<AuthRule> authRules = new ArrayList<>();
|
List<AuthRule> authRules = new ArrayList<>();
|
||||||
@@ -319,7 +360,7 @@ public class LoadModelDataDemo implements CommandLineRunner {
|
|||||||
|
|
||||||
public void addAuthGroup_2() {
|
public void addAuthGroup_2() {
|
||||||
AuthGroup authGroupReq = new AuthGroup();
|
AuthGroup authGroupReq = new AuthGroup();
|
||||||
authGroupReq.setModelId(1L);
|
authGroupReq.setModelId(3L);
|
||||||
authGroupReq.setName("tom_sales_permission");
|
authGroupReq.setName("tom_sales_permission");
|
||||||
|
|
||||||
List<AuthRule> authRules = new ArrayList<>();
|
List<AuthRule> authRules = new ArrayList<>();
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ com.tencent.supersonic.chat.api.component.SchemaMapper=\
|
|||||||
com.tencent.supersonic.chat.mapper.HanlpDictMapper, \
|
com.tencent.supersonic.chat.mapper.HanlpDictMapper, \
|
||||||
com.tencent.supersonic.chat.mapper.FuzzyNameMapper, \
|
com.tencent.supersonic.chat.mapper.FuzzyNameMapper, \
|
||||||
com.tencent.supersonic.chat.mapper.QueryFilterMapper, \
|
com.tencent.supersonic.chat.mapper.QueryFilterMapper, \
|
||||||
com.tencent.supersonic.chat.mapper.EntityMapper
|
com.tencent.supersonic.chat.mapper.EntityMapper, \
|
||||||
|
com.tencent.supersonic.chat.mapper.ModelClusterMapper
|
||||||
|
|
||||||
com.tencent.supersonic.chat.api.component.SemanticParser=\
|
com.tencent.supersonic.chat.api.component.SemanticParser=\
|
||||||
com.tencent.supersonic.chat.parser.rule.RuleBasedParser, \
|
com.tencent.supersonic.chat.parser.rule.RuleBasedParser, \
|
||||||
@@ -17,7 +18,8 @@ com.tencent.supersonic.chat.api.component.SemanticCorrector=\
|
|||||||
com.tencent.supersonic.chat.corrector.SelectCorrector, \
|
com.tencent.supersonic.chat.corrector.SelectCorrector, \
|
||||||
com.tencent.supersonic.chat.corrector.WhereCorrector, \
|
com.tencent.supersonic.chat.corrector.WhereCorrector, \
|
||||||
com.tencent.supersonic.chat.corrector.GroupByCorrector, \
|
com.tencent.supersonic.chat.corrector.GroupByCorrector, \
|
||||||
com.tencent.supersonic.chat.corrector.HavingCorrector
|
com.tencent.supersonic.chat.corrector.HavingCorrector, \
|
||||||
|
com.tencent.supersonic.chat.corrector.FromCorrector
|
||||||
|
|
||||||
com.tencent.supersonic.chat.llm.LLMInterpreter=\
|
com.tencent.supersonic.chat.llm.LLMInterpreter=\
|
||||||
com.tencent.supersonic.chat.llm.HttpLLMInterpreter
|
com.tencent.supersonic.chat.llm.HttpLLMInterpreter
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ dean _1_2 36
|
|||||||
john _1_2 50
|
john _1_2 50
|
||||||
jack _1_2 38
|
jack _1_2 38
|
||||||
admin _1_2 70
|
admin _1_2 70
|
||||||
周杰伦 _2_7 100
|
周杰伦 _4_9 100
|
||||||
陈奕迅 _2_7 100
|
陈奕迅 _4_9 100
|
||||||
林俊杰 _2_7 100
|
林俊杰 _4_9 100
|
||||||
张碧晨 _2_7 100
|
张碧晨 _4_9 100
|
||||||
程响 _2_7 100
|
程响 _4_9 100
|
||||||
Taylor#Swift _2_7 100
|
Taylor#Swift _4_9 100
|
||||||
内地 _2_4 100
|
内地 _4_6 100
|
||||||
欧美 _2_4 100
|
欧美 _4_6 100
|
||||||
港台 _2_4 100
|
港台 _4_6 100
|
||||||
流行 _2_6 100
|
流行 _4_8 100
|
||||||
国风 _2_6 100
|
国风 _4_8 100
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
p1 _1_3 52
|
p1 _3_4 52
|
||||||
p2 _1_3 47
|
p2 _3_4 47
|
||||||
p3 _1_3 31
|
p3 _3_4 31
|
||||||
p4 _1_3 36
|
p4 _3_4 36
|
||||||
p5 _1_3 50
|
p5 _3_4 50
|
||||||
p6 _1_3 38
|
p6 _3_4 38
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
周杰伦 _2_7 9000
|
|
||||||
周深 _2_7 8000
|
|
||||||
周传雄 _2_7 7000
|
|
||||||
周华建 _2_7 6000
|
|
||||||
陈奕迅 _2_7 8000
|
|
||||||
林俊杰 _2_7 7000
|
|
||||||
张碧晨 _2_7 7000
|
|
||||||
程响 _2_7 7000
|
|
||||||
Taylor#Swift _2_7 7000
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
周杰伦 _4_9 9000
|
||||||
|
周深 _4_9 8000
|
||||||
|
周传雄 _4_9 7000
|
||||||
|
周华建 _4_9 6000
|
||||||
|
陈奕迅 _4_9 8000
|
||||||
|
林俊杰 _4_9 7000
|
||||||
|
张碧晨 _4_9 7000
|
||||||
|
程响 _4_9 7000
|
||||||
|
Taylor#Swift _4_9 7000
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
tagore _3_8 9000
|
|
||||||
nazrul _3_8 9000
|
|
||||||
民间 _3_8 9000
|
|
||||||
现代 _3_8 9000
|
|
||||||
蓝调 _3_8 9000
|
|
||||||
流行 _3_8 9000
|
|
||||||
孟加拉国 _3_10 9000
|
|
||||||
锡尔赫特、吉大港、库斯蒂亚 _3_10 9000
|
|
||||||
加拿大 _3_10 9000
|
|
||||||
美国 _3_10 9000
|
|
||||||
Shrikanta _3_11 9000
|
|
||||||
Prity _3_11 9000
|
|
||||||
Farida _3_11 9000
|
|
||||||
Topu _3_11 9000
|
|
||||||
Enrique _3_11 9000
|
|
||||||
Michel _3_11 9000
|
|
||||||
孟加拉国 _3_12 9000
|
|
||||||
印度 _3_12 9000
|
|
||||||
美国 _3_12 9000
|
|
||||||
英国 _3_12 9000
|
|
||||||
男性 _3_13 9000
|
|
||||||
女性 _3_13 9000
|
|
||||||
mp4 _3_19 9000
|
|
||||||
mp3 _3_19 9000
|
|
||||||
Tumi#长袍#尼罗布 _3_20 9000
|
|
||||||
舒克诺#帕塔尔#努普尔#帕埃 _3_20 9000
|
|
||||||
阿米·奥帕尔·霍伊 _3_20 9000
|
|
||||||
我的爱 _3_20 9000
|
|
||||||
打败它 _3_20 9000
|
|
||||||
阿杰伊阿卡什 _3_20 9000
|
|
||||||
孟加拉国 _3_22 9000
|
|
||||||
印度 _3_22 9000
|
|
||||||
美国 _3_22 9000
|
|
||||||
英国 _3_22 9000
|
|
||||||
孟加拉语 _3_26 9000
|
|
||||||
英文 _3_26 9000
|
|
||||||
=======
|
|
||||||
孟加拉国 _3_8 9000
|
|
||||||
锡尔赫特、吉大港、库斯蒂亚 _3_8 9000
|
|
||||||
加拿大 _3_8 9000
|
|
||||||
美国 _3_8 9000
|
|
||||||
tagore _3_9 9000
|
|
||||||
nazrul _3_9 9000
|
|
||||||
民间 _3_9 9000
|
|
||||||
现代 _3_9 9000
|
|
||||||
蓝调 _3_9 9000
|
|
||||||
流行 _3_9 9000
|
|
||||||
孟加拉国 _3_10 9000
|
|
||||||
印度 _3_10 9000
|
|
||||||
美国 _3_10 9000
|
|
||||||
英国 _3_10 9000
|
|
||||||
男性 _3_11 9000
|
|
||||||
女性 _3_11 9000
|
|
||||||
Shrikanta _3_12 9000
|
|
||||||
Prity _3_12 9000
|
|
||||||
Farida _3_12 9000
|
|
||||||
Topu _3_12 9000
|
|
||||||
Enrique _3_12 9000
|
|
||||||
Michel _3_12 9000
|
|
||||||
mp4 _3_14 9000
|
|
||||||
mp3 _3_14 9000
|
|
||||||
孟加拉语 _3_16 9000
|
|
||||||
英文 _3_16 9000
|
|
||||||
Tumi#长袍#尼罗布 _3_18 9000
|
|
||||||
舒克诺#帕塔尔#努普尔#帕埃 _3_18 9000
|
|
||||||
阿米·奥帕尔·霍伊 _3_18 9000
|
|
||||||
我的爱 _3_18 9000
|
|
||||||
打败它 _3_18 9000
|
|
||||||
|
|||||||
@@ -133,6 +133,10 @@ CREATE TABLE IF NOT EXISTS `s2_model` (
|
|||||||
`view_org` varchar(3000) DEFAULT NULL , -- domain available organization
|
`view_org` varchar(3000) DEFAULT NULL , -- domain available organization
|
||||||
`entity` varchar(500) DEFAULT NULL , -- domain entity info
|
`entity` varchar(500) DEFAULT NULL , -- domain entity info
|
||||||
`drill_down_dimensions` varchar(500) DEFAULT NULL , -- drill down dimensions info
|
`drill_down_dimensions` varchar(500) DEFAULT NULL , -- drill down dimensions info
|
||||||
|
`database_id` INT NOT NULL ,
|
||||||
|
`model_detail` LONGVARCHAR NOT NULL ,
|
||||||
|
`depends` varchar(500) DEFAULT NULL ,
|
||||||
|
`filter_sql` varchar(1000) DEFAULT NULL ,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_model IS 'model information';
|
COMMENT ON TABLE s2_model IS 'model information';
|
||||||
@@ -156,16 +160,12 @@ CREATE TABLE `s2_database` (
|
|||||||
COMMENT ON TABLE s2_database IS 'database instance table';
|
COMMENT ON TABLE s2_database IS 'database instance table';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `s2_datasource` (
|
CREATE TABLE IF NOT EXISTS `s2_datasource` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
`id` INT NOT NULL AUTO_INCREMENT,
|
||||||
`model_id` INT NOT NULL ,
|
`model_id` INT NOT NULL ,
|
||||||
`name` varchar(255) NOT NULL ,
|
`name` varchar(255) NOT NULL ,
|
||||||
`biz_name` varchar(255) NOT NULL ,
|
`biz_name` varchar(255) NOT NULL ,
|
||||||
`description` varchar(500) DEFAULT NULL ,
|
`description` varchar(500) DEFAULT NULL ,
|
||||||
`database_id` INT NOT NULL ,
|
|
||||||
`datasource_detail` LONGVARCHAR NOT NULL ,
|
|
||||||
`status` int(11) DEFAULT NULL ,
|
|
||||||
`depends` varchar(500) DEFAULT NULL ,
|
|
||||||
`filter_sql` varchar(1000) DEFAULT NULL ,
|
|
||||||
`created_at` TIMESTAMP NOT NULL ,
|
`created_at` TIMESTAMP NOT NULL ,
|
||||||
`created_by` varchar(100) NOT NULL ,
|
`created_by` varchar(100) NOT NULL ,
|
||||||
`updated_at` TIMESTAMP NOT NULL ,
|
`updated_at` TIMESTAMP NOT NULL ,
|
||||||
@@ -208,7 +208,6 @@ COMMENT ON TABLE s2_metric IS 'metric information table';
|
|||||||
CREATE TABLE IF NOT EXISTS `s2_dimension` (
|
CREATE TABLE IF NOT EXISTS `s2_dimension` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT ,
|
`id` INT NOT NULL AUTO_INCREMENT ,
|
||||||
`model_id` INT NOT NULL ,
|
`model_id` INT NOT NULL ,
|
||||||
`datasource_id` INT NOT NULL ,
|
|
||||||
`name` varchar(255) NOT NULL ,
|
`name` varchar(255) NOT NULL ,
|
||||||
`biz_name` varchar(255) NOT NULL ,
|
`biz_name` varchar(255) NOT NULL ,
|
||||||
`description` varchar(500) NOT NULL ,
|
`description` varchar(500) NOT NULL ,
|
||||||
@@ -231,20 +230,16 @@ CREATE TABLE IF NOT EXISTS `s2_dimension` (
|
|||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_dimension IS 'dimension information table';
|
COMMENT ON TABLE s2_dimension IS 'dimension information table';
|
||||||
|
|
||||||
create table s2_datasource_rela
|
CREATE TABLE s2_model_rela
|
||||||
(
|
(
|
||||||
id INT AUTO_INCREMENT,
|
id BIGINT AUTO_INCREMENT,
|
||||||
model_id INT null,
|
domain_id BIGINT,
|
||||||
datasource_from INT null,
|
from_model_id BIGINT,
|
||||||
datasource_to INT null,
|
to_model_id BIGINT,
|
||||||
join_key varchar(100) null,
|
join_type VARCHAR(255),
|
||||||
created_at TIMESTAMP null,
|
join_condition VARCHAR(255),
|
||||||
created_by varchar(100) null,
|
|
||||||
updated_at TIMESTAMP null,
|
|
||||||
updated_by varchar(100) null,
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_datasource_rela IS 'data source association table';
|
|
||||||
|
|
||||||
create table s2_view_info
|
create table s2_view_info
|
||||||
(
|
(
|
||||||
@@ -536,3 +531,4 @@ CREATE TABLE s2_sys_parameter
|
|||||||
admin varchar(500),
|
admin varchar(500),
|
||||||
parameters text null
|
parameters text null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -454,3 +454,13 @@ CREATE TABLE s2_sys_parameter
|
|||||||
admin varchar(500) COMMENT '系统管理员',
|
admin varchar(500) COMMENT '系统管理员',
|
||||||
parameters text null COMMENT '配置项'
|
parameters text null COMMENT '配置项'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE s2_model_rela
|
||||||
|
(
|
||||||
|
id bigint primary key AUTO_INCREMENT,
|
||||||
|
domain_id bigint,
|
||||||
|
from_model_id bigint,
|
||||||
|
to_model_id bigint,
|
||||||
|
join_type VARCHAR(255),
|
||||||
|
join_condition VARCHAR(255)
|
||||||
|
);
|
||||||
@@ -97,3 +97,20 @@ alter table s2_datasource add column `filter_sql` varchar(1000) COMMENT 'filter_
|
|||||||
|
|
||||||
--20231120
|
--20231120
|
||||||
alter table s2_dimension add column `is_tag` int(10) DEFAULT NULL;
|
alter table s2_dimension add column `is_tag` int(10) DEFAULT NULL;
|
||||||
|
|
||||||
|
--20231125
|
||||||
|
alter table s2_model add column `database_id` INT NOT NULL;
|
||||||
|
alter table s2_model add column `model_detail` text NOT NULL;
|
||||||
|
alter table s2_model add column `depends` varchar(500) DEFAULT NULL;
|
||||||
|
alter table s2_model add column `filter_sql` varchar(1000) DEFAULT NULL;
|
||||||
|
|
||||||
|
CREATE TABLE s2_model_rela
|
||||||
|
(
|
||||||
|
id BIGINT AUTO_INCREMENT,
|
||||||
|
domain_id BIGINT,
|
||||||
|
from_model_id BIGINT,
|
||||||
|
to_model_id BIGINT,
|
||||||
|
join_type VARCHAR(255),
|
||||||
|
join_condition VARCHAR(255),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
package com.tencent.supersonic.integration;
|
package com.tencent.supersonic.integration;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum.NONE;
|
|
||||||
import static com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum.SUM;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatConfigEditReqReq;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ItemVisibility;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ChatConfigResp;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||||
import com.tencent.supersonic.chat.query.rule.metric.MetricFilterQuery;
|
import com.tencent.supersonic.chat.query.rule.metric.MetricFilterQuery;
|
||||||
@@ -19,15 +12,17 @@ import com.tencent.supersonic.common.pojo.DateConf;
|
|||||||
import com.tencent.supersonic.common.pojo.QueryType;
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.util.DataUtils;
|
import com.tencent.supersonic.util.DataUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import static com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum.NONE;
|
||||||
import org.springframework.beans.BeanUtils;
|
import static com.tencent.supersonic.common.pojo.enums.AggregateTypeEnum.SUM;
|
||||||
|
|
||||||
|
|
||||||
public class MetricQueryTest extends BaseQueryTest {
|
public class MetricQueryTest extends BaseQueryTest {
|
||||||
@@ -46,7 +41,7 @@ public class MetricQueryTest extends BaseQueryTest {
|
|||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
||||||
|
|
||||||
expectedParseInfo.getDimensionFilters().add(DataUtils.getFilter("user_name",
|
expectedParseInfo.getDimensionFilters().add(DataUtils.getFilter("user_name",
|
||||||
FilterOperatorEnum.EQUALS, "alice", "用户名", 2L));
|
FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
@@ -129,7 +124,7 @@ public class MetricQueryTest extends BaseQueryTest {
|
|||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
list.add("alice");
|
list.add("alice");
|
||||||
list.add("lucy");
|
list.add("lucy");
|
||||||
QueryFilter dimensionFilter = DataUtils.getFilter("user_name", FilterOperatorEnum.IN, list, "用户名", 2L);
|
QueryFilter dimensionFilter = DataUtils.getFilter("user_name", FilterOperatorEnum.IN, list, "用户", 2L);
|
||||||
expectedParseInfo.getDimensionFilters().add(dimensionFilter);
|
expectedParseInfo.getDimensionFilters().add(dimensionFilter);
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
||||||
@@ -150,7 +145,9 @@ public class MetricQueryTest extends BaseQueryTest {
|
|||||||
expectedParseInfo.setAggType(SUM);
|
expectedParseInfo.setAggType(SUM);
|
||||||
|
|
||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
||||||
|
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("用户"));
|
||||||
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("用户名"));
|
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("用户名"));
|
||||||
|
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("用户名称"));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(DataUtils.getDateConf(3, DateConf.DateMode.RECENT, "DAY"));
|
expectedParseInfo.setDateInfo(DataUtils.getDateConf(3, DateConf.DateMode.RECENT, "DAY"));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
@@ -195,7 +192,7 @@ public class MetricQueryTest extends BaseQueryTest {
|
|||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
||||||
|
|
||||||
expectedParseInfo.getDimensionFilters().add(DataUtils.getFilter("user_name",
|
expectedParseInfo.getDimensionFilters().add(DataUtils.getFilter("user_name",
|
||||||
FilterOperatorEnum.EQUALS, "alice", "用户名", 2L));
|
FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.BETWEEN, 1, period, startDay, startDay));
|
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.BETWEEN, 1, period, startDay, startDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
@@ -203,44 +200,4 @@ public class MetricQueryTest extends BaseQueryTest {
|
|||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void queryTest_config_visibility() throws Exception {
|
|
||||||
// 1. round_1 use blacklist
|
|
||||||
ChatConfigResp chatConfig = configService.fetchConfigByModelId(1L);
|
|
||||||
ChatConfigEditReqReq extendEditCmd = new ChatConfigEditReqReq();
|
|
||||||
BeanUtils.copyProperties(chatConfig, extendEditCmd);
|
|
||||||
// add blacklist
|
|
||||||
List<Long> blackMetrics = Arrays.asList(2L);
|
|
||||||
extendEditCmd.getChatAggConfig().getVisibility().setBlackMetricIdList(blackMetrics);
|
|
||||||
configService.editConfig(extendEditCmd, User.getFakeUser());
|
|
||||||
|
|
||||||
QueryResult actualResult = submitNewChat("超音数访问人数、访问次数");
|
|
||||||
QueryResult expectedResult = new QueryResult();
|
|
||||||
SemanticParseInfo expectedParseInfo = new SemanticParseInfo();
|
|
||||||
expectedResult.setChatContext(expectedParseInfo);
|
|
||||||
|
|
||||||
expectedResult.setQueryMode(MetricModelQuery.QUERY_MODE);
|
|
||||||
expectedParseInfo.setAggType(NONE);
|
|
||||||
|
|
||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
|
||||||
|
|
||||||
// 2. round_2 no blacklist
|
|
||||||
// remove blacklist
|
|
||||||
extendEditCmd.getChatAggConfig().setVisibility(new ItemVisibility());
|
|
||||||
configService.editConfig(extendEditCmd, User.getFakeUser());
|
|
||||||
|
|
||||||
actualResult = submitNewChat("超音数访问人数、访问次数");
|
|
||||||
expectedParseInfo.getMetrics().clear();
|
|
||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
|
||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问人数"));
|
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ com.tencent.supersonic.chat.api.component.SchemaMapper=\
|
|||||||
com.tencent.supersonic.chat.mapper.HanlpDictMapper, \
|
com.tencent.supersonic.chat.mapper.HanlpDictMapper, \
|
||||||
com.tencent.supersonic.chat.mapper.FuzzyNameMapper, \
|
com.tencent.supersonic.chat.mapper.FuzzyNameMapper, \
|
||||||
com.tencent.supersonic.chat.mapper.QueryFilterMapper, \
|
com.tencent.supersonic.chat.mapper.QueryFilterMapper, \
|
||||||
com.tencent.supersonic.chat.mapper.EntityMapper
|
com.tencent.supersonic.chat.mapper.EntityMapper, \
|
||||||
|
com.tencent.supersonic.chat.mapper.ModelClusterMapper
|
||||||
|
|
||||||
com.tencent.supersonic.chat.api.component.SemanticParser=\
|
com.tencent.supersonic.chat.api.component.SemanticParser=\
|
||||||
com.tencent.supersonic.chat.parser.rule.RuleBasedParser, \
|
com.tencent.supersonic.chat.parser.rule.RuleBasedParser, \
|
||||||
|
|||||||
@@ -80,21 +80,6 @@ CREATE TABLE IF NOT EXISTS `s2_chat_config` (
|
|||||||
) ;
|
) ;
|
||||||
COMMENT ON TABLE s2_chat_config IS 'chat config information table ';
|
COMMENT ON TABLE s2_chat_config IS 'chat config information table ';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS s2_agent
|
|
||||||
(
|
|
||||||
id int AUTO_INCREMENT,
|
|
||||||
name varchar(100) null,
|
|
||||||
description varchar(500) null,
|
|
||||||
status int null,
|
|
||||||
examples varchar(500) null,
|
|
||||||
config varchar(2000) null,
|
|
||||||
created_by varchar(100) null,
|
|
||||||
created_at TIMESTAMP null,
|
|
||||||
updated_by varchar(100) null,
|
|
||||||
updated_at TIMESTAMP null,
|
|
||||||
enable_search int null,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
); COMMENT ON TABLE s2_agent IS 'agent information table';
|
|
||||||
|
|
||||||
create table s2_user
|
create table s2_user
|
||||||
(
|
(
|
||||||
@@ -134,8 +119,8 @@ CREATE TABLE IF NOT EXISTS `s2_model` (
|
|||||||
`name` varchar(255) DEFAULT NULL , -- domain name
|
`name` varchar(255) DEFAULT NULL , -- domain name
|
||||||
`biz_name` varchar(255) DEFAULT NULL , -- internal name
|
`biz_name` varchar(255) DEFAULT NULL , -- internal name
|
||||||
`domain_id` INT DEFAULT '0' , -- parent domain ID
|
`domain_id` INT DEFAULT '0' , -- parent domain ID
|
||||||
`alias` varchar(255) DEFAULT NULL , -- alias name
|
`alias` varchar(255) DEFAULT NULL , -- internal name
|
||||||
`status` INT DEFAULT NULL ,
|
`status` INT DEFAULT NULL,
|
||||||
`description` varchar(500) DEFAULT NULL ,
|
`description` varchar(500) DEFAULT NULL ,
|
||||||
`created_at` TIMESTAMP DEFAULT NULL ,
|
`created_at` TIMESTAMP DEFAULT NULL ,
|
||||||
`created_by` varchar(100) DEFAULT NULL ,
|
`created_by` varchar(100) DEFAULT NULL ,
|
||||||
@@ -148,6 +133,10 @@ CREATE TABLE IF NOT EXISTS `s2_model` (
|
|||||||
`view_org` varchar(3000) DEFAULT NULL , -- domain available organization
|
`view_org` varchar(3000) DEFAULT NULL , -- domain available organization
|
||||||
`entity` varchar(500) DEFAULT NULL , -- domain entity info
|
`entity` varchar(500) DEFAULT NULL , -- domain entity info
|
||||||
`drill_down_dimensions` varchar(500) DEFAULT NULL , -- drill down dimensions info
|
`drill_down_dimensions` varchar(500) DEFAULT NULL , -- drill down dimensions info
|
||||||
|
`database_id` INT NOT NULL ,
|
||||||
|
`model_detail` LONGVARCHAR NOT NULL ,
|
||||||
|
`depends` varchar(500) DEFAULT NULL ,
|
||||||
|
`filter_sql` varchar(1000) DEFAULT NULL ,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_model IS 'model information';
|
COMMENT ON TABLE s2_model IS 'model information';
|
||||||
@@ -171,16 +160,12 @@ CREATE TABLE `s2_database` (
|
|||||||
COMMENT ON TABLE s2_database IS 'database instance table';
|
COMMENT ON TABLE s2_database IS 'database instance table';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `s2_datasource` (
|
CREATE TABLE IF NOT EXISTS `s2_datasource` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
`id` INT NOT NULL AUTO_INCREMENT,
|
||||||
`model_id` INT NOT NULL ,
|
`model_id` INT NOT NULL ,
|
||||||
`name` varchar(255) NOT NULL ,
|
`name` varchar(255) NOT NULL ,
|
||||||
`biz_name` varchar(255) NOT NULL ,
|
`biz_name` varchar(255) NOT NULL ,
|
||||||
`description` varchar(500) DEFAULT NULL ,
|
`description` varchar(500) DEFAULT NULL ,
|
||||||
`database_id` INT NOT NULL ,
|
|
||||||
`depends` varchar(500) DEFAULT NULL ,
|
|
||||||
`datasource_detail` LONGVARCHAR NOT NULL ,
|
|
||||||
`status` int(11) DEFAULT NULL ,
|
|
||||||
`filter_sql` varchar(1000) DEFAULT NULL ,
|
|
||||||
`created_at` TIMESTAMP NOT NULL ,
|
`created_at` TIMESTAMP NOT NULL ,
|
||||||
`created_by` varchar(100) NOT NULL ,
|
`created_by` varchar(100) NOT NULL ,
|
||||||
`updated_at` TIMESTAMP NOT NULL ,
|
`updated_at` TIMESTAMP NOT NULL ,
|
||||||
@@ -202,7 +187,7 @@ CREATE TABLE IF NOT EXISTS `s2_metric` (
|
|||||||
`name` varchar(255) NOT NULL ,
|
`name` varchar(255) NOT NULL ,
|
||||||
`biz_name` varchar(255) NOT NULL ,
|
`biz_name` varchar(255) NOT NULL ,
|
||||||
`description` varchar(500) DEFAULT NULL ,
|
`description` varchar(500) DEFAULT NULL ,
|
||||||
`status` INT NOT NULL , -- status, 0 is normal, 1 is off the shelf, 2 is deleted
|
`status` INT NOT NULL , -- status, 0 is off the shelf, 1 is normal
|
||||||
`sensitive_level` INT NOT NULL ,
|
`sensitive_level` INT NOT NULL ,
|
||||||
`type` varchar(50) NOT NULL , -- type proxy,expr
|
`type` varchar(50) NOT NULL , -- type proxy,expr
|
||||||
`type_params` LONGVARCHAR DEFAULT NULL ,
|
`type_params` LONGVARCHAR DEFAULT NULL ,
|
||||||
@@ -223,11 +208,10 @@ COMMENT ON TABLE s2_metric IS 'metric information table';
|
|||||||
CREATE TABLE IF NOT EXISTS `s2_dimension` (
|
CREATE TABLE IF NOT EXISTS `s2_dimension` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT ,
|
`id` INT NOT NULL AUTO_INCREMENT ,
|
||||||
`model_id` INT NOT NULL ,
|
`model_id` INT NOT NULL ,
|
||||||
`datasource_id` INT NOT NULL ,
|
|
||||||
`name` varchar(255) NOT NULL ,
|
`name` varchar(255) NOT NULL ,
|
||||||
`biz_name` varchar(255) NOT NULL ,
|
`biz_name` varchar(255) NOT NULL ,
|
||||||
`description` varchar(500) NOT NULL ,
|
`description` varchar(500) NOT NULL ,
|
||||||
`status` INT NOT NULL , -- status, 0 is normal, 1 is off the shelf, 2 is deleted
|
`status` INT NOT NULL , -- status, 0 is off the shelf, 1 is normal
|
||||||
`sensitive_level` INT DEFAULT NULL ,
|
`sensitive_level` INT DEFAULT NULL ,
|
||||||
`data_type` varchar(50) DEFAULT NULL , -- type date,array,varchar
|
`data_type` varchar(50) DEFAULT NULL , -- type date,array,varchar
|
||||||
`type` varchar(50) NOT NULL , -- type categorical,time
|
`type` varchar(50) NOT NULL , -- type categorical,time
|
||||||
@@ -246,20 +230,16 @@ CREATE TABLE IF NOT EXISTS `s2_dimension` (
|
|||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_dimension IS 'dimension information table';
|
COMMENT ON TABLE s2_dimension IS 'dimension information table';
|
||||||
|
|
||||||
create table s2_datasource_rela
|
CREATE TABLE s2_model_rela
|
||||||
(
|
(
|
||||||
id INT AUTO_INCREMENT,
|
id BIGINT AUTO_INCREMENT,
|
||||||
model_id INT null,
|
domain_id BIGINT,
|
||||||
datasource_from INT null,
|
from_model_id BIGINT,
|
||||||
datasource_to INT null,
|
to_model_id BIGINT,
|
||||||
join_key varchar(100) null,
|
join_type VARCHAR(255),
|
||||||
created_at TIMESTAMP null,
|
join_condition VARCHAR(255),
|
||||||
created_by varchar(100) null,
|
|
||||||
updated_at TIMESTAMP null,
|
|
||||||
updated_by varchar(100) null,
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
COMMENT ON TABLE s2_datasource_rela IS 'data source association table';
|
|
||||||
|
|
||||||
create table s2_view_info
|
create table s2_view_info
|
||||||
(
|
(
|
||||||
@@ -295,7 +275,6 @@ CREATE TABLE `s2_query_stat_info` (
|
|||||||
`native_query` INT DEFAULT NULL, -- 1-detail query, 0-aggregation query
|
`native_query` INT DEFAULT NULL, -- 1-detail query, 0-aggregation query
|
||||||
`start_date` varchar(50) DEFAULT NULL,
|
`start_date` varchar(50) DEFAULT NULL,
|
||||||
`end_date` varchar(50) DEFAULT NULL,
|
`end_date` varchar(50) DEFAULT NULL,
|
||||||
`query_opt_mode` varchar(50) DEFAULT NULL,
|
|
||||||
`dimensions`LONGVARCHAR , -- dimensions involved in sql
|
`dimensions`LONGVARCHAR , -- dimensions involved in sql
|
||||||
`metrics`LONGVARCHAR , -- metric involved in sql
|
`metrics`LONGVARCHAR , -- metric involved in sql
|
||||||
`select_cols`LONGVARCHAR ,
|
`select_cols`LONGVARCHAR ,
|
||||||
@@ -307,6 +286,7 @@ CREATE TABLE `s2_query_stat_info` (
|
|||||||
`use_sql_cache` TINYINT DEFAULT '-1' , -- whether to hit the sql cache
|
`use_sql_cache` TINYINT DEFAULT '-1' , -- whether to hit the sql cache
|
||||||
`sql_cache_key`LONGVARCHAR , -- sql cache key
|
`sql_cache_key`LONGVARCHAR , -- sql cache key
|
||||||
`result_cache_key`LONGVARCHAR , -- result cache key
|
`result_cache_key`LONGVARCHAR , -- result cache key
|
||||||
|
`query_opt_mode` varchar(50) DEFAULT NULL ,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ;
|
) ;
|
||||||
COMMENT ON TABLE s2_query_stat_info IS 'query statistics table';
|
COMMENT ON TABLE s2_query_stat_info IS 'query statistics table';
|
||||||
@@ -370,6 +350,22 @@ CREATE TABLE IF NOT EXISTS `s2_plugin`
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
); COMMENT ON TABLE s2_plugin IS 'plugin information table';
|
); COMMENT ON TABLE s2_plugin IS 'plugin information table';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS s2_agent
|
||||||
|
(
|
||||||
|
id int AUTO_INCREMENT,
|
||||||
|
name varchar(100) null,
|
||||||
|
description varchar(500) null,
|
||||||
|
status int null,
|
||||||
|
examples varchar(500) null,
|
||||||
|
config varchar(2000) null,
|
||||||
|
created_by varchar(100) null,
|
||||||
|
created_at TIMESTAMP null,
|
||||||
|
updated_by varchar(100) null,
|
||||||
|
updated_at TIMESTAMP null,
|
||||||
|
enable_search int null,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
); COMMENT ON TABLE s2_agent IS 'agent information table';
|
||||||
|
|
||||||
|
|
||||||
-------demo for semantic and chat
|
-------demo for semantic and chat
|
||||||
CREATE TABLE IF NOT EXISTS `s2_user_department` (
|
CREATE TABLE IF NOT EXISTS `s2_user_department` (
|
||||||
@@ -405,8 +401,68 @@ CREATE TABLE IF NOT EXISTS `singer` (
|
|||||||
);
|
);
|
||||||
COMMENT ON TABLE singer IS 'singer_info';
|
COMMENT ON TABLE singer IS 'singer_info';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `s2_dictionary_task` (
|
||||||
|
`id` INT NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` varchar(255) NOT NULL , -- task name
|
||||||
|
`description` varchar(255) ,
|
||||||
|
`command`LONGVARCHAR NOT NULL , -- task Request Parameters
|
||||||
|
`command_md5` varchar(255) NOT NULL , -- task Request Parameters md5
|
||||||
|
`status` INT NOT NULL , -- the final status of the task
|
||||||
|
`dimension_ids` varchar(500) NULL ,
|
||||||
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
|
||||||
|
`created_by` varchar(100) NOT NULL ,
|
||||||
|
`progress` DOUBLE default 0.00 , -- task real-time progress
|
||||||
|
`elapsed_ms` bigINT DEFAULT NULL , -- the task takes time in milliseconds
|
||||||
|
`message` LONGVARCHAR , -- remark related information
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);
|
||||||
|
COMMENT ON TABLE s2_dictionary_task IS 'dictionary task information table';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- benchmark
|
||||||
|
CREATE TABLE IF NOT EXISTS `genre` (
|
||||||
|
`g_name` varchar(20) NOT NULL , -- genre name
|
||||||
|
`rating` INT ,
|
||||||
|
`most_popular_in` varchar(50) ,
|
||||||
|
PRIMARY KEY (`g_name`)
|
||||||
|
);
|
||||||
|
COMMENT ON TABLE genre IS 'genre';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `artist` (
|
||||||
|
`artist_name` varchar(50) NOT NULL , -- genre name
|
||||||
|
`country` varchar(20) ,
|
||||||
|
`gender` varchar(20) ,
|
||||||
|
`g_name` varchar(50)
|
||||||
|
);
|
||||||
|
COMMENT ON TABLE artist IS 'artist';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `files` (
|
||||||
|
`f_id` bigINT NOT NULL,
|
||||||
|
`artist_name` varchar(50) ,
|
||||||
|
`file_size` varchar(20) ,
|
||||||
|
`duration` varchar(20) ,
|
||||||
|
`formats` varchar(20) ,
|
||||||
|
PRIMARY KEY (`f_id`)
|
||||||
|
);
|
||||||
|
COMMENT ON TABLE files IS 'files';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `song` (
|
||||||
|
`imp_date` varchar(50) ,
|
||||||
|
`song_name` varchar(50) ,
|
||||||
|
`artist_name` varchar(50) ,
|
||||||
|
`country` varchar(20) ,
|
||||||
|
`f_id` bigINT ,
|
||||||
|
`g_name` varchar(20) ,
|
||||||
|
`rating` INT ,
|
||||||
|
`languages` varchar(20) ,
|
||||||
|
`releasedate` varchar(50) ,
|
||||||
|
`resolution` bigINT NOT NULL
|
||||||
|
);
|
||||||
|
COMMENT ON TABLE song IS 'song';
|
||||||
|
|
||||||
|
-- benchmark
|
||||||
|
|
||||||
create table s2_materialization
|
create table s2_materialization
|
||||||
(
|
(
|
||||||
id int AUTO_INCREMENT ,
|
id int AUTO_INCREMENT ,
|
||||||
@@ -469,13 +525,9 @@ CREATE TABLE s2_materialization_record
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE s2_sys_parameter
|
CREATE TABLE s2_sys_parameter
|
||||||
(
|
(
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
admin varchar(500),
|
admin varchar(500),
|
||||||
parameters text null
|
parameters text null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.pojo;
|
package com.tencent.supersonic.semantic.api.model.pojo;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class DatasourceDetail {
|
public class ModelDetail {
|
||||||
|
|
||||||
private String queryType;
|
private String queryType;
|
||||||
|
|
||||||
@@ -19,5 +21,11 @@ public class DatasourceDetail {
|
|||||||
|
|
||||||
private List<Measure> measures;
|
private List<Measure> measures;
|
||||||
|
|
||||||
|
public String getSqlQuery() {
|
||||||
|
if (StringUtils.isNotBlank(sqlQuery) && sqlQuery.endsWith(";")) {
|
||||||
|
sqlQuery = sqlQuery.substring(0, sqlQuery.length() - 1);
|
||||||
|
}
|
||||||
|
return sqlQuery;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.request;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class DatasourceRelaReq {
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotNull(message = "model id cat not be null")
|
|
||||||
private Long modelId;
|
|
||||||
|
|
||||||
@NotNull(message = "datasource id cat not be null")
|
|
||||||
private Long datasourceFrom;
|
|
||||||
|
|
||||||
@NotNull(message = "datasource id cat not be null")
|
|
||||||
private Long datasourceTo;
|
|
||||||
|
|
||||||
@NotNull(message = "join key cat not be null")
|
|
||||||
private String joinKey;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.request;
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.enums.DimensionTypeEnum;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class DatasourceReq extends SchemaItem {
|
|
||||||
|
|
||||||
private Long databaseId;
|
|
||||||
|
|
||||||
private String queryType;
|
|
||||||
|
|
||||||
private String sqlQuery;
|
|
||||||
|
|
||||||
private String tableQuery;
|
|
||||||
|
|
||||||
private Long modelId;
|
|
||||||
|
|
||||||
private List<Identify> identifiers;
|
|
||||||
|
|
||||||
private List<Dim> dimensions;
|
|
||||||
|
|
||||||
private List<Measure> measures;
|
|
||||||
|
|
||||||
private String filterSql;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<Dim> getTimeDimension() {
|
|
||||||
if (CollectionUtils.isEmpty(dimensions)) {
|
|
||||||
return Lists.newArrayList();
|
|
||||||
}
|
|
||||||
return dimensions.stream()
|
|
||||||
.filter(dim -> DimensionTypeEnum.time.name().equalsIgnoreCase(dim.getType()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSqlQuery() {
|
|
||||||
if (StringUtils.isNotBlank(sqlQuery) && sqlQuery.endsWith(";")) {
|
|
||||||
sqlQuery = sqlQuery.substring(0, sqlQuery.length() - 1);
|
|
||||||
}
|
|
||||||
return sqlQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -18,9 +18,6 @@ public class DimensionReq extends SchemaItem {
|
|||||||
@NotNull(message = "expr can not be null")
|
@NotNull(message = "expr can not be null")
|
||||||
private String expr;
|
private String expr;
|
||||||
|
|
||||||
|
|
||||||
private Long datasourceId;
|
|
||||||
|
|
||||||
//DATE ID CATEGORY
|
//DATE ID CATEGORY
|
||||||
private String semanticType = "CATEGORY";
|
private String semanticType = "CATEGORY";
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.request;
|
package com.tencent.supersonic.semantic.api.model.request;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class DomainReq extends SchemaItem {
|
public class DomainReq extends SchemaItem {
|
||||||
@@ -24,4 +22,22 @@ public class DomainReq extends SchemaItem {
|
|||||||
private List<String> admins = new ArrayList<>();
|
private List<String> admins = new ArrayList<>();
|
||||||
|
|
||||||
private List<String> adminOrgs = new ArrayList<>();
|
private List<String> adminOrgs = new ArrayList<>();
|
||||||
|
|
||||||
|
public String getViewer() {
|
||||||
|
return String.join(",", viewers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getViewOrg() {
|
||||||
|
return String.join(",", viewOrgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getAdmin() {
|
||||||
|
return String.join(",", admins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdminOrg() {
|
||||||
|
return String.join(",", adminOrgs);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,37 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.request;
|
package com.tencent.supersonic.semantic.api.model.request;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.tencent.supersonic.semantic.api.model.enums.DimensionTypeEnum;
|
||||||
|
import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.DrillDownDimension;
|
import com.tencent.supersonic.semantic.api.model.pojo.DrillDownDimension;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.Entity;
|
import com.tencent.supersonic.semantic.api.model.pojo.ModelDetail;
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ModelReq extends SchemaItem {
|
public class ModelReq extends SchemaItem {
|
||||||
|
|
||||||
private Long domainId = 0L;
|
private Long databaseId;
|
||||||
|
|
||||||
private Integer isOpen = 0;
|
private Long domainId;
|
||||||
|
|
||||||
|
private String filterSql;
|
||||||
|
|
||||||
|
private Integer isOpen;
|
||||||
|
|
||||||
|
private List<DrillDownDimension> drillDownDimensions;
|
||||||
|
|
||||||
private String alias;
|
private String alias;
|
||||||
|
|
||||||
|
private ModelDetail modelDetail;
|
||||||
|
|
||||||
private List<String> viewers = new ArrayList<>();
|
private List<String> viewers = new ArrayList<>();
|
||||||
|
|
||||||
private List<String> viewOrgs = new ArrayList<>();
|
private List<String> viewOrgs = new ArrayList<>();
|
||||||
@@ -27,9 +40,16 @@ public class ModelReq extends SchemaItem {
|
|||||||
|
|
||||||
private List<String> adminOrgs = new ArrayList<>();
|
private List<String> adminOrgs = new ArrayList<>();
|
||||||
|
|
||||||
private Entity entity;
|
|
||||||
|
|
||||||
private List<DrillDownDimension> drillDownDimensions;
|
public List<Dim> getTimeDimension() {
|
||||||
|
if (CollectionUtils.isEmpty(modelDetail.getDimensions())) {
|
||||||
|
return Lists.newArrayList();
|
||||||
|
}
|
||||||
|
return modelDetail.getDimensions().stream()
|
||||||
|
.filter(dim -> DimensionTypeEnum.time.name().equalsIgnoreCase(dim.getType()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getViewer() {
|
public String getViewer() {
|
||||||
return String.join(",", viewers);
|
return String.join(",", viewers);
|
||||||
@@ -48,4 +68,5 @@ public class ModelReq extends SchemaItem {
|
|||||||
return String.join(",", adminOrgs);
|
return String.join(",", adminOrgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.response;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class DatasourceRelaResp {
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private Long domainId;
|
|
||||||
|
|
||||||
private Long datasourceFrom;
|
|
||||||
|
|
||||||
private Long datasourceTo;
|
|
||||||
|
|
||||||
private String joinKey;
|
|
||||||
|
|
||||||
private Date createdAt;
|
|
||||||
|
|
||||||
private String createdBy;
|
|
||||||
|
|
||||||
private Date updatedAt;
|
|
||||||
|
|
||||||
private String updatedBy;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.tencent.supersonic.semantic.api.model.response;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.DatasourceDetail;
|
|
||||||
import com.tencent.supersonic.semantic.api.model.pojo.SchemaItem;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class DatasourceResp extends SchemaItem {
|
|
||||||
|
|
||||||
private Long modelId;
|
|
||||||
|
|
||||||
private Long databaseId;
|
|
||||||
|
|
||||||
private DatasourceDetail datasourceDetail;
|
|
||||||
|
|
||||||
private String depends;
|
|
||||||
|
|
||||||
private String filterSql;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,14 @@ package com.tencent.supersonic.semantic.api.model.response;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class DimSchemaResp extends DimensionResp {
|
public class DimSchemaResp extends DimensionResp {
|
||||||
|
|
||||||
private Long useCnt = 0L;
|
private Long useCnt = 0L;
|
||||||
|
|
||||||
|
private List<String> entityAlias;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,13 +22,11 @@ public class DimensionResp extends SchemaItem {
|
|||||||
|
|
||||||
private String fullPath;
|
private String fullPath;
|
||||||
|
|
||||||
private Long datasourceId;
|
private String modelName;
|
||||||
|
|
||||||
private String datasourceName;
|
private String modelBizName;
|
||||||
|
|
||||||
private String datasourceBizName;
|
private String modelFilterSql;
|
||||||
|
|
||||||
private String datasourceFilterSql;
|
|
||||||
//DATE ID CATEGORY
|
//DATE ID CATEGORY
|
||||||
private String semanticType;
|
private String semanticType;
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ public class MetricResp extends SchemaItem {
|
|||||||
|
|
||||||
private boolean hasAdminRes = false;
|
private boolean hasAdminRes = false;
|
||||||
|
|
||||||
private String defaultAgg;
|
|
||||||
|
|
||||||
public void setTag(String tag) {
|
public void setTag(String tag) {
|
||||||
if (StringUtils.isBlank(tag)) {
|
if (StringUtils.isBlank(tag)) {
|
||||||
tags = Lists.newArrayList();
|
tags = Lists.newArrayList();
|
||||||
@@ -80,4 +78,8 @@ public class MetricResp extends SchemaItem {
|
|||||||
}
|
}
|
||||||
return typeParams.getMeasures();
|
return typeParams.getMeasures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDefaultAgg() {
|
||||||
|
return typeParams.getMeasures().get(0).getAgg();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user