mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(improvement)(headless) (improvement)(headless) Supports creating new metric by fields and metrics and convert struct to sql (#654)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class Field {
|
||||
|
||||
private String fieldName;
|
||||
|
||||
private String dataType;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ public class Measure {
|
||||
|
||||
private String expr;
|
||||
|
||||
private String createMetric;
|
||||
|
||||
private String bizName;
|
||||
|
||||
private Integer isCreateMetric = 0;
|
||||
|
||||
@@ -7,4 +7,6 @@ public abstract class MetricDefineParams {
|
||||
|
||||
private String expr;
|
||||
|
||||
private String filterSql;
|
||||
|
||||
}
|
||||
|
||||
@@ -43,4 +43,28 @@ public class ModelDetail {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Field> getFields() {
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
return fields;
|
||||
}
|
||||
List<Field> fieldList = Lists.newArrayList();
|
||||
//Compatible with older versions
|
||||
if (!CollectionUtils.isEmpty(identifiers)) {
|
||||
fieldList.addAll(identifiers.stream()
|
||||
.map(identify -> Field.builder().fieldName(identify.getFieldName()).build())
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dimensions)) {
|
||||
fieldList.addAll(dimensions.stream()
|
||||
.map(dim -> Field.builder().fieldName(dim.getFieldName()).build())
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(measures)) {
|
||||
fieldList.addAll(measures.stream()
|
||||
.map(measure -> Field.builder().fieldName(measure.getFieldName()).build())
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.tencent.supersonic.headless.api.request;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FieldRemovedReq {
|
||||
|
||||
private Long modelId;
|
||||
|
||||
private List<String> fields;
|
||||
|
||||
}
|
||||
@@ -12,23 +12,24 @@ import lombok.Data;
|
||||
public class MetricReq extends MetricBaseReq {
|
||||
|
||||
private MetricDefineType metricDefineType = MetricDefineType.MEASURE;
|
||||
private MetricDefineByMeasureParams typeParams;
|
||||
private MetricDefineByMeasureParams metricDefineByMeasureParams;
|
||||
private MetricDefineByFieldParams metricDefineByFieldParams;
|
||||
private MetricDefineByMetricParams metricDefineByMetricParams;
|
||||
|
||||
public String getTypeParamsJson() {
|
||||
if (metricDefineByFieldParams != null) {
|
||||
if (MetricDefineType.FIELD.equals(metricDefineType) && metricDefineByFieldParams != null) {
|
||||
return JSONObject.toJSONString(metricDefineByFieldParams);
|
||||
} else if (typeParams != null) {
|
||||
return JSONObject.toJSONString(typeParams);
|
||||
} else if (metricDefineByMetricParams != null) {
|
||||
} else if (MetricDefineType.MEASURE.equals(metricDefineType) && metricDefineByMeasureParams != null) {
|
||||
return JSONObject.toJSONString(metricDefineByMeasureParams);
|
||||
} else if (MetricDefineType.METRIC.equals(metricDefineType) && metricDefineByMetricParams != null) {
|
||||
return JSONObject.toJSONString(metricDefineByMetricParams);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MetricType getMetricType() {
|
||||
return MetricType.isDerived(metricDefineType, typeParams) ? MetricType.DERIVED : MetricType.ATOMIC;
|
||||
return MetricType.isDerived(metricDefineType, metricDefineByMeasureParams)
|
||||
? MetricType.DERIVED : MetricType.ATOMIC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,6 @@ import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.common.util.DateModeUtils;
|
||||
import com.tencent.supersonic.common.util.SqlFilterUtils;
|
||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserAddHelper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
@@ -39,6 +35,11 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@@ -266,4 +267,11 @@ public class QueryStructReq extends SemanticQueryReq {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public String getModelName() {
|
||||
if (StringUtils.isNotBlank(modelName)) {
|
||||
return modelName;
|
||||
}
|
||||
return "table";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,15 +10,16 @@ import com.tencent.supersonic.headless.api.pojo.MetricDefineByMeasureParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricDefineByMetricParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.RelateDimension;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaItem;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
@Data
|
||||
@@ -52,7 +53,7 @@ public class MetricResp extends SchemaItem {
|
||||
|
||||
private MetricDefineType metricDefineType = MetricDefineType.MEASURE;
|
||||
|
||||
private MetricDefineByMeasureParams typeParams;
|
||||
private MetricDefineByMeasureParams metricDefineByMeasureParams;
|
||||
|
||||
private MetricDefineByFieldParams metricDefineByFieldParams;
|
||||
|
||||
@@ -77,9 +78,20 @@ public class MetricResp extends SchemaItem {
|
||||
}
|
||||
|
||||
public String getDefaultAgg() {
|
||||
if (typeParams != null
|
||||
&& CollectionUtils.isNotEmpty(typeParams.getMeasures())) {
|
||||
return typeParams.getMeasures().get(0).getAgg();
|
||||
if (metricDefineByMeasureParams != null
|
||||
&& CollectionUtils.isNotEmpty(metricDefineByMeasureParams.getMeasures())) {
|
||||
return metricDefineByMeasureParams.getMeasures().get(0).getAgg();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getExpr() {
|
||||
if (MetricDefineType.MEASURE.equals(metricDefineType)) {
|
||||
return metricDefineByMeasureParams.getExpr();
|
||||
} else if (MetricDefineType.METRIC.equals(metricDefineType)) {
|
||||
return metricDefineByMetricParams.getExpr();
|
||||
} else if (MetricDefineType.FIELD.equals(metricDefineType)) {
|
||||
return metricDefineByFieldParams.getExpr();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.tencent.supersonic.headless.api.response;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class UnAvailableItemResp {
|
||||
|
||||
private List<MetricResp> metricResps;
|
||||
|
||||
private List<DimensionResp> dimensionResps;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user