mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
[improvement][project]Use DatePeriodEnum to replace DAY/MONTH/YEAR period constants.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.chat.api.pojo.response;
|
package com.tencent.supersonic.chat.api.pojo.response;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -17,7 +17,7 @@ public class ChatDefaultRichConfigResp {
|
|||||||
private Integer unit = 1;
|
private Integer unit = 1;
|
||||||
|
|
||||||
/** default time type: DAY, WEEK, MONTH, YEAR */
|
/** default time type: DAY, WEEK, MONTH, YEAR */
|
||||||
private String period = Constants.DAY;
|
private DatePeriodEnum period = DatePeriodEnum.DAY;
|
||||||
|
|
||||||
private TimeMode timeMode;
|
private TimeMode timeMode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.RatioOverType;
|
import com.tencent.supersonic.common.pojo.enums.RatioOverType;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
@@ -43,15 +44,12 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
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.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;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT_INT;
|
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.TIMES_FORMAT;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
import static com.tencent.supersonic.common.pojo.Constants.TIME_FORMAT;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
|
||||||
|
|
||||||
/** Add ratio queries for metric queries. */
|
/** Add ratio queries for metric queries. */
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -193,11 +191,11 @@ public class MetricRatioProcessor implements ExecuteResultProcessor {
|
|||||||
}
|
}
|
||||||
String statisticsRollName = RatioOverType.DAY_ON_DAY.getShowName();
|
String statisticsRollName = RatioOverType.DAY_ON_DAY.getShowName();
|
||||||
String statisticsOverName = RatioOverType.WEEK_ON_DAY.getShowName();
|
String statisticsOverName = RatioOverType.WEEK_ON_DAY.getShowName();
|
||||||
if (MONTH.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
||||||
statisticsRollName = RatioOverType.MONTH_ON_MONTH.getShowName();
|
statisticsRollName = RatioOverType.MONTH_ON_MONTH.getShowName();
|
||||||
statisticsOverName = RatioOverType.YEAR_ON_MONTH.getShowName();
|
statisticsOverName = RatioOverType.YEAR_ON_MONTH.getShowName();
|
||||||
}
|
}
|
||||||
if (WEEK.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
||||||
statisticsRollName = RatioOverType.WEEK_ON_WEEK.getShowName();
|
statisticsRollName = RatioOverType.WEEK_ON_WEEK.getShowName();
|
||||||
statisticsOverName = RatioOverType.MONTH_ON_WEEK.getShowName();
|
statisticsOverName = RatioOverType.MONTH_ON_WEEK.getShowName();
|
||||||
}
|
}
|
||||||
@@ -234,7 +232,7 @@ public class MetricRatioProcessor implements ExecuteResultProcessor {
|
|||||||
List<String> dayList = new ArrayList<>();
|
List<String> dayList = new ArrayList<>();
|
||||||
dayList.add(lastDay);
|
dayList.add(lastDay);
|
||||||
String start = "";
|
String start = "";
|
||||||
if (DAY.equalsIgnoreCase(semanticParseInfo.getDateInfo().getPeriod())) {
|
if (DatePeriodEnum.DAY.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
||||||
DateTimeFormatter formatter =
|
DateTimeFormatter formatter =
|
||||||
DateUtils.getDateFormatter(lastDay, new String[] {DAY_FORMAT, DAY_FORMAT_INT});
|
DateUtils.getDateFormatter(lastDay, new String[] {DAY_FORMAT, DAY_FORMAT_INT});
|
||||||
LocalDate end = LocalDate.parse(lastDay, formatter);
|
LocalDate end = LocalDate.parse(lastDay, formatter);
|
||||||
@@ -243,7 +241,7 @@ public class MetricRatioProcessor implements ExecuteResultProcessor {
|
|||||||
? end.minusDays(1).format(formatter)
|
? end.minusDays(1).format(formatter)
|
||||||
: end.minusWeeks(1).format(formatter);
|
: end.minusWeeks(1).format(formatter);
|
||||||
}
|
}
|
||||||
if (WEEK.equalsIgnoreCase(semanticParseInfo.getDateInfo().getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
||||||
DateTimeFormatter formatter =
|
DateTimeFormatter formatter =
|
||||||
DateUtils.getTimeFormatter(
|
DateUtils.getTimeFormatter(
|
||||||
lastDay,
|
lastDay,
|
||||||
@@ -254,7 +252,7 @@ public class MetricRatioProcessor implements ExecuteResultProcessor {
|
|||||||
? end.minusWeeks(1).format(formatter)
|
? end.minusWeeks(1).format(formatter)
|
||||||
: end.minusMonths(1).with(DayOfWeek.MONDAY).format(formatter);
|
: end.minusMonths(1).with(DayOfWeek.MONDAY).format(formatter);
|
||||||
}
|
}
|
||||||
if (MONTH.equalsIgnoreCase(semanticParseInfo.getDateInfo().getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(semanticParseInfo.getDateInfo().getPeriod())) {
|
||||||
DateTimeFormatter formatter =
|
DateTimeFormatter formatter =
|
||||||
DateUtils.getDateFormatter(
|
DateUtils.getDateFormatter(
|
||||||
lastDay, new String[] {MONTH_FORMAT, MONTH_FORMAT_INT});
|
lastDay, new String[] {MONTH_FORMAT, MONTH_FORMAT_INT});
|
||||||
|
|||||||
@@ -48,15 +48,6 @@ import com.tencent.supersonic.headless.chat.query.SemanticQuery;
|
|||||||
import com.tencent.supersonic.headless.chat.query.llm.s2sql.LLMSqlQuery;
|
import com.tencent.supersonic.headless.chat.query.llm.s2sql.LLMSqlQuery;
|
||||||
import com.tencent.supersonic.headless.server.facade.service.ChatLayerService;
|
import com.tencent.supersonic.headless.server.facade.service.ChatLayerService;
|
||||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
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 lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
import net.sf.jsqlparser.expression.LongValue;
|
import net.sf.jsqlparser.expression.LongValue;
|
||||||
@@ -73,6 +64,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
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.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class ChatQueryServiceImpl implements ChatQueryService {
|
public class ChatQueryServiceImpl implements ChatQueryService {
|
||||||
@@ -222,7 +223,10 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleLLMQueryMode(
|
private void handleLLMQueryMode(
|
||||||
ChatQueryDataReq chatQueryDataReq, SemanticQuery semanticQuery, DataSetSchema dataSetSchema, User user)
|
ChatQueryDataReq chatQueryDataReq,
|
||||||
|
SemanticQuery semanticQuery,
|
||||||
|
DataSetSchema dataSetSchema,
|
||||||
|
User user)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
||||||
List<String> fields = getFieldsFromSql(parseInfo);
|
List<String> fields = getFieldsFromSql(parseInfo);
|
||||||
@@ -271,7 +275,8 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
return !oriFields.containsAll(metricNames);
|
return !oriFields.containsAll(metricNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String reviseCorrectS2SQL(ChatQueryDataReq queryData, SemanticParseInfo parseInfo, DataSetSchema dataSetSchema) {
|
private String reviseCorrectS2SQL(
|
||||||
|
ChatQueryDataReq queryData, SemanticParseInfo parseInfo, DataSetSchema dataSetSchema) {
|
||||||
String correctorSql = parseInfo.getSqlInfo().getCorrectedS2SQL();
|
String correctorSql = parseInfo.getSqlInfo().getCorrectedS2SQL();
|
||||||
log.info("correctorSql before replacing:{}", correctorSql);
|
log.info("correctorSql before replacing:{}", correctorSql);
|
||||||
// get where filter and having filter
|
// get where filter and having filter
|
||||||
@@ -372,7 +377,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
queryData
|
queryData
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.setStartDate(DateUtils.getBeforeDate(queryData.getDateInfo().getUnit() + 1));
|
.setStartDate(DateUtils.getBeforeDate(queryData.getDateInfo().getUnit() + 1));
|
||||||
queryData.getDateInfo().setEndDate(DateUtils.getBeforeDate(1));
|
queryData.getDateInfo().setEndDate(DateUtils.getBeforeDate(0));
|
||||||
}
|
}
|
||||||
SchemaElement partitionDimension = dataSetSchema.getPartitionDimension();
|
SchemaElement partitionDimension = dataSetSchema.getPartitionDimension();
|
||||||
// startDate equals to endDate
|
// startDate equals to endDate
|
||||||
@@ -382,10 +387,16 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
removeFieldNames.add(partitionDimension.getName());
|
removeFieldNames.add(partitionDimension.getName());
|
||||||
GreaterThanEquals greaterThanEquals = new GreaterThanEquals();
|
GreaterThanEquals greaterThanEquals = new GreaterThanEquals();
|
||||||
addTimeFilters(
|
addTimeFilters(
|
||||||
queryData.getDateInfo().getStartDate(), greaterThanEquals, addConditions, partitionDimension);
|
queryData.getDateInfo().getStartDate(),
|
||||||
|
greaterThanEquals,
|
||||||
|
addConditions,
|
||||||
|
partitionDimension);
|
||||||
MinorThanEquals minorThanEquals = new MinorThanEquals();
|
MinorThanEquals minorThanEquals = new MinorThanEquals();
|
||||||
addTimeFilters(
|
addTimeFilters(
|
||||||
queryData.getDateInfo().getEndDate(), minorThanEquals, addConditions, partitionDimension);
|
queryData.getDateInfo().getEndDate(),
|
||||||
|
minorThanEquals,
|
||||||
|
addConditions,
|
||||||
|
partitionDimension);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,7 +426,10 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private <T extends ComparisonOperator> void addTimeFilters(
|
private <T extends ComparisonOperator> void addTimeFilters(
|
||||||
String date, T comparisonExpression, List<Expression> addConditions, SchemaElement partitionDimension) {
|
String date,
|
||||||
|
T comparisonExpression,
|
||||||
|
List<Expression> addConditions,
|
||||||
|
SchemaElement partitionDimension) {
|
||||||
Column column = new Column(partitionDimension.getName());
|
Column column = new Column(partitionDimension.getName());
|
||||||
StringValue stringValue = new StringValue(date);
|
StringValue stringValue = new StringValue(date);
|
||||||
comparisonExpression.setLeftExpression(column);
|
comparisonExpression.setLeftExpression(column);
|
||||||
|
|||||||
@@ -3,70 +3,40 @@ package com.tencent.supersonic.common.pojo;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final String COMMA = ",";
|
public static final String COMMA = ",";
|
||||||
public static final String DOUBLE_SLASH = "//";
|
public static final String DOUBLE_SLASH = "//";
|
||||||
public static final String EMPTY = "";
|
public static final String EMPTY = "";
|
||||||
public static final String AT_SYMBOL = "@";
|
public static final String AT_SYMBOL = "@";
|
||||||
public static final String DOT = ".";
|
public static final String DOT = ".";
|
||||||
public static String SPACE = " ";
|
public static final String SPACE = " ";
|
||||||
public static String POUND = "#";
|
public static final String POUND = "#";
|
||||||
public static final String COLON = ":";
|
public static final String COLON = ":";
|
||||||
public static final String MINUS = "-";
|
public static final String MINUS = "-";
|
||||||
public static final String UNDERLINE = "_";
|
public static final String UNDERLINE = "_";
|
||||||
public static final String DICT_VALUE = "v";
|
|
||||||
public static final String UNDERLINE_DOUBLE = "__";
|
|
||||||
public static final String PARENTHESES_START = "(";
|
public static final String PARENTHESES_START = "(";
|
||||||
public static final String PARENTHESES_END = ")";
|
public static final String PARENTHESES_END = ")";
|
||||||
public static final String APOSTROPHE = "'";
|
public static final String APOSTROPHE = "'";
|
||||||
public static final String PERCENT_SIGN = "%";
|
public static final String PERCENT_SIGN = "%";
|
||||||
public static String LIMIT_UPPER = "LIMIT";
|
public static final String DESC_UPPER = "DESC";
|
||||||
public static String ORDER_UPPER = "ORDER";
|
public static final String ASC_UPPER = "ASC";
|
||||||
public static String DESC_UPPER = "DESC";
|
public static final String AND_UPPER = "AND";
|
||||||
public static String ASC_UPPER = "ASC";
|
public static final String SYS_VAR = "sys_var";
|
||||||
public static String GROUP_UPPER = "GROUP";
|
|
||||||
public static String NULL_UPPER = "NULL";
|
|
||||||
public static String AND_UPPER = "AND";
|
|
||||||
public static String END_SUBQUERY = ") subq_";
|
|
||||||
public static String SYS_VAR = "sys_var";
|
|
||||||
public static final String NEW_LINE_CHAR = "\n";
|
public static final String NEW_LINE_CHAR = "\n";
|
||||||
public static final String UNIONALL = " union all ";
|
public static final String UNIONALL = " union all ";
|
||||||
public static final String YAML_FILES_SUFFIX = ".yaml";
|
|
||||||
public static final String JDBC_PREFIX_FORMATTER = "jdbc:%s:";
|
public static final String JDBC_PREFIX_FORMATTER = "jdbc:%s:";
|
||||||
public static final Pattern PATTERN_JDBC_TYPE = Pattern.compile("jdbc:\\w+");
|
public static final Pattern PATTERN_JDBC_TYPE = Pattern.compile("jdbc:\\w+");
|
||||||
public static final String STATISTIC = "statistic";
|
|
||||||
public static final String DORIS_LOWER = "doris";
|
|
||||||
public static final String MYSQL_LOWER = "mysql";
|
|
||||||
public static final String ADMIN_LOWER = "admin";
|
public static final String ADMIN_LOWER = "admin";
|
||||||
|
|
||||||
public static final String DAY = "DAY";
|
|
||||||
public static final String DAY_FORMAT = "yyyy-MM-dd";
|
public static final String DAY_FORMAT = "yyyy-MM-dd";
|
||||||
public static final String MONTH_FORMAT = "yyyy-MM";
|
public static final String MONTH_FORMAT = "yyyy-MM";
|
||||||
public static final String TIMES_FORMAT = "yyyy-MM-dd HH:mm:ss.S";
|
public static final String TIMES_FORMAT = "yyyy-MM-dd HH:mm:ss.S";
|
||||||
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||||
public static final String DAY_FORMAT_INT = "YYYYMMDD";
|
public static final String DAY_FORMAT_INT = "YYYYMMDD";
|
||||||
public static final String MONTH_FORMAT_INT = "YYYYMM";
|
public static final String MONTH_FORMAT_INT = "YYYYMM";
|
||||||
public static final String MONTH = "MONTH";
|
|
||||||
public static final String WEEK = "WEEK";
|
|
||||||
public static final String YEAR = "YEAR";
|
|
||||||
|
|
||||||
public static final String JOIN_UNDERLINE = "__";
|
public static final String JOIN_UNDERLINE = "__";
|
||||||
|
|
||||||
public static final String LIST_LOWER = "list";
|
|
||||||
public static final String TOTAL_LOWER = "total";
|
|
||||||
public static final String PAGESIZE_LOWER = "pageSize";
|
|
||||||
public static final String TRUE_LOWER = "true";
|
|
||||||
|
|
||||||
public static final String NULL = "null";
|
public static final String NULL = "null";
|
||||||
public static final Double MAX_SIMILARITY = 1.0d;
|
|
||||||
public static final String CONTEXT = "CONTEXT";
|
public static final String CONTEXT = "CONTEXT";
|
||||||
public static final String BRACKETS_START = "[";
|
|
||||||
public static final String BRACKETS_END = "]";
|
|
||||||
|
|
||||||
public static final Long DEFAULT_FREQUENCY = 100000L;
|
public static final Long DEFAULT_FREQUENCY = 100000L;
|
||||||
|
|
||||||
public static final String TABLE_PREFIX = "t_";
|
public static final String TABLE_PREFIX = "t_";
|
||||||
|
|
||||||
public static final Long DEFAULT_DETAIL_LIMIT = 500L;
|
public static final Long DEFAULT_DETAIL_LIMIT = 500L;
|
||||||
public static final Long DEFAULT_METRIC_LIMIT = 200L;
|
public static final Long DEFAULT_METRIC_LIMIT = 200L;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.tencent.supersonic.common.pojo;
|
package com.tencent.supersonic.common.pojo;
|
||||||
|
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
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 lombok.Data;
|
import lombok.Data;
|
||||||
@@ -29,8 +30,8 @@ public class DateConf {
|
|||||||
/** the last unit time unit, such as the last 7 days, unit = 7 */
|
/** the last unit time unit, such as the last 7 days, unit = 7 */
|
||||||
private Integer unit = 1;
|
private Integer unit = 1;
|
||||||
|
|
||||||
/** DAY,WEEK,MONTH */
|
/** DAY,WEEK,MONTH,QUARTER,YEAR */
|
||||||
private String period = Constants.DAY;
|
private DatePeriodEnum period = DatePeriodEnum.DAY;
|
||||||
|
|
||||||
/** the text parse from , example "last 7 days" , "last mouth" */
|
/** the text parse from , example "last 7 days" , "last mouth" */
|
||||||
private String detectWord;
|
private String detectWord;
|
||||||
@@ -49,11 +50,11 @@ public class DateConf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupByTimeDimension() {
|
public String getGroupByTimeDimension() {
|
||||||
if (Constants.DAY.equals(period)) {
|
if (DatePeriodEnum.DAY.equals(period)) {
|
||||||
return TimeDimensionEnum.DAY.getName();
|
return TimeDimensionEnum.DAY.getName();
|
||||||
} else if (Constants.WEEK.equals(period)) {
|
} else if (DatePeriodEnum.WEEK.equals(period)) {
|
||||||
return TimeDimensionEnum.WEEK.getName();
|
return TimeDimensionEnum.WEEK.getName();
|
||||||
} else if (Constants.MONTH.equals(period)) {
|
} else if (DatePeriodEnum.MONTH.equals(period)) {
|
||||||
return TimeDimensionEnum.MONTH.getName();
|
return TimeDimensionEnum.MONTH.getName();
|
||||||
} else {
|
} else {
|
||||||
return TimeDimensionEnum.DAY.getName();
|
return TimeDimensionEnum.DAY.getName();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tencent.supersonic.common.pojo.enums;
|
package com.tencent.supersonic.common.pojo.enums;
|
||||||
|
|
||||||
public enum DatePeriodEnum {
|
public enum DatePeriodEnum {
|
||||||
DAY("日"),
|
DAY("天"),
|
||||||
WEEK("周"),
|
WEEK("周"),
|
||||||
MONTH("月"),
|
MONTH("月"),
|
||||||
QUARTER("季度"),
|
QUARTER("季度"),
|
||||||
@@ -24,4 +24,13 @@ public enum DatePeriodEnum {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DatePeriodEnum fromChName(String chName) {
|
||||||
|
for (DatePeriodEnum value : values()) {
|
||||||
|
if (value.chName.equals(chName)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.common.util;
|
|||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.Constants;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
import com.tencent.supersonic.common.pojo.ItemDateResp;
|
import com.tencent.supersonic.common.pojo.ItemDateResp;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -23,12 +24,8 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
|
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
|
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||||
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;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.YEAR;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -50,16 +47,6 @@ public class DateModeUtils {
|
|||||||
@Value("${s2.query.parameter.sys.zipper.end:end_}")
|
@Value("${s2.query.parameter.sys.zipper.end:end_}")
|
||||||
private String sysZipperDateColEnd;
|
private String sysZipperDateColEnd;
|
||||||
|
|
||||||
public Boolean recentMode(DateConf dateInfo) {
|
|
||||||
if (Objects.nonNull(dateInfo)
|
|
||||||
&& DateConf.DateMode.RECENT == dateInfo.getDateMode()
|
|
||||||
&& DAY.equalsIgnoreCase(dateInfo.getPeriod())
|
|
||||||
&& Objects.nonNull(dateInfo.getUnit())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasAvailableDataMode(DateConf dateInfo) {
|
public boolean hasAvailableDataMode(DateConf dateInfo) {
|
||||||
if (Objects.nonNull(dateInfo) && DateConf.DateMode.AVAILABLE == dateInfo.getDateMode()) {
|
if (Objects.nonNull(dateInfo) && DateConf.DateMode.AVAILABLE == dateInfo.getDateMode()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -93,7 +80,7 @@ public class DateModeUtils {
|
|||||||
LocalDate endReq = LocalDate.parse(dateInfo.getEndDate(), formatter);
|
LocalDate endReq = LocalDate.parse(dateInfo.getEndDate(), formatter);
|
||||||
|
|
||||||
if (endReq.isAfter(endData)) {
|
if (endReq.isAfter(endData)) {
|
||||||
if (DAY.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.DAY.equals(dateInfo.getPeriod())) {
|
||||||
Long unit =
|
Long unit =
|
||||||
getInterval(
|
getInterval(
|
||||||
dateInfo.getStartDate(),
|
dateInfo.getStartDate(),
|
||||||
@@ -106,7 +93,7 @@ public class DateModeUtils {
|
|||||||
"(%s >= '%s' and %s <= '%s')", sysDateCol, dateMin, sysDateCol, dateMax);
|
"(%s >= '%s' and %s <= '%s')", sysDateCol, dateMin, sysDateCol, dateMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateInfo.getPeriod())) {
|
||||||
Long unit =
|
Long unit =
|
||||||
getInterval(
|
getInterval(
|
||||||
dateInfo.getStartDate(),
|
dateInfo.getStartDate(),
|
||||||
@@ -193,7 +180,8 @@ public class DateModeUtils {
|
|||||||
dateDate.getEndDate(),
|
dateDate.getEndDate(),
|
||||||
DateTimeFormatter.ofPattern(dateDate.getDateFormat()));
|
DateTimeFormatter.ofPattern(dateDate.getDateFormat()));
|
||||||
List<ImmutablePair<String, String>> ret = new ArrayList<>();
|
List<ImmutablePair<String, String>> ret = new ArrayList<>();
|
||||||
if (dateDate.getDatePeriod() != null && MONTH.equalsIgnoreCase(dateDate.getDatePeriod())) {
|
if (dateDate.getDatePeriod() != null
|
||||||
|
&& DatePeriodEnum.MONTH.equals(dateDate.getDatePeriod())) {
|
||||||
Long unit =
|
Long unit =
|
||||||
getInterval(
|
getInterval(
|
||||||
dateInfo.getStartDate(),
|
dateInfo.getStartDate(),
|
||||||
@@ -260,13 +248,13 @@ public class DateModeUtils {
|
|||||||
if (Objects.isNull(dateDate)) {
|
if (Objects.isNull(dateDate)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (DAY.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.DAY.equals(dateInfo.getPeriod())) {
|
||||||
return recentDayStr(dateDate, dateInfo);
|
return recentDayStr(dateDate, dateInfo);
|
||||||
}
|
}
|
||||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateInfo.getPeriod())) {
|
||||||
return recentMonthStr(dateDate, dateInfo);
|
return recentMonthStr(dateDate, dateInfo);
|
||||||
}
|
}
|
||||||
if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(dateInfo.getPeriod())) {
|
||||||
return recentWeekStr(dateDate, dateInfo);
|
return recentWeekStr(dateDate, dateInfo);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -279,7 +267,7 @@ public class DateModeUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String betweenDateStr(DateConf dateInfo) {
|
public String betweenDateStr(DateConf dateInfo) {
|
||||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateInfo.getPeriod())) {
|
||||||
// startDate YYYYMM
|
// startDate YYYYMM
|
||||||
if (!dateInfo.getStartDate().contains(Constants.MINUS)) {
|
if (!dateInfo.getStartDate().contains(Constants.MINUS)) {
|
||||||
return String.format(
|
return String.format(
|
||||||
@@ -302,7 +290,7 @@ public class DateModeUtils {
|
|||||||
sysDateMonthCol,
|
sysDateMonthCol,
|
||||||
endData.format(formatter));
|
endData.format(formatter));
|
||||||
}
|
}
|
||||||
if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(dateInfo.getPeriod())) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"%s >= '%s' and %s <= '%s'",
|
"%s >= '%s' and %s <= '%s'",
|
||||||
sysDateWeekCol, dateInfo.getStartDate(), sysDateWeekCol, dateInfo.getEndDate());
|
sysDateWeekCol, dateInfo.getStartDate(), sysDateWeekCol, dateInfo.getEndDate());
|
||||||
@@ -322,10 +310,10 @@ public class DateModeUtils {
|
|||||||
StringJoiner joiner = new StringJoiner(COMMA);
|
StringJoiner joiner = new StringJoiner(COMMA);
|
||||||
dateInfo.getDateList().stream().forEach(date -> joiner.add(APOSTROPHE + date + APOSTROPHE));
|
dateInfo.getDateList().stream().forEach(date -> joiner.add(APOSTROPHE + date + APOSTROPHE));
|
||||||
String dateCol = sysDateCol;
|
String dateCol = sysDateCol;
|
||||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateInfo.getPeriod())) {
|
||||||
dateCol = sysDateMonthCol;
|
dateCol = sysDateMonthCol;
|
||||||
}
|
}
|
||||||
if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(dateInfo.getPeriod())) {
|
||||||
dateCol = sysDateWeekCol;
|
dateCol = sysDateWeekCol;
|
||||||
}
|
}
|
||||||
return String.format("(%s in (%s))", dateCol, joiner.toString());
|
return String.format("(%s in (%s))", dateCol, joiner.toString());
|
||||||
@@ -344,22 +332,22 @@ public class DateModeUtils {
|
|||||||
|
|
||||||
Integer unit = dateInfo.getUnit();
|
Integer unit = dateInfo.getUnit();
|
||||||
|
|
||||||
if (DAY.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.DAY.equals(dateInfo.getPeriod())) {
|
||||||
LocalDate dateMax = LocalDate.now().minusDays(1);
|
LocalDate dateMax = LocalDate.now().minusDays(1);
|
||||||
LocalDate dateMin = dateMax.minusDays(unit - 1);
|
LocalDate dateMin = dateMax.minusDays(unit - 1);
|
||||||
return String.format(
|
return String.format(
|
||||||
"(%s >= '%s' and %s <= '%s')", sysDateCol, dateMin, sysDateCol, dateMax);
|
"(%s >= '%s' and %s <= '%s')", sysDateCol, dateMin, sysDateCol, dateMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(dateInfo.getPeriod())) {
|
||||||
LocalDate dateMax = LocalDate.now().minusDays(1);
|
LocalDate dateMax = LocalDate.now().minusDays(1);
|
||||||
return recentWeekStr(dateMax, unit.longValue());
|
return recentWeekStr(dateMax, unit.longValue());
|
||||||
}
|
}
|
||||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateInfo.getPeriod())) {
|
||||||
LocalDate dateMax = LocalDate.now().minusDays(1);
|
LocalDate dateMax = LocalDate.now().minusDays(1);
|
||||||
return recentMonthStr(dateMax, unit.longValue(), MONTH_FORMAT);
|
return recentMonthStr(dateMax, unit.longValue(), MONTH_FORMAT);
|
||||||
}
|
}
|
||||||
if (YEAR.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.YEAR.equals(dateInfo.getPeriod())) {
|
||||||
LocalDate dateMax = LocalDate.now().minusDays(1);
|
LocalDate dateMax = LocalDate.now().minusDays(1);
|
||||||
return recentMonthStr(dateMax, unit.longValue() * 12, MONTH_FORMAT);
|
return recentMonthStr(dateMax, unit.longValue() * 12, MONTH_FORMAT);
|
||||||
}
|
}
|
||||||
@@ -398,13 +386,13 @@ public class DateModeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getSysDateCol(DateConf dateInfo) {
|
public String getSysDateCol(DateConf dateInfo) {
|
||||||
if (DAY.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.DAY.equals(dateInfo.getPeriod())) {
|
||||||
return sysDateCol;
|
return sysDateCol;
|
||||||
}
|
}
|
||||||
if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(dateInfo.getPeriod())) {
|
||||||
return sysDateWeekCol;
|
return sysDateWeekCol;
|
||||||
}
|
}
|
||||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateInfo.getPeriod())) {
|
||||||
return sysDateMonthCol;
|
return sysDateMonthCol;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -414,16 +402,16 @@ public class DateModeUtils {
|
|||||||
return Pattern.matches("[\\d\\s-:]+", date);
|
return Pattern.matches("[\\d\\s-:]+", date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPeriodByCol(String col) {
|
public DatePeriodEnum getPeriodByCol(String col) {
|
||||||
if (sysDateCol.equalsIgnoreCase(col)) {
|
if (sysDateCol.equalsIgnoreCase(col)) {
|
||||||
return DAY;
|
return DatePeriodEnum.DAY;
|
||||||
}
|
}
|
||||||
if (sysDateWeekCol.equalsIgnoreCase(col)) {
|
if (sysDateWeekCol.equalsIgnoreCase(col)) {
|
||||||
return WEEK;
|
return DatePeriodEnum.WEEK;
|
||||||
}
|
}
|
||||||
if (sysDateMonthCol.equalsIgnoreCase(col)) {
|
if (sysDateMonthCol.equalsIgnoreCase(col)) {
|
||||||
return MONTH;
|
return DatePeriodEnum.MONTH;
|
||||||
}
|
}
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.tencent.supersonic.common.util;
|
package com.tencent.supersonic.common.util;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -163,7 +162,8 @@ public class DateUtils {
|
|||||||
return !timeString.equals("00:00:00");
|
return !timeString.equals("00:00:00");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getDateList(String startDateStr, String endDateStr, String period) {
|
public static List<String> getDateList(
|
||||||
|
String startDateStr, String endDateStr, DatePeriodEnum period) {
|
||||||
try {
|
try {
|
||||||
LocalDate startDate = LocalDate.parse(startDateStr);
|
LocalDate startDate = LocalDate.parse(startDateStr);
|
||||||
LocalDate endDate = LocalDate.parse(endDateStr);
|
LocalDate endDate = LocalDate.parse(endDateStr);
|
||||||
@@ -171,10 +171,10 @@ public class DateUtils {
|
|||||||
LocalDate currentDate = startDate;
|
LocalDate currentDate = startDate;
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||||
while (!currentDate.isAfter(endDate)) {
|
while (!currentDate.isAfter(endDate)) {
|
||||||
if (Constants.MONTH.equals(period)) {
|
if (DatePeriodEnum.MONTH.equals(period)) {
|
||||||
datesInRange.add(currentDate.format(formatter));
|
datesInRange.add(currentDate.format(formatter));
|
||||||
currentDate = currentDate.plusMonths(1);
|
currentDate = currentDate.plusMonths(1);
|
||||||
} else if (Constants.WEEK.equals(period)) {
|
} else if (DatePeriodEnum.WEEK.equals((period))) {
|
||||||
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
|
datesInRange.add(currentDate.format(DateTimeFormatter.ISO_DATE));
|
||||||
currentDate = currentDate.plusWeeks(1);
|
currentDate = currentDate.plusWeeks(1);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.tencent.supersonic.common;
|
package com.tencent.supersonic.common;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.util.DateUtils;
|
import com.tencent.supersonic.common.util.DateUtils;
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
@@ -47,7 +46,7 @@ class DateUtilsTest {
|
|||||||
void testDayDateList() {
|
void testDayDateList() {
|
||||||
String startDate = "2023-07-29";
|
String startDate = "2023-07-29";
|
||||||
String endDate = "2023-08-03";
|
String endDate = "2023-08-03";
|
||||||
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, Constants.DAY);
|
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, DatePeriodEnum.DAY);
|
||||||
List<String> expectedDateList =
|
List<String> expectedDateList =
|
||||||
Lists.newArrayList(
|
Lists.newArrayList(
|
||||||
"2023-07-29",
|
"2023-07-29",
|
||||||
@@ -56,14 +55,15 @@ class DateUtilsTest {
|
|||||||
"2023-08-01",
|
"2023-08-01",
|
||||||
"2023-08-02",
|
"2023-08-02",
|
||||||
"2023-08-03");
|
"2023-08-03");
|
||||||
Assertions.assertEquals(actualDateList, expectedDateList);
|
Assertions.assertEquals(expectedDateList, actualDateList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWeekDateList() {
|
void testWeekDateList() {
|
||||||
String startDate = "2023-10-30";
|
String startDate = "2023-10-30";
|
||||||
String endDate = "2023-11-13";
|
String endDate = "2023-11-13";
|
||||||
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, Constants.WEEK);
|
List<String> actualDateList =
|
||||||
|
DateUtils.getDateList(startDate, endDate, DatePeriodEnum.WEEK);
|
||||||
List<String> expectedDateList =
|
List<String> expectedDateList =
|
||||||
Lists.newArrayList("2023-10-30", "2023-11-06", "2023-11-13");
|
Lists.newArrayList("2023-10-30", "2023-11-06", "2023-11-13");
|
||||||
Assertions.assertEquals(actualDateList, expectedDateList);
|
Assertions.assertEquals(actualDateList, expectedDateList);
|
||||||
@@ -73,7 +73,8 @@ class DateUtilsTest {
|
|||||||
void testMonthDateList() {
|
void testMonthDateList() {
|
||||||
String startDate = "2023-07-01";
|
String startDate = "2023-07-01";
|
||||||
String endDate = "2023-10-01";
|
String endDate = "2023-10-01";
|
||||||
List<String> actualDateList = DateUtils.getDateList(startDate, endDate, Constants.MONTH);
|
List<String> actualDateList =
|
||||||
|
DateUtils.getDateList(startDate, endDate, DatePeriodEnum.MONTH);
|
||||||
List<String> expectedDateList =
|
List<String> expectedDateList =
|
||||||
Lists.newArrayList("2023-07", "2023-08", "2023-09", "2023-10");
|
Lists.newArrayList("2023-07", "2023-08", "2023-09", "2023-10");
|
||||||
Assertions.assertEquals(actualDateList, expectedDateList);
|
Assertions.assertEquals(actualDateList, expectedDateList);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.headless.api.pojo;
|
package com.tencent.supersonic.headless.api.pojo;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ import lombok.Data;
|
|||||||
public class MetricTypeDefaultConfig {
|
public class MetricTypeDefaultConfig {
|
||||||
|
|
||||||
private TimeDefaultConfig timeDefaultConfig =
|
private TimeDefaultConfig timeDefaultConfig =
|
||||||
new TimeDefaultConfig(7, Constants.DAY, TimeMode.RECENT);
|
new TimeDefaultConfig(7, DatePeriodEnum.DAY, TimeMode.RECENT);
|
||||||
|
|
||||||
private Long limit;
|
private Long limit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.headless.api.pojo;
|
package com.tencent.supersonic.headless.api.pojo;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -14,8 +14,7 @@ public class TimeDefaultConfig {
|
|||||||
/** default time span unit */
|
/** default time span unit */
|
||||||
private Integer unit = 1;
|
private Integer unit = 1;
|
||||||
|
|
||||||
/** default time type: day DAY, WEEK, MONTH, YEAR */
|
private DatePeriodEnum period = DatePeriodEnum.DAY;
|
||||||
private String period = Constants.DAY;
|
|
||||||
|
|
||||||
private TimeMode timeMode = TimeMode.LAST;
|
private TimeMode timeMode = TimeMode.LAST;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class S2SqlDateHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimeMode timeMode = timeConfig.getTimeMode();
|
TimeMode timeMode = timeConfig.getTimeMode();
|
||||||
DatePeriodEnum datePeriod = DatePeriodEnum.get(timeConfig.getPeriod());
|
DatePeriodEnum datePeriod = timeConfig.getPeriod();
|
||||||
String startDate;
|
String startDate;
|
||||||
String endDate;
|
String endDate;
|
||||||
switch (timeMode) {
|
switch (timeMode) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.tencent.supersonic.headless.chat.parser.rule;
|
package com.tencent.supersonic.headless.chat.parser.rule;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
||||||
import com.tencent.supersonic.headless.chat.parser.SemanticParser;
|
import com.tencent.supersonic.headless.chat.parser.SemanticParser;
|
||||||
@@ -132,11 +132,11 @@ public class TimeRangeParser implements SemanticParser {
|
|||||||
String detectWord = matcher.group("periodStr");
|
String detectWord = matcher.group("periodStr");
|
||||||
|
|
||||||
DateConf info = new DateConf();
|
DateConf info = new DateConf();
|
||||||
info.setPeriod(getPeriodConstant(zhPeriod));
|
info.setPeriod(DatePeriodEnum.fromChName(zhPeriod));
|
||||||
info.setDateMode(DateConf.DateMode.RECENT);
|
info.setDateMode(DateConf.DateMode.BETWEEN);
|
||||||
info.setDetectWord(detectWord);
|
info.setDetectWord(detectWord);
|
||||||
info.setStartDate(LocalDate.now().minusDays(days).toString());
|
info.setStartDate(LocalDate.now().minusDays(days).toString());
|
||||||
info.setEndDate(LocalDate.now().minusDays(1).toString());
|
info.setEndDate(LocalDate.now().toString());
|
||||||
info.setUnit(num);
|
info.setUnit(num);
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
@@ -166,19 +166,6 @@ public class TimeRangeParser implements SemanticParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPeriodConstant(String zhPeriod) {
|
|
||||||
switch (zhPeriod) {
|
|
||||||
case "周":
|
|
||||||
return Constants.WEEK;
|
|
||||||
case "月":
|
|
||||||
return Constants.MONTH;
|
|
||||||
case "年":
|
|
||||||
return Constants.YEAR;
|
|
||||||
default:
|
|
||||||
return Constants.DAY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int zhNumParse(String zhNumStr) {
|
private int zhNumParse(String zhNumStr) {
|
||||||
Stack<Integer> stack = new Stack<>();
|
Stack<Integer> stack = new Stack<>();
|
||||||
String numStr = "一二三四五六七八九";
|
String numStr = "一二三四五六七八九";
|
||||||
|
|||||||
@@ -49,13 +49,11 @@ public abstract class DetailSemanticQuery extends RuleSemanticQuery {
|
|||||||
&& timeDefaultConfig.getUnit() != -1) {
|
&& timeDefaultConfig.getUnit() != -1) {
|
||||||
DateConf dateInfo = new DateConf();
|
DateConf dateInfo = new DateConf();
|
||||||
int unit = timeDefaultConfig.getUnit();
|
int unit = timeDefaultConfig.getUnit();
|
||||||
String startDate = LocalDate.now().plusDays(-unit).toString();
|
String startDate = LocalDate.now().minusDays(unit).toString();
|
||||||
String endDate = startDate;
|
String endDate = startDate;
|
||||||
if (TimeMode.LAST.equals(timeDefaultConfig.getTimeMode())) {
|
|
||||||
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
||||||
} else if (TimeMode.RECENT.equals(timeDefaultConfig.getTimeMode())) {
|
if (TimeMode.RECENT.equals(timeDefaultConfig.getTimeMode())) {
|
||||||
dateInfo.setDateMode(DateConf.DateMode.RECENT);
|
endDate = LocalDate.now().toString();
|
||||||
endDate = LocalDate.now().plusDays(-1).toString();
|
|
||||||
}
|
}
|
||||||
dateInfo.setUnit(unit);
|
dateInfo.setUnit(unit);
|
||||||
dateInfo.setPeriod(timeDefaultConfig.getPeriod());
|
dateInfo.setPeriod(timeDefaultConfig.getPeriod());
|
||||||
|
|||||||
@@ -56,13 +56,11 @@ public abstract class MetricSemanticQuery extends RuleSemanticQuery {
|
|||||||
&& Objects.nonNull(timeDefaultConfig.getUnit())
|
&& Objects.nonNull(timeDefaultConfig.getUnit())
|
||||||
&& timeDefaultConfig.getUnit() != -1) {
|
&& timeDefaultConfig.getUnit() != -1) {
|
||||||
int unit = timeDefaultConfig.getUnit();
|
int unit = timeDefaultConfig.getUnit();
|
||||||
String startDate = LocalDate.now().plusDays(-unit).toString();
|
String startDate = LocalDate.now().minusDays(unit).toString();
|
||||||
String endDate = startDate;
|
String endDate = startDate;
|
||||||
if (TimeMode.LAST.equals(timeDefaultConfig.getTimeMode())) {
|
|
||||||
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
||||||
} else if (TimeMode.RECENT.equals(timeDefaultConfig.getTimeMode())) {
|
if (TimeMode.RECENT.equals(timeDefaultConfig.getTimeMode())) {
|
||||||
dateInfo.setDateMode(DateConf.DateMode.RECENT);
|
endDate = LocalDate.now().toString();
|
||||||
endDate = LocalDate.now().plusDays(-1).toString();
|
|
||||||
}
|
}
|
||||||
dateInfo.setUnit(unit);
|
dateInfo.setUnit(unit);
|
||||||
dateInfo.setPeriod(timeDefaultConfig.getPeriod());
|
dateInfo.setPeriod(timeDefaultConfig.getPeriod());
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package com.tencent.supersonic.headless.chat.utils;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
import com.tencent.supersonic.common.pojo.Filter;
|
import com.tencent.supersonic.common.pojo.Filter;
|
||||||
import com.tencent.supersonic.common.pojo.Order;
|
import com.tencent.supersonic.common.pojo.Order;
|
||||||
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.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||||
@@ -23,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -42,7 +41,7 @@ public class QueryReqBuilder {
|
|||||||
queryStructReq.setDataSetId(parseInfo.getDataSetId());
|
queryStructReq.setDataSetId(parseInfo.getDataSetId());
|
||||||
queryStructReq.setDataSetName(parseInfo.getDataSet().getName());
|
queryStructReq.setDataSetName(parseInfo.getDataSet().getName());
|
||||||
queryStructReq.setQueryType(parseInfo.getQueryType());
|
queryStructReq.setQueryType(parseInfo.getQueryType());
|
||||||
queryStructReq.setDateInfo(rewrite2Between(parseInfo.getDateInfo()));
|
queryStructReq.setDateInfo(parseInfo.getDateInfo());
|
||||||
|
|
||||||
List<Filter> dimensionFilters = getFilters(parseInfo.getDimensionFilters());
|
List<Filter> dimensionFilters = getFilters(parseInfo.getDimensionFilters());
|
||||||
queryStructReq.setDimensionFilters(dimensionFilters);
|
queryStructReq.setDimensionFilters(dimensionFilters);
|
||||||
@@ -108,40 +107,6 @@ public class QueryReqBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DateConf rewrite2Between(DateConf dateInfo) {
|
|
||||||
if (Objects.isNull(dateInfo)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
DateConf dateInfoNew = new DateConf();
|
|
||||||
BeanUtils.copyProperties(dateInfo, dateInfoNew);
|
|
||||||
if (DateConf.DateMode.RECENT.equals(dateInfo.getDateMode())) {
|
|
||||||
int unit = dateInfo.getUnit();
|
|
||||||
int days = 1;
|
|
||||||
switch (dateInfo.getPeriod()) {
|
|
||||||
case Constants.DAY:
|
|
||||||
days = 1;
|
|
||||||
break;
|
|
||||||
case Constants.WEEK:
|
|
||||||
days = 7;
|
|
||||||
break;
|
|
||||||
case Constants.MONTH:
|
|
||||||
days = 30;
|
|
||||||
break;
|
|
||||||
case Constants.YEAR:
|
|
||||||
days = 365;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
String startDate = LocalDate.now().plusDays(-(unit * days)).toString();
|
|
||||||
String endDate = LocalDate.now().plusDays(-1).toString();
|
|
||||||
dateInfoNew.setDateMode(DateConf.DateMode.BETWEEN);
|
|
||||||
dateInfoNew.setStartDate(startDate);
|
|
||||||
dateInfoNew.setEndDate(endDate);
|
|
||||||
}
|
|
||||||
return dateInfoNew;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static QueryMultiStructReq buildMultiStructReq(SemanticParseInfo parseInfo) {
|
public static QueryMultiStructReq buildMultiStructReq(SemanticParseInfo parseInfo) {
|
||||||
QueryStructReq queryStructReq = buildStructReq(parseInfo);
|
QueryStructReq queryStructReq = buildStructReq(parseInfo);
|
||||||
QueryMultiStructReq queryMultiStructReq = new QueryMultiStructReq();
|
QueryMultiStructReq queryMultiStructReq = new QueryMultiStructReq();
|
||||||
@@ -282,10 +247,10 @@ public class QueryReqBuilder {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String dateField = TimeDimensionEnum.DAY.getName();
|
String dateField = TimeDimensionEnum.DAY.getName();
|
||||||
if (Constants.MONTH.equals(dateConf.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateConf.getPeriod())) {
|
||||||
dateField = TimeDimensionEnum.MONTH.getName();
|
dateField = TimeDimensionEnum.MONTH.getName();
|
||||||
}
|
}
|
||||||
if (Constants.WEEK.equals(dateConf.getPeriod())) {
|
if (DatePeriodEnum.WEEK.equals(dateConf.getPeriod())) {
|
||||||
dateField = TimeDimensionEnum.WEEK.getName();
|
dateField = TimeDimensionEnum.WEEK.getName();
|
||||||
}
|
}
|
||||||
return dateField;
|
return dateField;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.headless.chat.utils;
|
package com.tencent.supersonic.headless.chat.utils;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
import com.tencent.supersonic.common.pojo.enums.TimeMode;
|
||||||
import com.tencent.supersonic.headless.api.pojo.TimeDefaultConfig;
|
import com.tencent.supersonic.headless.api.pojo.TimeDefaultConfig;
|
||||||
import com.tencent.supersonic.headless.chat.corrector.S2SqlDateHelper;
|
import com.tencent.supersonic.headless.chat.corrector.S2SqlDateHelper;
|
||||||
@@ -13,14 +13,14 @@ class S2SqlDateHelperTest {
|
|||||||
void testCurrentTimeMode() {
|
void testCurrentTimeMode() {
|
||||||
TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
||||||
timeDefaultConfig.setTimeMode(TimeMode.CURRENT);
|
timeDefaultConfig.setTimeMode(TimeMode.CURRENT);
|
||||||
timeDefaultConfig.setPeriod(Constants.MONTH);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.MONTH);
|
||||||
|
|
||||||
Pair<String, String> dateRange =
|
Pair<String, String> dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2024-09-01");
|
assert dateRange.getLeft().equals("2024-09-01");
|
||||||
assert dateRange.getRight().equals("2024-09-21");
|
assert dateRange.getRight().equals("2024-09-21");
|
||||||
|
|
||||||
timeDefaultConfig.setPeriod(Constants.YEAR);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.YEAR);
|
||||||
dateRange =
|
dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2024-01-01");
|
assert dateRange.getLeft().equals("2024-01-01");
|
||||||
@@ -32,20 +32,20 @@ class S2SqlDateHelperTest {
|
|||||||
TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
||||||
timeDefaultConfig.setTimeMode(TimeMode.RECENT);
|
timeDefaultConfig.setTimeMode(TimeMode.RECENT);
|
||||||
timeDefaultConfig.setUnit(3);
|
timeDefaultConfig.setUnit(3);
|
||||||
timeDefaultConfig.setPeriod(Constants.DAY);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.DAY);
|
||||||
|
|
||||||
Pair<String, String> dateRange =
|
Pair<String, String> dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2024-09-18");
|
assert dateRange.getLeft().equals("2024-09-18");
|
||||||
assert dateRange.getRight().equals("2024-09-21");
|
assert dateRange.getRight().equals("2024-09-21");
|
||||||
|
|
||||||
timeDefaultConfig.setPeriod(Constants.MONTH);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.MONTH);
|
||||||
dateRange =
|
dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2024-06-21");
|
assert dateRange.getLeft().equals("2024-06-21");
|
||||||
assert dateRange.getRight().equals("2024-09-21");
|
assert dateRange.getRight().equals("2024-09-21");
|
||||||
|
|
||||||
timeDefaultConfig.setPeriod(Constants.YEAR);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.YEAR);
|
||||||
dateRange =
|
dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2021-09-21");
|
assert dateRange.getLeft().equals("2021-09-21");
|
||||||
@@ -57,20 +57,20 @@ class S2SqlDateHelperTest {
|
|||||||
TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
TimeDefaultConfig timeDefaultConfig = new TimeDefaultConfig();
|
||||||
timeDefaultConfig.setTimeMode(TimeMode.LAST);
|
timeDefaultConfig.setTimeMode(TimeMode.LAST);
|
||||||
timeDefaultConfig.setUnit(3);
|
timeDefaultConfig.setUnit(3);
|
||||||
timeDefaultConfig.setPeriod(Constants.DAY);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.DAY);
|
||||||
|
|
||||||
Pair<String, String> dateRange =
|
Pair<String, String> dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2024-09-18");
|
assert dateRange.getLeft().equals("2024-09-18");
|
||||||
assert dateRange.getRight().equals("2024-09-18");
|
assert dateRange.getRight().equals("2024-09-18");
|
||||||
|
|
||||||
timeDefaultConfig.setPeriod(Constants.MONTH);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.MONTH);
|
||||||
dateRange =
|
dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2024-06-21");
|
assert dateRange.getLeft().equals("2024-06-21");
|
||||||
assert dateRange.getRight().equals("2024-06-21");
|
assert dateRange.getRight().equals("2024-06-21");
|
||||||
|
|
||||||
timeDefaultConfig.setPeriod(Constants.YEAR);
|
timeDefaultConfig.setPeriod(DatePeriodEnum.YEAR);
|
||||||
dateRange =
|
dateRange =
|
||||||
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
S2SqlDateHelper.calculateDateRange("2024-09-21", timeDefaultConfig, "yyyy-MM-dd");
|
||||||
assert dateRange.getLeft().equals("2021-09-21");
|
assert dateRange.getLeft().equals("2021-09-21");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.headless.core.config;
|
package com.tencent.supersonic.headless.core.config;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
@@ -16,5 +16,5 @@ public class DefaultMetricInfo {
|
|||||||
private Integer unit = 1;
|
private Integer unit = 1;
|
||||||
|
|
||||||
/** default time type: day DAY, WEEK, MONTH, YEAR */
|
/** default time type: day DAY, WEEK, MONTH, YEAR */
|
||||||
private String period = Constants.DAY;
|
private DatePeriodEnum period = DatePeriodEnum.DAY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.tencent.supersonic.headless.core.translator.converter;
|
package com.tencent.supersonic.headless.core.translator.converter;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.AggOperatorEnum;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.common.util.DateModeUtils;
|
import com.tencent.supersonic.common.util.DateModeUtils;
|
||||||
import com.tencent.supersonic.headless.api.pojo.MetricTable;
|
import com.tencent.supersonic.headless.api.pojo.MetricTable;
|
||||||
@@ -214,13 +214,13 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
public String getTimeSpan(QueryParam queryParam, boolean isOver, boolean isAdd) {
|
public String getTimeSpan(QueryParam queryParam, boolean isOver, boolean isAdd) {
|
||||||
if (Objects.nonNull(queryParam.getDateInfo())) {
|
if (Objects.nonNull(queryParam.getDateInfo())) {
|
||||||
String addStr = isAdd ? "" : "-";
|
String addStr = isAdd ? "" : "-";
|
||||||
if (queryParam.getDateInfo().getPeriod().equalsIgnoreCase(Constants.DAY)) {
|
if (queryParam.getDateInfo().getPeriod().equals(DatePeriodEnum.DAY)) {
|
||||||
return "day," + (isOver ? addStr + "7" : addStr + "1");
|
return "day," + (isOver ? addStr + "7" : addStr + "1");
|
||||||
}
|
}
|
||||||
if (queryParam.getDateInfo().getPeriod().equalsIgnoreCase(Constants.WEEK)) {
|
if (queryParam.getDateInfo().getPeriod().equals(DatePeriodEnum.MONTH)) {
|
||||||
return isOver ? "month," + addStr + "1" : "day," + addStr + "7";
|
return isOver ? "month," + addStr + "1" : "day," + addStr + "7";
|
||||||
}
|
}
|
||||||
if (queryParam.getDateInfo().getPeriod().equalsIgnoreCase(Constants.MONTH)) {
|
if (queryParam.getDateInfo().getPeriod().equals(DatePeriodEnum.MONTH.MONTH)) {
|
||||||
return isOver ? "year," + addStr + "1" : "month," + addStr + "1";
|
return isOver ? "year," + addStr + "1" : "month," + addStr + "1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
if (queryParam
|
if (queryParam
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.getPeriod()
|
.getPeriod()
|
||||||
.equals(Constants.MONTH)) {
|
.equals(DatePeriodEnum.MONTH)) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"%s is not null and %s = FORMATDATETIME(DATEADD(%s,CONCAT(%s,'-01')),'yyyy-MM') ",
|
"%s is not null and %s = FORMATDATETIME(DATEADD(%s,CONCAT(%s,'-01')),'yyyy-MM') ",
|
||||||
aliasRight + timeDim,
|
aliasRight + timeDim,
|
||||||
@@ -251,7 +251,7 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
if (queryParam
|
if (queryParam
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.getPeriod()
|
.getPeriod()
|
||||||
.equals(Constants.WEEK)
|
.equals(DatePeriodEnum.WEEK)
|
||||||
&& isOver) {
|
&& isOver) {
|
||||||
return String.format(
|
return String.format(
|
||||||
" DATE_TRUNC('week',DATEADD(%s,%s) ) = %s ",
|
" DATE_TRUNC('week',DATEADD(%s,%s) ) = %s ",
|
||||||
@@ -313,7 +313,7 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
if (queryParam
|
if (queryParam
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.getPeriod()
|
.getPeriod()
|
||||||
.equals(Constants.MONTH)) {
|
.equals(DatePeriodEnum.MONTH)) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"toDate(CONCAT(%s,'-01')) = date_add(toDate(CONCAT(%s,'-01')),%s) ",
|
"toDate(CONCAT(%s,'-01')) = date_add(toDate(CONCAT(%s,'-01')),%s) ",
|
||||||
aliasLeft + timeDim,
|
aliasLeft + timeDim,
|
||||||
@@ -323,7 +323,7 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
if (queryParam
|
if (queryParam
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.getPeriod()
|
.getPeriod()
|
||||||
.equals(Constants.WEEK)
|
.equals(DatePeriodEnum.WEEK)
|
||||||
&& isOver) {
|
&& isOver) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"toMonday(date_add(%s ,INTERVAL %s) ) = %s",
|
"toMonday(date_add(%s ,INTERVAL %s) ) = %s",
|
||||||
@@ -386,13 +386,13 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
public String getTimeSpan(QueryParam queryParam, boolean isOver, boolean isAdd) {
|
public String getTimeSpan(QueryParam queryParam, boolean isOver, boolean isAdd) {
|
||||||
if (Objects.nonNull(queryParam.getDateInfo())) {
|
if (Objects.nonNull(queryParam.getDateInfo())) {
|
||||||
String addStr = isAdd ? "" : "-";
|
String addStr = isAdd ? "" : "-";
|
||||||
if (queryParam.getDateInfo().getPeriod().equalsIgnoreCase(Constants.DAY)) {
|
if (queryParam.getDateInfo().getPeriod().equals(DatePeriodEnum.DAY)) {
|
||||||
return isOver ? addStr + "7 day" : addStr + "1 day";
|
return isOver ? addStr + "7 day" : addStr + "1 day";
|
||||||
}
|
}
|
||||||
if (queryParam.getDateInfo().getPeriod().equalsIgnoreCase(Constants.WEEK)) {
|
if (queryParam.getDateInfo().getPeriod().equals(DatePeriodEnum.WEEK)) {
|
||||||
return isOver ? addStr + "1 month" : addStr + "7 day";
|
return isOver ? addStr + "1 month" : addStr + "7 day";
|
||||||
}
|
}
|
||||||
if (queryParam.getDateInfo().getPeriod().equalsIgnoreCase(Constants.MONTH)) {
|
if (queryParam.getDateInfo().getPeriod().equals(DatePeriodEnum.MONTH)) {
|
||||||
return isOver ? addStr + "1 year" : addStr + "1 month";
|
return isOver ? addStr + "1 year" : addStr + "1 month";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -438,7 +438,7 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
if (queryParam
|
if (queryParam
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.getPeriod()
|
.getPeriod()
|
||||||
.equals(Constants.MONTH)) {
|
.equals(DatePeriodEnum.MONTH)) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"%s = DATE_FORMAT(date_add(CONCAT(%s,'-01'), %s),'%%Y-%%m') ",
|
"%s = DATE_FORMAT(date_add(CONCAT(%s,'-01'), %s),'%%Y-%%m') ",
|
||||||
aliasLeft + timeDim,
|
aliasLeft + timeDim,
|
||||||
@@ -448,7 +448,7 @@ public class CalculateAggConverter implements QueryConverter {
|
|||||||
if (queryParam
|
if (queryParam
|
||||||
.getDateInfo()
|
.getDateInfo()
|
||||||
.getPeriod()
|
.getPeriod()
|
||||||
.equals(Constants.WEEK)
|
.equals(DatePeriodEnum.WEEK)
|
||||||
&& isOver) {
|
&& isOver) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"to_monday(date_add(%s ,INTERVAL %s) ) = %s",
|
"to_monday(date_add(%s ,INTERVAL %s) ) = %s",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.tencent.supersonic.headless.core.utils;
|
package com.tencent.supersonic.headless.core.utils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
import com.tencent.supersonic.common.pojo.enums.TimeDimensionEnum;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -66,9 +66,9 @@ public class DataTransformUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String getTimeDimension(DateConf dateConf) {
|
private static String getTimeDimension(DateConf dateConf) {
|
||||||
if (Constants.MONTH.equals(dateConf.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateConf.getPeriod())) {
|
||||||
return TimeDimensionEnum.MONTH.getName();
|
return TimeDimensionEnum.MONTH.getName();
|
||||||
} else if (Constants.WEEK.equals(dateConf.getPeriod())) {
|
} else if (DatePeriodEnum.WEEK.equals(dateConf.getPeriod())) {
|
||||||
return TimeDimensionEnum.WEEK.getName();
|
return TimeDimensionEnum.WEEK.getName();
|
||||||
} else {
|
} else {
|
||||||
return TimeDimensionEnum.DAY.getName();
|
return TimeDimensionEnum.DAY.getName();
|
||||||
|
|||||||
@@ -39,12 +39,9 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.JOIN_UNDERLINE;
|
import static com.tencent.supersonic.common.pojo.Constants.JOIN_UNDERLINE;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
|
import static com.tencent.supersonic.common.pojo.Constants.UNDERLINE;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
|
||||||
|
|
||||||
/** tools functions to analyze queryStructReq */
|
/** tools functions to analyze queryStructReq */
|
||||||
@Component
|
@Component
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
|||||||
TimeDefaultConfig timeDefaultConfig = dataSetSchema.getTagTypeTimeDefaultConfig();
|
TimeDefaultConfig timeDefaultConfig = dataSetSchema.getTagTypeTimeDefaultConfig();
|
||||||
if (Objects.nonNull(timeDefaultConfig)) {
|
if (Objects.nonNull(timeDefaultConfig)) {
|
||||||
unit = timeDefaultConfig.getUnit();
|
unit = timeDefaultConfig.getUnit();
|
||||||
String date = LocalDate.now().plusDays(-unit).toString();
|
String date = LocalDate.now().minusDays(unit).toString();
|
||||||
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
dateInfo.setDateMode(DateConf.DateMode.BETWEEN);
|
||||||
dateInfo.setStartDate(date);
|
dateInfo.setStartDate(date);
|
||||||
dateInfo.setEndDate(date);
|
dateInfo.setEndDate(date);
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import com.alibaba.excel.write.metadata.WriteSheet;
|
|||||||
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.common.pojo.Aggregator;
|
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||||
import com.tencent.supersonic.common.pojo.Constants;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
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.headless.api.pojo.DrillDownDimension;
|
import com.tencent.supersonic.headless.api.pojo.DrillDownDimension;
|
||||||
@@ -298,9 +298,9 @@ public class DownloadServiceImpl implements DownloadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getTimeDimension(DateConf dateConf) {
|
private String getTimeDimension(DateConf dateConf) {
|
||||||
if (Constants.MONTH.equals(dateConf.getPeriod())) {
|
if (DatePeriodEnum.MONTH.equals(dateConf.getPeriod())) {
|
||||||
return TimeDimensionEnum.MONTH.getName();
|
return TimeDimensionEnum.MONTH.getName();
|
||||||
} else if (Constants.WEEK.equals(dateConf.getPeriod())) {
|
} else if (DatePeriodEnum.WEEK.equals(dateConf.getPeriod())) {
|
||||||
return TimeDimensionEnum.WEEK.getName();
|
return TimeDimensionEnum.WEEK.getName();
|
||||||
} else {
|
} else {
|
||||||
return TimeDimensionEnum.DAY.getName();
|
return TimeDimensionEnum.DAY.getName();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.tencent.supersonic.common.pojo.Aggregator;
|
|||||||
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.ItemDateResp;
|
import com.tencent.supersonic.common.pojo.ItemDateResp;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
||||||
import com.tencent.supersonic.common.util.DateModeUtils;
|
import com.tencent.supersonic.common.util.DateModeUtils;
|
||||||
import com.tencent.supersonic.common.util.SqlFilterUtils;
|
import com.tencent.supersonic.common.util.SqlFilterUtils;
|
||||||
@@ -40,10 +41,7 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -236,7 +234,7 @@ public class QueryStructUtils {
|
|||||||
Set<String> dateList = new HashSet<>();
|
Set<String> dateList = new HashSet<>();
|
||||||
String startDate = "";
|
String startDate = "";
|
||||||
String endDate = "";
|
String endDate = "";
|
||||||
String period = "";
|
DatePeriodEnum period = null;
|
||||||
for (FieldExpression f : fieldExpressions) {
|
for (FieldExpression f : fieldExpressions) {
|
||||||
if (Objects.isNull(f.getFieldName())
|
if (Objects.isNull(f.getFieldName())
|
||||||
|| !internalCols.contains(f.getFieldName().toLowerCase())) {
|
|| !internalCols.contains(f.getFieldName().toLowerCase())) {
|
||||||
@@ -247,7 +245,7 @@ public class QueryStructUtils {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
period = dateModeUtils.getPeriodByCol(f.getFieldName().toLowerCase());
|
period = dateModeUtils.getPeriodByCol(f.getFieldName().toLowerCase());
|
||||||
if ("".equals(period)) {
|
if (period == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ("=".equals(f.getOperator())) {
|
if ("=".equals(f.getOperator())) {
|
||||||
@@ -263,7 +261,7 @@ public class QueryStructUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!"".equals(period)) {
|
if (period != null) {
|
||||||
DateConf dateConf = new DateConf();
|
DateConf dateConf = new DateConf();
|
||||||
dateConf.setPeriod(period);
|
dateConf.setPeriod(period);
|
||||||
if (!CollectionUtils.isEmpty(dateList)) {
|
if (!CollectionUtils.isEmpty(dateList)) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
import com.tencent.supersonic.chat.server.service.AgentService;
|
||||||
import com.tencent.supersonic.chat.server.service.ChatQueryService;
|
import com.tencent.supersonic.chat.server.service.ChatQueryService;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||||
@@ -22,9 +23,9 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class BaseTest extends BaseApplication {
|
public class BaseTest extends BaseApplication {
|
||||||
|
|
||||||
protected final int unit = 7;
|
protected final int unit = 7;
|
||||||
protected final String startDay = LocalDate.now().plusDays(-unit).toString();
|
protected final String startDay = LocalDate.now().minusDays(unit).toString();
|
||||||
protected final String endDay = LocalDate.now().plusDays(-1).toString();
|
protected final String endDay = LocalDate.now().toString();
|
||||||
protected final String period = "DAY";
|
protected final DatePeriodEnum period = DatePeriodEnum.DAY;
|
||||||
|
|
||||||
@Autowired protected ChatQueryService chatQueryService;
|
@Autowired protected ChatQueryService chatQueryService;
|
||||||
@Autowired protected AgentService agentService;
|
@Autowired protected AgentService agentService;
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package com.tencent.supersonic.chat;
|
|||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResult;
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
import com.tencent.supersonic.common.pojo.enums.QueryType;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
||||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricFilterQuery;
|
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricFilterQuery;
|
||||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricGroupByQuery;
|
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricGroupByQuery;
|
||||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricModelQuery;
|
|
||||||
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricTopNQuery;
|
import com.tencent.supersonic.headless.chat.query.rule.metric.MetricTopNQuery;
|
||||||
import com.tencent.supersonic.util.DataUtils;
|
import com.tencent.supersonic.util.DataUtils;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
@@ -45,25 +45,7 @@ public class MetricTest extends BaseTest {
|
|||||||
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testMetricDomain() throws Exception {
|
|
||||||
QueryResult actualResult = submitNewChat("超音数总访问次数", DataUtils.metricAgentId);
|
|
||||||
|
|
||||||
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);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
@@ -84,7 +66,8 @@ public class MetricTest extends BaseTest {
|
|||||||
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("部门"));
|
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("部门"));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(
|
||||||
|
DateConf.DateMode.BETWEEN, 7, DatePeriodEnum.DAY, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
@@ -110,7 +93,7 @@ public class MetricTest extends BaseTest {
|
|||||||
expectedParseInfo.getDimensionFilters().add(dimensionFilter);
|
expectedParseInfo.getDimensionFilters().add(dimensionFilter);
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
@@ -131,7 +114,8 @@ public class MetricTest extends BaseTest {
|
|||||||
expectedParseInfo.getMetrics().add(DataUtils.getSchemaElement("访问次数"));
|
expectedParseInfo.getMetrics().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.BETWEEN, DatePeriodEnum.DAY));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
@@ -151,7 +135,7 @@ public class MetricTest extends BaseTest {
|
|||||||
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("部门"));
|
expectedParseInfo.getDimensions().add(DataUtils.getSchemaElement("部门"));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class MultiTurnsTest extends BaseTest {
|
|||||||
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
@@ -66,7 +66,7 @@ public class MultiTurnsTest extends BaseTest {
|
|||||||
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
"user_name", FilterOperatorEnum.EQUALS, "alice", "用户", 2L));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
@@ -93,7 +93,7 @@ public class MultiTurnsTest extends BaseTest {
|
|||||||
.add(DataUtils.getFilter("user_name", FilterOperatorEnum.EQUALS, "lucy", "用户", 2L));
|
.add(DataUtils.getFilter("user_name", FilterOperatorEnum.EQUALS, "lucy", "用户", 2L));
|
||||||
|
|
||||||
expectedParseInfo.setDateInfo(
|
expectedParseInfo.setDateInfo(
|
||||||
DataUtils.getDateConf(DateConf.DateMode.RECENT, unit, period, startDay, endDay));
|
DataUtils.getDateConf(DateConf.DateMode.BETWEEN, unit, period, startDay, endDay));
|
||||||
expectedParseInfo.setQueryType(QueryType.METRIC);
|
expectedParseInfo.setQueryType(QueryType.METRIC);
|
||||||
|
|
||||||
assertQueryResult(expectedResult, actualResult);
|
assertQueryResult(expectedResult, actualResult);
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
package com.tencent.supersonic.util;
|
package com.tencent.supersonic.util;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
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.request.ChatParseReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
|
||||||
import com.tencent.supersonic.chat.server.agent.AgentConfig;
|
|
||||||
import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
|
||||||
import com.tencent.supersonic.chat.server.agent.PluginTool;
|
|
||||||
import com.tencent.supersonic.chat.server.agent.RuleParserTool;
|
|
||||||
import com.tencent.supersonic.common.pojo.DateConf;
|
import com.tencent.supersonic.common.pojo.DateConf;
|
||||||
|
import com.tencent.supersonic.common.pojo.enums.DatePeriodEnum;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
import com.tencent.supersonic.headless.api.pojo.request.QueryFilter;
|
||||||
@@ -51,15 +45,6 @@ public class DataUtils {
|
|||||||
return chatParseReq;
|
return chatParseReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatParseReq getChatParseReqWithAgent(Integer id, String query, Integer agentId) {
|
|
||||||
ChatParseReq queryReq = new ChatParseReq();
|
|
||||||
queryReq.setQueryText(query);
|
|
||||||
queryReq.setChatId(id);
|
|
||||||
queryReq.setUser(user_test);
|
|
||||||
queryReq.setAgentId(agentId);
|
|
||||||
return queryReq;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SchemaElement getSchemaElement(String name) {
|
public static SchemaElement getSchemaElement(String name) {
|
||||||
return SchemaElement.builder().name(name).build();
|
return SchemaElement.builder().name(name).build();
|
||||||
}
|
}
|
||||||
@@ -79,20 +64,21 @@ public class DataUtils {
|
|||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateConf getDateConf(Integer unit, DateConf.DateMode dateMode, String period) {
|
public static DateConf getDateConf(
|
||||||
|
Integer unit, DateConf.DateMode dateMode, DatePeriodEnum period) {
|
||||||
DateConf dateInfo = new DateConf();
|
DateConf dateInfo = new DateConf();
|
||||||
dateInfo.setUnit(unit);
|
dateInfo.setUnit(unit);
|
||||||
dateInfo.setDateMode(dateMode);
|
dateInfo.setDateMode(dateMode);
|
||||||
dateInfo.setPeriod(period);
|
dateInfo.setPeriod(period);
|
||||||
dateInfo.setStartDate(now().plusDays(-unit).toString());
|
dateInfo.setStartDate(now().minusDays(unit).toString());
|
||||||
dateInfo.setEndDate(now().plusDays(-1).toString());
|
dateInfo.setEndDate(now().toString());
|
||||||
return dateInfo;
|
return dateInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateConf getDateConf(
|
public static DateConf getDateConf(
|
||||||
DateConf.DateMode dateMode,
|
DateConf.DateMode dateMode,
|
||||||
Integer unit,
|
Integer unit,
|
||||||
String period,
|
DatePeriodEnum period,
|
||||||
String startDate,
|
String startDate,
|
||||||
String endDate) {
|
String endDate) {
|
||||||
DateConf dateInfo = new DateConf();
|
DateConf dateInfo = new DateConf();
|
||||||
@@ -104,69 +90,6 @@ public class DataUtils {
|
|||||||
return dateInfo;
|
return dateInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateConf getDateConf(
|
|
||||||
DateConf.DateMode dateMode, String startDate, String endDate) {
|
|
||||||
DateConf dateInfo = new DateConf();
|
|
||||||
dateInfo.setDateMode(dateMode);
|
|
||||||
dateInfo.setStartDate(startDate);
|
|
||||||
dateInfo.setEndDate(endDate);
|
|
||||||
return dateInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DateConf getDateConf(
|
|
||||||
DateConf.DateMode dateMode, String startDate, String endDate, int unit) {
|
|
||||||
DateConf dateInfo = new DateConf();
|
|
||||||
dateInfo.setDateMode(dateMode);
|
|
||||||
dateInfo.setStartDate(startDate);
|
|
||||||
dateInfo.setEndDate(endDate);
|
|
||||||
dateInfo.setUnit(unit);
|
|
||||||
return dateInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Agent getMetricAgent() {
|
|
||||||
Agent agent = new Agent();
|
|
||||||
agent.setId(1);
|
|
||||||
agent.setName("查信息");
|
|
||||||
agent.setDescription("查信息");
|
|
||||||
AgentConfig agentConfig = new AgentConfig();
|
|
||||||
agentConfig.getTools().add(getRuleQueryTool());
|
|
||||||
agent.setAgentConfig(JSONObject.toJSONString(agentConfig));
|
|
||||||
return agent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Agent getTagAgent() {
|
|
||||||
Agent agent = new Agent();
|
|
||||||
agent.setId(2);
|
|
||||||
agent.setName("标签圈选");
|
|
||||||
agent.setDescription("标签圈选");
|
|
||||||
AgentConfig agentConfig = new AgentConfig();
|
|
||||||
agentConfig.getTools().add(getRuleQueryTool());
|
|
||||||
agent.setAgentConfig(JSONObject.toJSONString(agentConfig));
|
|
||||||
return agent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static RuleParserTool getRuleQueryTool() {
|
|
||||||
RuleParserTool ruleQueryTool = new RuleParserTool();
|
|
||||||
ruleQueryTool.setType(AgentToolType.NL2SQL_RULE);
|
|
||||||
ruleQueryTool.setDataSetIds(Lists.newArrayList(-1L));
|
|
||||||
ruleQueryTool.setQueryModes(
|
|
||||||
Lists.newArrayList(
|
|
||||||
"METRIC_ID",
|
|
||||||
"METRIC_FILTER",
|
|
||||||
"METRIC_MODEL",
|
|
||||||
"TAG_DETAIL",
|
|
||||||
"TAG_LIST_FILTER",
|
|
||||||
"TAG_ID"));
|
|
||||||
return ruleQueryTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PluginTool getPluginTool() {
|
|
||||||
PluginTool pluginTool = new PluginTool();
|
|
||||||
pluginTool.setType(AgentToolType.PLUGIN);
|
|
||||||
pluginTool.setPlugins(Lists.newArrayList(1L));
|
|
||||||
return pluginTool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<Long> getMetricAgentIModelIds() {
|
public static Set<Long> getMetricAgentIModelIds() {
|
||||||
Set<Long> result = new HashSet<>();
|
Set<Long> result = new HashSet<>();
|
||||||
result.add(1L);
|
result.add(1L);
|
||||||
|
|||||||
Reference in New Issue
Block a user