mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
(feature) (headless) tag api (#769)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TagDefineParams {
|
||||
|
||||
private String expr;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.enums;
|
||||
|
||||
public enum TagDefineType {
|
||||
|
||||
FIELD,
|
||||
DIMENSION,
|
||||
Tag
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.enums;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public enum TagType {
|
||||
ATOMIC,
|
||||
DERIVED;
|
||||
|
||||
public static TagType of(String src) {
|
||||
for (TagType tagType : TagType.values()) {
|
||||
if (Objects.nonNull(src) && src.equalsIgnoreCase(tagType.name())) {
|
||||
return tagType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Boolean isDerived(String src) {
|
||||
TagType tagType = of(src);
|
||||
return Objects.nonNull(tagType) && tagType.equals(DERIVED);
|
||||
}
|
||||
|
||||
public static TagType getType(TagDefineType tagDefineType) {
|
||||
return Objects.nonNull(tagDefineType) && TagDefineType.Tag.equals(tagDefineType) ? TagType.DERIVED
|
||||
: TagType.ATOMIC;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.request;
|
||||
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
import com.tencent.supersonic.common.pojo.Constants;
|
||||
|
||||
@@ -1,18 +1,64 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.request;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
import com.tencent.supersonic.common.pojo.DateConf;
|
||||
import com.tencent.supersonic.common.pojo.Filter;
|
||||
import com.tencent.supersonic.common.pojo.Order;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@ToString
|
||||
public class QueryTagReq {
|
||||
public class QueryTagReq extends SemanticQueryReq {
|
||||
|
||||
private Long domainId;
|
||||
private List<String> groups = new ArrayList<>();
|
||||
private List<Aggregator> aggregators = new ArrayList<>();
|
||||
private List<Filter> tagFilters = new ArrayList<>();
|
||||
private List<Order> orders = new ArrayList<>();
|
||||
|
||||
private List<Long> tagIds;
|
||||
private Long limit = 20L;
|
||||
private Long offset = 0L;
|
||||
|
||||
private List<String> tagNames;
|
||||
private String tagFiltersDate;
|
||||
private DateConf dateInfo;
|
||||
|
||||
private Long limit = 2000L;
|
||||
}
|
||||
@Override
|
||||
public String toCustomizedString() {
|
||||
StringBuilder stringBuilder = new StringBuilder("{");
|
||||
stringBuilder.append("\"viewId\":")
|
||||
.append(viewId);
|
||||
stringBuilder.append("\"modelIds\":")
|
||||
.append(modelIds);
|
||||
stringBuilder.append(",\"groups\":")
|
||||
.append(groups);
|
||||
stringBuilder.append(",\"aggregators\":")
|
||||
.append(aggregators);
|
||||
stringBuilder.append(",\"orders\":")
|
||||
.append(orders);
|
||||
stringBuilder.append(",\"tagFilters\":")
|
||||
.append(tagFilters);
|
||||
stringBuilder.append(",\"dateInfo\":")
|
||||
.append(dateInfo);
|
||||
stringBuilder.append(",\"params\":")
|
||||
.append(params);
|
||||
stringBuilder.append(",\"limit\":")
|
||||
.append(limit);
|
||||
stringBuilder.append('}');
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public List<String> getMetrics() {
|
||||
List<String> metrics = Lists.newArrayList();
|
||||
if (!CollectionUtils.isEmpty(this.aggregators)) {
|
||||
metrics = aggregators.stream().map(Aggregator::getColumn).collect(Collectors.toList());
|
||||
}
|
||||
return metrics;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.request;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaItem;
|
||||
import com.tencent.supersonic.headless.api.pojo.TagDefineParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.TagType;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TagReq extends SchemaItem {
|
||||
|
||||
private Long modelId;
|
||||
private Map<String, Object> ext = new HashMap<>();
|
||||
private TagDefineType tagDefineType;
|
||||
private TagDefineParams tagDefineParams;
|
||||
|
||||
public String getTypeParamsJson() {
|
||||
return JSONObject.toJSONString(tagDefineParams);
|
||||
}
|
||||
|
||||
public String getExtJson() {
|
||||
return Objects.nonNull(ext) && ext.size() > 0 ? JSONObject.toJSONString(ext) : "";
|
||||
}
|
||||
|
||||
public TagType getType() {
|
||||
return TagType.getType(tagDefineType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public class SemanticSchemaResp {
|
||||
private SchemaType schemaType;
|
||||
private List<MetricSchemaResp> metrics = Lists.newArrayList();
|
||||
private List<DimSchemaResp> dimensions = Lists.newArrayList();
|
||||
private List<TagResp> tags = Lists.newArrayList();
|
||||
private List<ModelRela> modelRelas = Lists.newArrayList();
|
||||
private List<ModelResp> modelResps = Lists.newArrayList();
|
||||
private ViewResp viewResp;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.response;
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaItem;
|
||||
import com.tencent.supersonic.headless.api.pojo.TagDefineParams;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.TagDefineType;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class TagResp extends SchemaItem {
|
||||
|
||||
private Long modelId;
|
||||
|
||||
private String type;
|
||||
|
||||
private Map<String, Object> ext = new HashMap<>();
|
||||
|
||||
private TagDefineType tagDefineType = TagDefineType.FIELD;
|
||||
|
||||
private TagDefineParams tagDefineParams;
|
||||
|
||||
public String getExpr() {
|
||||
return tagDefineParams.getExpr();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user