mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(improvement)(headless) Supports creating new metric by fields and metrics (#639)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package com.tencent.supersonic.headless.api.enums;
|
||||
|
||||
public enum MetricDefineType {
|
||||
|
||||
FIELD,
|
||||
MEASURE,
|
||||
METRIC
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Field {
|
||||
|
||||
private String fieldName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FieldParam {
|
||||
|
||||
private String fieldName;
|
||||
|
||||
}
|
||||
@@ -32,6 +32,11 @@ public class Measure {
|
||||
this.bizName = bizName;
|
||||
}
|
||||
|
||||
public Measure(String bizName, String constraint) {
|
||||
this.bizName = bizName;
|
||||
this.constraint = constraint;
|
||||
}
|
||||
|
||||
public String getFieldName() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MeasureParam {
|
||||
|
||||
private String bizName;
|
||||
|
||||
private String constraint;
|
||||
|
||||
private String agg;
|
||||
|
||||
public MeasureParam(String bizName, String constraint) {
|
||||
this.bizName = bizName;
|
||||
this.constraint = constraint;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import java.util.List;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MetricTypeParams {
|
||||
public class MetricDefineByFieldParams extends MetricDefineParams {
|
||||
|
||||
private List<Measure> measures = Lists.newArrayList();
|
||||
|
||||
private String expr;
|
||||
private List<FieldParam> fields = Lists.newArrayList();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MetricDefineByMeasureParams extends MetricDefineParams {
|
||||
|
||||
private List<MeasureParam> measures = Lists.newArrayList();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MetricDefineByMetricParams extends MetricDefineParams {
|
||||
|
||||
private List<MetricParam> metrics = Lists.newArrayList();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public abstract class MetricDefineParams {
|
||||
|
||||
private String expr;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MetricParam {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String bizName;
|
||||
|
||||
}
|
||||
@@ -25,6 +25,8 @@ public class ModelDetail {
|
||||
|
||||
private List<Measure> measures;
|
||||
|
||||
private List<Field> fields;
|
||||
|
||||
public String getSqlQuery() {
|
||||
if (StringUtils.isNotBlank(sqlQuery) && sqlQuery.endsWith(";")) {
|
||||
sqlQuery = sqlQuery.substring(0, sqlQuery.length() - 1);
|
||||
@@ -32,7 +34,7 @@ public class ModelDetail {
|
||||
return sqlQuery;
|
||||
}
|
||||
|
||||
public List<Dim> getTimeDims() {
|
||||
public List<Dim> filterTimeDims() {
|
||||
if (CollectionUtils.isEmpty(dimensions)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import com.google.common.base.Objects;
|
||||
import com.tencent.supersonic.common.pojo.RecordInfo;
|
||||
import com.tencent.supersonic.common.pojo.enums.SensitiveLevelEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class SchemaItem extends RecordInfo {
|
||||
@@ -38,9 +39,6 @@ public class SchemaItem extends RecordInfo {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
SchemaItem that = (SchemaItem) o;
|
||||
return Objects.equal(id, that.id) && Objects.equal(name, that.name)
|
||||
&& Objects.equal(bizName, that.bizName) && Objects.equal(
|
||||
@@ -50,7 +48,7 @@ public class SchemaItem extends RecordInfo {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), id, name, bizName, description, status, typeEnum, sensitiveLevel);
|
||||
return Objects.hashCode(id, name, bizName, description, status, typeEnum, sensitiveLevel);
|
||||
}
|
||||
|
||||
public static List<String> getAliasList(String alias) {
|
||||
|
||||
@@ -30,6 +30,9 @@ public class MetricBaseReq extends SchemaItem {
|
||||
private Map<String, Object> ext = new HashMap<>();
|
||||
|
||||
public String getTag() {
|
||||
if (tags == null) {
|
||||
return null;
|
||||
}
|
||||
if (CollectionUtils.isEmpty(tags)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1,30 +1,49 @@
|
||||
package com.tencent.supersonic.headless.api.request;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tencent.supersonic.headless.api.enums.MetricDefineType;
|
||||
import com.tencent.supersonic.headless.api.enums.MetricType;
|
||||
import com.tencent.supersonic.headless.api.pojo.Measure;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricTypeParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.MeasureParam;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricDefineByFieldParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricDefineByMeasureParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricDefineByMetricParams;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MetricReq extends MetricBaseReq {
|
||||
|
||||
private MetricType metricType;
|
||||
private MetricDefineType metricDefineType = MetricDefineType.MEASURE;
|
||||
private MetricDefineByMeasureParams typeParams;
|
||||
private MetricDefineByFieldParams metricDefineByFieldParams;
|
||||
private MetricDefineByMetricParams metricDefineByMetricParams;
|
||||
|
||||
private MetricTypeParams typeParams;
|
||||
public String getTypeParamsJson() {
|
||||
if (metricDefineByFieldParams != null) {
|
||||
return JSONObject.toJSONString(metricDefineByFieldParams);
|
||||
} else if (typeParams != null) {
|
||||
return JSONObject.toJSONString(typeParams);
|
||||
} else if (metricDefineByMetricParams != null) {
|
||||
return JSONObject.toJSONString(metricDefineByMetricParams);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MetricType getMetricType() {
|
||||
if (metricType != null) {
|
||||
return metricType;
|
||||
}
|
||||
List<Measure> measureList = typeParams.getMeasures();
|
||||
if (measureList.size() == 1 && typeParams.getExpr().trim().equalsIgnoreCase(measureList.get(0).getBizName())) {
|
||||
return MetricType.ATOMIC;
|
||||
} else if (measureList.size() >= 1) {
|
||||
if (MetricDefineType.METRIC.equals(metricDefineType)) {
|
||||
return MetricType.DERIVED;
|
||||
}
|
||||
throw new RuntimeException("measure can not be none");
|
||||
if (MetricDefineType.MEASURE.equals(metricDefineType)) {
|
||||
List<MeasureParam> measures = typeParams.getMeasures();
|
||||
if (measures.size() > 1) {
|
||||
return MetricType.DERIVED;
|
||||
}
|
||||
if (measures.size() == 1 && measures.get(0).getBizName()
|
||||
.equalsIgnoreCase(typeParams.getExpr())) {
|
||||
return MetricType.ATOMIC;
|
||||
}
|
||||
}
|
||||
return MetricType.ATOMIC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ModelReq extends SchemaItem {
|
||||
if (modelDetail == null) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
return modelDetail.getTimeDims();
|
||||
return modelDetail.filterTimeDims();
|
||||
}
|
||||
|
||||
public String getViewer() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.tencent.supersonic.headless.api.response;
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.Entity;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaItem;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
@@ -26,12 +25,6 @@ public class DomainResp extends SchemaItem {
|
||||
|
||||
private Integer isOpen = 0;
|
||||
|
||||
private Integer dimensionCnt;
|
||||
|
||||
private Integer metricCnt;
|
||||
|
||||
private Entity entity;
|
||||
|
||||
private boolean hasEditPermission = false;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,21 +2,23 @@ package com.tencent.supersonic.headless.api.response;
|
||||
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.tencent.supersonic.common.pojo.DataFormat;
|
||||
import com.tencent.supersonic.headless.api.enums.MetricDefineType;
|
||||
import com.tencent.supersonic.headless.api.pojo.DrillDownDimension;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricTypeParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetricDefineByFieldParams;
|
||||
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.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -33,8 +35,6 @@ public class MetricResp extends SchemaItem {
|
||||
//ATOMIC DERIVED
|
||||
private String type;
|
||||
|
||||
private MetricTypeParams typeParams;
|
||||
|
||||
private String dataFormatType;
|
||||
|
||||
private DataFormat dataFormat;
|
||||
@@ -51,6 +51,14 @@ public class MetricResp extends SchemaItem {
|
||||
|
||||
private Map<String, Object> ext = new HashMap<>();
|
||||
|
||||
private MetricDefineType metricDefineType = MetricDefineType.MEASURE;
|
||||
|
||||
private MetricDefineByMeasureParams typeParams;
|
||||
|
||||
private MetricDefineByFieldParams metricDefineByFieldParams;
|
||||
|
||||
private MetricDefineByMetricParams metricDefineByMetricParams;
|
||||
|
||||
public void setTag(String tag) {
|
||||
if (StringUtils.isBlank(tag)) {
|
||||
tags = Lists.newArrayList();
|
||||
@@ -59,14 +67,6 @@ public class MetricResp extends SchemaItem {
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Long> getNecessaryDimensionIds() {
|
||||
if (relateDimension == null || CollectionUtils.isEmpty(relateDimension.getDrillDownDimensions())) {
|
||||
return Sets.newHashSet();
|
||||
}
|
||||
return relateDimension.getDrillDownDimensions().stream().filter(DrillDownDimension::isNecessary)
|
||||
.map(DrillDownDimension::getDimensionId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public String getRelaDimensionIdKey() {
|
||||
if (relateDimension == null || CollectionUtils.isEmpty(relateDimension.getDrillDownDimensions())) {
|
||||
return "";
|
||||
@@ -78,6 +78,11 @@ public class MetricResp extends SchemaItem {
|
||||
}
|
||||
|
||||
public String getDefaultAgg() {
|
||||
return typeParams.getMeasures().get(0).getAgg();
|
||||
if (typeParams != null
|
||||
&& CollectionUtils.isNotEmpty(typeParams.getMeasures())) {
|
||||
return typeParams.getMeasures().get(0).getAgg();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,22 @@ package com.tencent.supersonic.headless.api.response;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.headless.api.pojo.Dim;
|
||||
import com.tencent.supersonic.headless.api.pojo.DrillDownDimension;
|
||||
import com.tencent.supersonic.headless.api.pojo.Identify;
|
||||
import com.tencent.supersonic.headless.api.pojo.Measure;
|
||||
import com.tencent.supersonic.headless.api.pojo.ModelDetail;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaItem;
|
||||
import com.tencent.supersonic.headless.api.pojo.Identify;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class ModelResp extends SchemaItem {
|
||||
|
||||
private Long domainId;
|
||||
@@ -66,7 +72,27 @@ public class ModelResp extends SchemaItem {
|
||||
if (modelDetail == null) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
return modelDetail.getTimeDims();
|
||||
return modelDetail.filterTimeDims();
|
||||
}
|
||||
|
||||
public Set<String> getFieldList() {
|
||||
Set<String> fieldSet = new HashSet<>();
|
||||
if (modelDetail == null) {
|
||||
return fieldSet;
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(modelDetail.getIdentifiers())) {
|
||||
fieldSet.addAll(modelDetail.getIdentifiers().stream()
|
||||
.map(Identify::getFieldName).collect(Collectors.toSet()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(modelDetail.getDimensions())) {
|
||||
fieldSet.addAll(modelDetail.getDimensions().stream()
|
||||
.map(Dim::getFieldName).collect(Collectors.toSet()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(modelDetail.getMeasures())) {
|
||||
fieldSet.addAll(modelDetail.getMeasures().stream()
|
||||
.map(Measure::getFieldName).collect(Collectors.toSet()));
|
||||
}
|
||||
return fieldSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user