mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
Support limit (#1688)
This commit is contained in:
@@ -66,4 +66,7 @@ public class Constants {
|
||||
public static final Long DEFAULT_FREQUENCY = 100000L;
|
||||
|
||||
public static final String TABLE_PREFIX = "t_";
|
||||
|
||||
public static final Long DEFAULT_DETAIL_LIMIT = 500L;
|
||||
public static final Long DEFAULT_METRIC_LIMIT = 200L;
|
||||
}
|
||||
|
||||
@@ -9,4 +9,6 @@ public class MetricTypeDefaultConfig {
|
||||
|
||||
private TimeDefaultConfig timeDefaultConfig =
|
||||
new TimeDefaultConfig(7, Constants.DAY, TimeMode.RECENT);
|
||||
|
||||
private Long limit;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,19 @@ import lombok.Data;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DEFAULT_DETAIL_LIMIT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DEFAULT_METRIC_LIMIT;
|
||||
|
||||
@Data
|
||||
public class SemanticParseInfo {
|
||||
|
||||
private Integer id;
|
||||
private String queryMode = "PLAIN_TEXT";
|
||||
private SchemaElement dataSet;
|
||||
private QueryConfig queryConfig;
|
||||
private Set<SchemaElement> metrics = Sets.newTreeSet(new SchemaNameLengthComparator());
|
||||
private Set<SchemaElement> dimensions = Sets.newTreeSet(new SchemaNameLengthComparator());
|
||||
private SchemaElement entity;
|
||||
@@ -68,4 +73,24 @@ public class SemanticParseInfo {
|
||||
}
|
||||
return dataSet.getDataSetId();
|
||||
}
|
||||
|
||||
public Long getDetailLimit() {
|
||||
Long limit = DEFAULT_DETAIL_LIMIT;
|
||||
if (Objects.nonNull(queryConfig)
|
||||
&& Objects.nonNull(queryConfig.getTagTypeDefaultConfig())
|
||||
&& Objects.nonNull(queryConfig.getTagTypeDefaultConfig().getLimit())) {
|
||||
limit = queryConfig.getTagTypeDefaultConfig().getLimit();
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
|
||||
public Long getMetricLimit() {
|
||||
Long limit = DEFAULT_METRIC_LIMIT;
|
||||
if (Objects.nonNull(queryConfig)
|
||||
&& Objects.nonNull(queryConfig.getMetricTypeDefaultConfig())
|
||||
&& Objects.nonNull(queryConfig.getMetricTypeDefaultConfig().getLimit())) {
|
||||
limit = queryConfig.getMetricTypeDefaultConfig().getLimit();
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -151,6 +152,20 @@ public class SemanticSchema implements Serializable {
|
||||
return getElementsById(dataSetId, dataSets).orElse(null);
|
||||
}
|
||||
|
||||
public QueryConfig getQueryConfig(Long dataSetId) {
|
||||
DataSetSchema first =
|
||||
dataSetSchemaList.stream()
|
||||
.filter(
|
||||
dataSetSchema ->
|
||||
dataSetId.equals(dataSetSchema.getDataSet().getDataSetId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (Objects.nonNull(first)) {
|
||||
return first.getQueryConfig();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SchemaElement> getDataSets() {
|
||||
List<SchemaElement> dataSets = new ArrayList<>();
|
||||
dataSetSchemaList.stream().forEach(d -> dataSets.add(d.getDataSet()));
|
||||
|
||||
@@ -9,4 +9,6 @@ public class TagTypeDefaultConfig {
|
||||
|
||||
// default time to filter tag selection results
|
||||
private TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
||||
|
||||
private Long limit;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public class LLMResponseService {
|
||||
LLMSemanticQuery semanticQuery = QueryManager.createLLMQuery(LLMSqlQuery.QUERY_MODE);
|
||||
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
||||
parseInfo.setDataSet(queryCtx.getSemanticSchema().getDataSet(parseResult.getDataSetId()));
|
||||
parseInfo.setQueryConfig(
|
||||
queryCtx.getSemanticSchema().getQueryConfig(parseResult.getDataSetId()));
|
||||
parseInfo
|
||||
.getElementMatches()
|
||||
.addAll(queryCtx.getMapInfo().getMatchedElements(parseInfo.getDataSetId()));
|
||||
|
||||
@@ -113,6 +113,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
||||
.collect(Collectors.toSet());
|
||||
Long dataSetId = dataSetIds.iterator().next();
|
||||
parseInfo.setDataSet(semanticSchema.getDataSet(dataSetId));
|
||||
parseInfo.setQueryConfig(semanticSchema.getQueryConfig(dataSetId));
|
||||
Map<Long, List<SchemaElementMatch>> dim2Values = new HashMap<>();
|
||||
Map<Long, List<SchemaElementMatch>> id2Values = new HashMap<>();
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
public abstract class DetailSemanticQuery extends RuleSemanticQuery {
|
||||
|
||||
private static final Long DETAIL_MAX_RESULTS = 500L;
|
||||
|
||||
public DetailSemanticQuery() {
|
||||
super();
|
||||
}
|
||||
@@ -35,7 +33,9 @@ public abstract class DetailSemanticQuery extends RuleSemanticQuery {
|
||||
super.fillParseInfo(chatQueryContext);
|
||||
|
||||
parseInfo.setQueryType(QueryType.DETAIL);
|
||||
parseInfo.setLimit(DETAIL_MAX_RESULTS);
|
||||
if (Objects.isNull(parseInfo.getLimit())) {
|
||||
parseInfo.setLimit(parseInfo.getDetailLimit());
|
||||
}
|
||||
if (!needFillDateConf(chatQueryContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import static com.tencent.supersonic.headless.chat.query.rule.QueryMatchOption.R
|
||||
@Slf4j
|
||||
public abstract class MetricSemanticQuery extends RuleSemanticQuery {
|
||||
|
||||
private static final Long METRIC_MAX_RESULTS = 365L;
|
||||
|
||||
public MetricSemanticQuery() {
|
||||
super();
|
||||
queryMatcher.addOption(METRIC, REQUIRED, AT_LEAST, 1);
|
||||
@@ -36,7 +34,9 @@ public abstract class MetricSemanticQuery extends RuleSemanticQuery {
|
||||
@Override
|
||||
public void fillParseInfo(ChatQueryContext chatQueryContext) {
|
||||
super.fillParseInfo(chatQueryContext);
|
||||
parseInfo.setLimit(METRIC_MAX_RESULTS);
|
||||
if (Objects.isNull(parseInfo.getLimit())) {
|
||||
parseInfo.setLimit(parseInfo.getMetricLimit());
|
||||
}
|
||||
fillDateInfo(chatQueryContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import static com.tencent.supersonic.headless.chat.query.rule.QueryMatchOption.R
|
||||
public class MetricTopNQuery extends MetricSemanticQuery {
|
||||
|
||||
public static final String QUERY_MODE = "METRIC_ORDERBY";
|
||||
private static final Long ORDERBY_MAX_RESULTS = 3L;
|
||||
private static final Pattern INTENT_PATTERN = Pattern.compile("(.*)(最大|最高|最多)(.*)");
|
||||
|
||||
public MetricTopNQuery() {
|
||||
@@ -52,7 +51,6 @@ public class MetricTopNQuery extends MetricSemanticQuery {
|
||||
public void fillParseInfo(ChatQueryContext chatQueryContext) {
|
||||
super.fillParseInfo(chatQueryContext);
|
||||
|
||||
parseInfo.setLimit(ORDERBY_MAX_RESULTS);
|
||||
parseInfo.setScore(parseInfo.getScore() + 2.0);
|
||||
parseInfo.setAggType(AggregateTypeEnum.SUM);
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ public class S2ChatLayerService implements ChatLayerService {
|
||||
}
|
||||
SchemaElement dataSet = semanticSchema.getDataSet(dataSetId);
|
||||
semanticParseInfo.setDataSet(dataSet);
|
||||
|
||||
semanticParseInfo.setQueryConfig(semanticSchema.getQueryConfig(dataSetId));
|
||||
ComponentFactory.getSemanticCorrectors()
|
||||
.forEach(
|
||||
corrector -> {
|
||||
|
||||
Reference in New Issue
Block a user