mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 22:25:19 +00:00
[improvement][project] global refactor , code format , support llm , support fuzzy detect ,support query filter and so on.
This commit is contained in:
@@ -3,15 +3,7 @@ package com.tencent.supersonic.semantic.api.core.enums;
|
||||
|
||||
public enum MetricTypeEnum {
|
||||
|
||||
EXPR("expr");
|
||||
ATOMIC,
|
||||
DERIVED
|
||||
|
||||
private String name;
|
||||
|
||||
MetricTypeEnum(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ public enum OperatorEnum {
|
||||
UNKNOWN("UNKNOWN");
|
||||
|
||||
|
||||
private String operator;
|
||||
|
||||
OperatorEnum(String operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
private String operator;
|
||||
|
||||
public String getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
@@ -14,14 +14,6 @@ public enum QueryTypeBackEnum {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Integer getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public static QueryTypeBackEnum of(String src) {
|
||||
for (QueryTypeBackEnum operatorEnum : QueryTypeBackEnum.values()) {
|
||||
if (src.toUpperCase().contains(operatorEnum.value)) {
|
||||
@@ -31,5 +23,13 @@ public enum QueryTypeBackEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Integer getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,6 @@ public enum QueryTypeEnum {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static QueryTypeEnum of(String src) {
|
||||
for (QueryTypeEnum operatorEnum : QueryTypeEnum.values()) {
|
||||
if (src.toUpperCase().contains(operatorEnum.value)) {
|
||||
@@ -25,5 +21,9 @@ public enum QueryTypeEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ public enum TimeDimensionEnum {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static List<String> getNameList() {
|
||||
return Arrays.stream(TimeDimensionEnum.values()).map(TimeDimensionEnum::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.tencent.supersonic.semantic.api.core.pojo;
|
||||
|
||||
import java.util.List;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MetricTypeParams {
|
||||
|
||||
private List<Measure> measures;
|
||||
private List<Measure> measures = Lists.newArrayList();
|
||||
|
||||
private String expr;
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ public class QueryColumn {
|
||||
private String showType;
|
||||
private Boolean authorized = true;
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type == null ? null : type;
|
||||
}
|
||||
|
||||
public QueryColumn(String nameEn, String type) {
|
||||
this.type = type;
|
||||
this.nameEn = nameEn;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type == null ? null : type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tencent.supersonic.semantic.api.core.request;
|
||||
|
||||
import com.tencent.supersonic.semantic.api.core.enums.DataTypeEnum;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -7,7 +8,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
@Data
|
||||
public class DatabaseReq {
|
||||
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long domainId;
|
||||
@@ -34,6 +34,10 @@ public class DatabaseReq {
|
||||
if (StringUtils.isNotBlank(url)) {
|
||||
return url;
|
||||
}
|
||||
if (type.equalsIgnoreCase(DataTypeEnum.MYSQL.getFeature())) {
|
||||
return String.format("jdbc:%s://%s:%s?sessionVariables=sql_mode='IGNORE_SPACE'&allowMultiQueries=true",
|
||||
type, host, port);
|
||||
}
|
||||
return String.format("jdbc:%s://%s:%s", type, host, port);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class DatasourceReq extends SchemaItem {
|
||||
|
||||
private String sqlQuery;
|
||||
|
||||
private String sqlTable;
|
||||
private String tableQuery;
|
||||
|
||||
private Long domainId;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.semantic.api.core.request;
|
||||
import com.tencent.supersonic.common.pojo.SchemaItem;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DimensionReq extends SchemaItem {
|
||||
@@ -20,5 +21,9 @@ public class DimensionReq extends SchemaItem {
|
||||
//DATE ID CATEGORY
|
||||
private String semanticType = "CATEGORY";
|
||||
|
||||
private String alias;
|
||||
|
||||
private List<String> defaultValues;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,4 +10,6 @@ public class MetricBaseReq extends SchemaItem {
|
||||
|
||||
private Long domainId;
|
||||
|
||||
private String alias;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,31 @@
|
||||
package com.tencent.supersonic.semantic.api.core.request;
|
||||
|
||||
|
||||
import com.tencent.supersonic.semantic.api.core.enums.MetricTypeEnum;
|
||||
import com.tencent.supersonic.semantic.api.core.pojo.Measure;
|
||||
import com.tencent.supersonic.semantic.api.core.pojo.MetricTypeParams;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MetricReq extends MetricBaseReq {
|
||||
|
||||
private MetricTypeEnum metricType;
|
||||
|
||||
private MetricTypeParams typeParams;
|
||||
|
||||
public MetricTypeEnum getMetricType() {
|
||||
if (metricType != null) {
|
||||
return metricType;
|
||||
}
|
||||
List<Measure> measureList = typeParams.getMeasures();
|
||||
if (measureList.size() > 1) {
|
||||
return MetricTypeEnum.DERIVED;
|
||||
}
|
||||
if (measureList.size() == 1 && typeParams.getExpr().trim().equalsIgnoreCase(measureList.get(0).getBizName())) {
|
||||
return MetricTypeEnum.ATOMIC;
|
||||
}
|
||||
throw new RuntimeException("measure can not be none");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.semantic.api.core.response;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.SchemaItem;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@@ -24,5 +25,9 @@ public class DimensionResp extends SchemaItem {
|
||||
//DATE ID CATEGORY
|
||||
private String semanticType;
|
||||
|
||||
private String alias;
|
||||
|
||||
private List<String> defaultValues;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,5 +23,9 @@ public class DomainResp extends SchemaItem {
|
||||
|
||||
private Integer isOpen = 0;
|
||||
|
||||
private Integer dimensionCnt;
|
||||
|
||||
private Integer metricCnt;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,16 +14,18 @@ public class MetricResp extends SchemaItem {
|
||||
|
||||
private String domainName;
|
||||
|
||||
//measure_proxy ratio expr cumulative derived
|
||||
//ATOMIC DERIVED
|
||||
private String type;
|
||||
|
||||
private MetricTypeParams typeParams;
|
||||
|
||||
private String fullPath;
|
||||
|
||||
|
||||
private String dataFormatType;
|
||||
|
||||
private DataFormat dataFormat;
|
||||
|
||||
private String alias;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,6 @@ public enum FilterOperatorEnum {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static FilterOperatorEnum getSqlOperator(String type) {
|
||||
for (FilterOperatorEnum operatorEnum : FilterOperatorEnum.values()) {
|
||||
@@ -41,5 +36,10 @@ public enum FilterOperatorEnum {
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,26 @@ public class Criterion {
|
||||
|
||||
private String dataType;
|
||||
|
||||
public Criterion(String column, FilterOperatorEnum operator, Object value, String dataType) {
|
||||
super();
|
||||
this.column = column;
|
||||
this.operator = operator;
|
||||
this.value = value;
|
||||
this.dataType = dataType;
|
||||
|
||||
if (FilterOperatorEnum.BETWEEN.name().equals(operator) || FilterOperatorEnum.IN.name().equals(operator)
|
||||
|| FilterOperatorEnum.NOT_IN.name().equals(operator)) {
|
||||
this.values = (List) value;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNeedApostrophe() {
|
||||
return Arrays.stream(StringDataType.values())
|
||||
.filter(value -> this.dataType.equalsIgnoreCase(value.getType())).findFirst()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
|
||||
public enum NumericDataType {
|
||||
TINYINT("TINYINT"),
|
||||
SMALLINT("SMALLINT"),
|
||||
@@ -43,6 +63,7 @@ public class Criterion {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum StringDataType {
|
||||
VARCHAR("VARCHAR"),
|
||||
STRING("STRING"),
|
||||
@@ -59,25 +80,4 @@ public class Criterion {
|
||||
}
|
||||
|
||||
|
||||
public Criterion(String column, FilterOperatorEnum operator, Object value, String dataType) {
|
||||
super();
|
||||
this.column = column;
|
||||
this.operator = operator;
|
||||
this.value = value;
|
||||
this.dataType = dataType;
|
||||
|
||||
if (FilterOperatorEnum.BETWEEN.name().equals(operator) || FilterOperatorEnum.IN.name().equals(operator)
|
||||
|| FilterOperatorEnum.NOT_IN.name().equals(operator)) {
|
||||
this.values = (List) value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isNeedApostrophe() {
|
||||
return Arrays.stream(StringDataType.values())
|
||||
.filter(value -> this.dataType.equalsIgnoreCase(value.getType())).findFirst()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,19 +13,11 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class Filter {
|
||||
|
||||
public enum Relation {
|
||||
FILTER, OR, AND
|
||||
}
|
||||
|
||||
private Relation relation = Relation.FILTER;
|
||||
private String bizName;
|
||||
|
||||
private String name;
|
||||
|
||||
private FilterOperatorEnum operator;
|
||||
|
||||
private Object value;
|
||||
|
||||
private List<Filter> children;
|
||||
|
||||
public Filter(String bizName, FilterOperatorEnum operator, Object value) {
|
||||
@@ -34,7 +26,6 @@ public class Filter {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
public Filter(Relation relation, String bizName, FilterOperatorEnum operator, Object value) {
|
||||
this.relation = relation;
|
||||
this.bizName = bizName;
|
||||
@@ -60,4 +51,8 @@ public class Filter {
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public enum Relation {
|
||||
FILTER, OR, AND
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user