[improvement][project] global refactor , code format , support llm , support fuzzy detect ,support query filter and so on.

This commit is contained in:
lexluo
2023-07-08 15:00:03 +08:00
parent 5ffd617431
commit 404163f391
329 changed files with 21050 additions and 5036 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -19,7 +19,7 @@ public class DatasourceReq extends SchemaItem {
private String sqlQuery;
private String sqlTable;
private String tableQuery;
private Long domainId;

View File

@@ -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;
}

View File

@@ -10,4 +10,6 @@ public class MetricBaseReq extends SchemaItem {
private Long domainId;
private String alias;
}

View File

@@ -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");
}
}

View File

@@ -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;
}

View File

@@ -23,5 +23,9 @@ public class DomainResp extends SchemaItem {
private Integer isOpen = 0;
private Integer dimensionCnt;
private Integer metricCnt;
}

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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
}
}

View File

@@ -5,6 +5,8 @@ import com.tencent.supersonic.semantic.api.core.request.DatabaseReq;
import com.tencent.supersonic.semantic.api.core.response.DatabaseResp;
import com.tencent.supersonic.semantic.api.core.response.QueryResultWithSchemaResp;
import com.tencent.supersonic.semantic.api.core.response.SqlParserResp;
import com.tencent.supersonic.semantic.core.domain.adaptor.engineadapter.EngineAdaptor;
import com.tencent.supersonic.semantic.core.domain.adaptor.engineadapter.EngineAdaptorFactory;
import com.tencent.supersonic.semantic.core.domain.dataobject.DatabaseDO;
import com.tencent.supersonic.semantic.core.domain.repository.DatabaseRepository;
import com.tencent.supersonic.semantic.core.domain.utils.DatabaseConverter;
@@ -24,9 +26,8 @@ import org.springframework.stereotype.Service;
@Service
public class DatabaseServiceImpl implements DatabaseService {
private DatabaseRepository databaseRepository;
private final SqlUtils sqlUtils;
private DatabaseRepository databaseRepository;
public DatabaseServiceImpl(DatabaseRepository databaseRepository, SqlUtils sqlUtils) {
this.databaseRepository = databaseRepository;
@@ -53,6 +54,7 @@ public class DatabaseServiceImpl implements DatabaseService {
return DatabaseConverter.convert(databaseDO);
}
@Override
public DatabaseResp getDatabase(Long id) {
DatabaseDO databaseDO = databaseRepository.getDatabase(id);
@@ -74,8 +76,6 @@ public class DatabaseServiceImpl implements DatabaseService {
@Override
public QueryResultWithSchemaResp executeSql(String sql, DatabaseResp databaseResp) {
SqlUtils sqlUtils = this.sqlUtils.init(databaseResp);
return queryWithColumns(sql, databaseResp);
}
@@ -93,7 +93,7 @@ public class DatabaseServiceImpl implements DatabaseService {
private QueryResultWithSchemaResp queryWithColumns(String sql, DatabaseResp databaseResp) {
QueryResultWithSchemaResp queryResultWithColumns = new QueryResultWithSchemaResp();
SqlUtils sqlUtils = this.sqlUtils.init(databaseResp);
log.info("query SQL: {}" , sql);
log.info("query SQL: {}", sql);
sqlUtils.queryInternal(sql, queryResultWithColumns);
return queryResultWithColumns;
}
@@ -103,4 +103,31 @@ public class DatabaseServiceImpl implements DatabaseService {
return databaseDOS.stream().findFirst();
}
@Override
public QueryResultWithSchemaResp getDbNames(Long id) {
DatabaseResp databaseResp = getDatabase(id);
EngineAdaptor engineAdaptor = EngineAdaptorFactory.getEngineAdaptor(databaseResp.getType());
String metaQueryTpl = engineAdaptor.getDbMetaQueryTpl();
return queryWithColumns(metaQueryTpl, databaseResp);
}
@Override
public QueryResultWithSchemaResp getTables(Long id, String db) {
DatabaseResp databaseResp = getDatabase(id);
EngineAdaptor engineAdaptor = EngineAdaptorFactory.getEngineAdaptor(databaseResp.getType());
String metaQueryTpl = engineAdaptor.getTableMetaQueryTpl();
String metaQuerySql = String.format(metaQueryTpl, db);
return queryWithColumns(metaQuerySql, databaseResp);
}
@Override
public QueryResultWithSchemaResp getColumns(Long id, String db, String table) {
DatabaseResp databaseResp = getDatabase(id);
EngineAdaptor engineAdaptor = EngineAdaptorFactory.getEngineAdaptor(databaseResp.getType());
String metaQueryTpl = engineAdaptor.getColumnMetaQueryTpl();
String metaQuerySql = String.format(metaQueryTpl, db, table);
return queryWithColumns(metaQuerySql, databaseResp);
}
}

View File

@@ -63,8 +63,6 @@ public class DatasourceServiceImpl implements DatasourceService {
private DatasourceRepository datasourceRepository;
private DatasourceYamlManager datasourceYamlManager;
private DatabaseService databaseService;
private DimensionService dimensionService;
@@ -73,19 +71,13 @@ public class DatasourceServiceImpl implements DatasourceService {
private DateInfoRepository dateInfoRepository;
private DomainService domainService;
public DatasourceServiceImpl(DatasourceRepository datasourceRepository,
DatasourceYamlManager datasourceYamlManager,
DomainService domainService,
DatabaseService databaseService,
@Lazy DimensionService dimensionService,
@Lazy MetricService metricService,
DateInfoRepository dateInfoRepository) {
this.domainService = domainService;
this.datasourceRepository = datasourceRepository;
this.datasourceYamlManager = datasourceYamlManager;
this.databaseService = databaseService;
this.dimensionService = dimensionService;
this.metricService = metricService;
@@ -107,10 +99,6 @@ public class DatasourceServiceImpl implements DatasourceService {
datasource.setId(datasourceDesc.getId());
batchCreateDimension(datasource, user);
batchCreateMetric(datasource, user);
List<DimensionResp> dimensionDescsExist = dimensionService.getDimensionsByDatasource(datasource.getId());
DatabaseResp databaseResp = databaseService.getDatabase(datasource.getDatabaseId());
datasourceYamlManager.generateYamlFile(datasource, databaseResp,
domainService.getDomainFullPath(datasource.getDomainId()), dimensionDescsExist);
return datasourceDesc;
}
@@ -124,10 +112,6 @@ public class DatasourceServiceImpl implements DatasourceService {
batchCreateDimension(datasource, user);
batchCreateMetric(datasource, user);
List<DimensionResp> dimensionDescsExist = dimensionService.getDimensionsByDatasource(datasource.getId());
DatabaseResp databaseResp = databaseService.getDatabase(datasource.getDatabaseId());
datasourceYamlManager.generateYamlFile(datasource, databaseResp,
domainService.getDomainFullPath(datasource.getDomainId()), dimensionDescsExist);
DatasourceDO datasourceDO = updateDatasource(datasource, user);
return DatasourceConverter.convert(datasourceDO);
}
@@ -207,8 +191,6 @@ public class DatasourceServiceImpl implements DatasourceService {
}
private void preCheck(DatasourceReq datasourceReq) {
List<Dim> dims = datasourceReq.getDimensions();
if (CollectionUtils.isEmpty(dims)) {
@@ -245,8 +227,6 @@ public class DatasourceServiceImpl implements DatasourceService {
}
@Override
public Map<Long, DatasourceResp> getDatasourceMap() {
Map<Long, DatasourceResp> map = new HashMap<>();
@@ -264,9 +244,16 @@ public class DatasourceServiceImpl implements DatasourceService {
if (datasourceDO == null) {
return;
}
checkDelete(datasourceDO.getDomainId(), id);
datasourceRepository.deleteDatasource(id);
datasourceYamlManager.deleteYamlFile(datasourceDO.getBizName(),
domainService.getDomainFullPath(datasourceDO.getDomainId()));
}
private void checkDelete(Long domainId, Long datasourceId) {
List<MetricResp> metricResps = metricService.getMetrics(domainId, datasourceId);
List<DimensionResp> dimensionResps = dimensionService.getDimensionsByDatasource(datasourceId);
if (!CollectionUtils.isEmpty(metricResps) || !CollectionUtils.isEmpty(dimensionResps)) {
throw new RuntimeException("exist dimension or metric on this datasource, please check");
}
}
@@ -315,6 +302,7 @@ public class DatasourceServiceImpl implements DatasourceService {
}
@Override
public ItemDateResp getDateDate(ItemDateFilter dimension, ItemDateFilter metric) {
List<DateInfoReq> itemDates = new ArrayList<>();
List<DateInfoDO> dimensions = dateInfoRepository.getDateInfos(dimension);
@@ -355,10 +343,10 @@ public class DatasourceServiceImpl implements DatasourceService {
String startDate1 = item.getStartDate();
String endDate1 = item.getEndDate();
List<String> unavailableDateList1 = item.getUnavailableDateList();
if (Strings.isNotEmpty(startDate1) && startDate1.compareTo(startDate) < 0) {
if (Strings.isNotEmpty(startDate1) && startDate1.compareTo(startDate) > 0) {
startDate = startDate1;
}
if (Strings.isNotEmpty(endDate1) && startDate1.compareTo(endDate1) > 0) {
if (Strings.isNotEmpty(endDate1) && endDate1.compareTo(endDate) < 0) {
endDate = endDate1;
}
if (!CollectionUtils.isEmpty(unavailableDateList1)) {

View File

@@ -11,7 +11,6 @@ import com.tencent.supersonic.semantic.api.core.response.DatasourceResp;
import com.tencent.supersonic.semantic.api.core.response.DimensionResp;
import com.tencent.supersonic.common.enums.SensitiveLevelEnum;
import com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO;
import com.tencent.supersonic.semantic.core.domain.manager.DimensionYamlManager;
import com.tencent.supersonic.semantic.core.domain.repository.DimensionRepository;
import com.tencent.supersonic.semantic.core.domain.utils.DimensionConverter;
import com.tencent.supersonic.semantic.core.domain.DatasourceService;
@@ -19,7 +18,6 @@ import com.tencent.supersonic.semantic.core.domain.DimensionService;
import com.tencent.supersonic.semantic.core.domain.DomainService;
import com.tencent.supersonic.semantic.core.domain.pojo.Dimension;
import com.tencent.supersonic.semantic.core.domain.pojo.DimensionFilter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -37,59 +35,54 @@ public class DimensionServiceImpl implements DimensionService {
private DimensionRepository dimensionRepository;
private DimensionYamlManager dimensionYamlManager;
private DatasourceService datasourceService;
private DomainService domainService;
public DimensionServiceImpl(DimensionRepository dimensionRepository,
DimensionYamlManager dimensionYamlManager,
DomainService domainService,
DatasourceService datasourceService) {
this.domainService = domainService;
this.dimensionRepository = dimensionRepository;
this.dimensionYamlManager = dimensionYamlManager;
this.datasourceService = datasourceService;
}
@Override
public void createDimension(DimensionReq dimensionReq, User user) throws Exception {
public void createDimension(DimensionReq dimensionReq, User user) {
checkExist(Lists.newArrayList(dimensionReq));
Dimension dimension = DimensionConverter.convert(dimensionReq);
log.info("[create dimension] object:{}", JSONObject.toJSONString(dimension));
saveDimensionAndGenerateYaml(dimension, user);
dimension.createdBy(user.getName());
saveDimension(dimension);
}
@Override
public void createDimensionBatch(List<DimensionReq> dimensionReqs, User user) throws Exception {
public void createDimensionBatch(List<DimensionReq> dimensionReqs, User user) {
if (CollectionUtils.isEmpty(dimensionReqs)) {
return;
}
Long domainId = dimensionReqs.get(0).getDomainId();
List<DimensionResp> dimensionDescs = getDimensions(domainId);
Map<String, DimensionResp> dimensionDescMap = dimensionDescs.stream()
List<DimensionResp> dimensionResps = getDimensions(domainId);
Map<String, DimensionResp> dimensionRespMap = dimensionResps.stream()
.collect(Collectors.toMap(DimensionResp::getBizName, a -> a, (k1, k2) -> k1));
List<Dimension> dimensions = dimensionReqs.stream().map(DimensionConverter::convert)
.collect(Collectors.toList());
List<Dimension> dimensionToInsert = dimensions.stream()
.filter(dimension -> !dimensionDescMap.containsKey(dimension.getBizName()))
.filter(dimension -> !dimensionRespMap.containsKey(dimension.getBizName()))
.collect(Collectors.toList());
log.info("[create dimension] object:{}", JSONObject.toJSONString(dimensions));
saveDimensionBatch(dimensionToInsert, user);
generateYamlFile(dimensions.get(0).getDatasourceId(), dimensions.get(0).getDomainId());
}
@Override
public void updateDimension(DimensionReq dimensionReq, User user) throws Exception {
public void updateDimension(DimensionReq dimensionReq, User user) {
Dimension dimension = DimensionConverter.convert(dimensionReq);
dimension.updatedBy(user.getName());
log.info("[update dimension] object:{}", JSONObject.toJSONString(dimension));
updateDimension(dimension);
generateYamlFile(dimension.getDatasourceId(), dimension.getDomainId());
}
protected void updateDimension(Dimension dimension) {
@@ -100,13 +93,13 @@ public class DimensionServiceImpl implements DimensionService {
@Override
public DimensionResp getDimension(String bizName, Long domainId) {
List<DimensionResp> dimensionDescs = getDimensions(domainId);
if (CollectionUtils.isEmpty(dimensionDescs)) {
List<DimensionResp> dimensionResps = getDimensions(domainId);
if (CollectionUtils.isEmpty(dimensionResps)) {
return null;
}
for (DimensionResp dimensionDesc : dimensionDescs) {
if (dimensionDesc.getBizName().equalsIgnoreCase(bizName)) {
return dimensionDesc;
for (DimensionResp dimensionResp : dimensionResps) {
if (dimensionResp.getBizName().equalsIgnoreCase(bizName)) {
return dimensionResp;
}
}
return null;
@@ -132,16 +125,16 @@ public class DimensionServiceImpl implements DimensionService {
@Override
public List<DimensionResp> getDimensions(List<Long> ids) {
List<DimensionResp> dimensionDescs = Lists.newArrayList();
List<DimensionResp> dimensionResps = Lists.newArrayList();
List<DimensionDO> dimensionDOS = dimensionRepository.getDimensionListByIds(ids);
Map<Long, String> fullDomainPathMap = domainService.getDomainFullPath();
if (!CollectionUtils.isEmpty(dimensionDOS)) {
dimensionDescs = dimensionDOS.stream()
.map(dimensionDO -> DimensionConverter.convert2DimensionDesc(dimensionDO, fullDomainPathMap,
dimensionResps = dimensionDOS.stream()
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, fullDomainPathMap,
new HashMap<>()))
.collect(Collectors.toList());
}
return dimensionDescs;
return dimensionResps;
}
@Override
@@ -149,52 +142,46 @@ public class DimensionServiceImpl implements DimensionService {
return convertList(getDimensionDOS(domainId), datasourceService.getDatasourceMap());
}
public List<Dimension> getDimensionList(Long datasourceId) {
List<Dimension> dimensions = Lists.newArrayList();
List<DimensionDO> dimensionDOS = dimensionRepository.getDimensionListOfDatasource(datasourceId);
if (!CollectionUtils.isEmpty(dimensionDOS)) {
dimensions = dimensionDOS.stream().map(DimensionConverter::convert2Dimension).collect(Collectors.toList());
}
return dimensions;
@Override
public List<DimensionResp> getDimensions() {
return convertList(getDimensionDOS(), datasourceService.getDatasourceMap());
}
@Override
public List<DimensionResp> getDimensionsByDatasource(Long datasourceId) {
List<DimensionResp> dimensionDescs = Lists.newArrayList();
List<DimensionResp> dimensionResps = Lists.newArrayList();
List<DimensionDO> dimensionDOS = dimensionRepository.getDimensionListOfDatasource(datasourceId);
if (!CollectionUtils.isEmpty(dimensionDOS)) {
dimensionDescs = dimensionDOS.stream()
.map(dimensionDO -> DimensionConverter.convert2DimensionDesc(dimensionDO, new HashMap<>(),
dimensionResps = dimensionDOS.stream()
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, new HashMap<>(),
new HashMap<>()))
.collect(Collectors.toList());
}
return dimensionDescs;
return dimensionResps;
}
private List<DimensionResp> convertList(List<DimensionDO> dimensionDOS,
Map<Long, DatasourceResp> datasourceDescMap) {
List<DimensionResp> dimensionDescs = Lists.newArrayList();
Map<Long, DatasourceResp> datasourceRespMap) {
List<DimensionResp> dimensionResps = Lists.newArrayList();
Map<Long, String> fullDomainPathMap = domainService.getDomainFullPath();
if (!CollectionUtils.isEmpty(dimensionDOS)) {
dimensionDescs = dimensionDOS.stream()
.map(dimensionDO -> DimensionConverter.convert2DimensionDesc(dimensionDO, fullDomainPathMap,
datasourceDescMap))
dimensionResps = dimensionDOS.stream()
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, fullDomainPathMap,
datasourceRespMap))
.collect(Collectors.toList());
}
return dimensionDescs;
return dimensionResps;
}
@Override
public List<DimensionResp> getHighSensitiveDimension(Long domainId) {
List<DimensionResp> dimensionDescs = getDimensions(domainId);
if (CollectionUtils.isEmpty(dimensionDescs)) {
return dimensionDescs;
List<DimensionResp> dimensionResps = getDimensions(domainId);
if (CollectionUtils.isEmpty(dimensionResps)) {
return dimensionResps;
}
return dimensionDescs.stream()
.filter(dimensionDesc -> SensitiveLevelEnum.HIGH.getCode().equals(dimensionDesc.getSensitiveLevel()))
return dimensionResps.stream()
.filter(dimensionResp -> SensitiveLevelEnum.HIGH.getCode().equals(dimensionResp.getSensitiveLevel()))
.collect(Collectors.toList());
}
@@ -203,13 +190,17 @@ public class DimensionServiceImpl implements DimensionService {
return dimensionRepository.getDimensionListOfDomain(domainId);
}
protected List<DimensionDO> getDimensionDOS() {
return dimensionRepository.getDimensionList();
}
@Override
public List<DimensionResp> getAllHighSensitiveDimension() {
List<DimensionResp> dimensionDescs = Lists.newArrayList();
List<DimensionResp> dimensionResps = Lists.newArrayList();
List<DimensionDO> dimensionDOS = dimensionRepository.getAllDimensionList();
if (CollectionUtils.isEmpty(dimensionDOS)) {
return dimensionDescs;
return dimensionResps;
}
return convertList(dimensionDOS.stream()
.filter(dimensionDO -> SensitiveLevelEnum.HIGH.getCode().equals(dimensionDO.getSensitiveLevel()))
@@ -217,8 +208,7 @@ public class DimensionServiceImpl implements DimensionService {
}
//保存并获取自增ID
private void saveDimension(Dimension dimension) {
public void saveDimension(Dimension dimension) {
DimensionDO dimensionDO = DimensionConverter.convert2DimensionDO(dimension);
log.info("[save dimension] dimensionDO:{}", JSONObject.toJSONString(dimensionDO));
dimensionRepository.createDimension(dimensionDO);
@@ -238,52 +228,30 @@ public class DimensionServiceImpl implements DimensionService {
}
@Override
public void deleteDimension(Long id) throws Exception {
public void deleteDimension(Long id) {
DimensionDO dimensionDO = dimensionRepository.getDimensionById(id);
if (dimensionDO == null) {
throw new RuntimeException(String.format("the dimension %s not exist", id));
}
dimensionRepository.deleteDimension(id);
generateYamlFile(dimensionDO.getDatasourceId(), dimensionDO.getDomainId());
}
protected void generateYamlFile(Long datasourceId, Long domainId) throws Exception {
String datasourceBizName = datasourceService.getSourceBizNameById(datasourceId);
List<Dimension> dimensionList = getDimensionList(datasourceId);
String fullPath = domainService.getDomainFullPath(domainId);
dimensionYamlManager.generateYamlFile(dimensionList, fullPath, datasourceBizName);
}
private void checkExist(List<DimensionReq> dimensionReqs) {
Long domainId = dimensionReqs.get(0).getDomainId();
List<DimensionResp> dimensionDescs = getDimensions(domainId);
List<DimensionResp> dimensionResps = getDimensions(domainId);
for (DimensionReq dimensionReq : dimensionReqs) {
for (DimensionResp dimensionDesc : dimensionDescs) {
if (dimensionDesc.getName().equalsIgnoreCase(dimensionReq.getBizName())) {
for (DimensionResp dimensionResp : dimensionResps) {
if (dimensionResp.getName().equalsIgnoreCase(dimensionReq.getBizName())) {
throw new RuntimeException(String.format("exist same dimension name:%s", dimensionReq.getName()));
}
if (dimensionDesc.getBizName().equalsIgnoreCase(dimensionReq.getBizName())) {
if (dimensionResp.getBizName().equalsIgnoreCase(dimensionReq.getBizName())) {
throw new RuntimeException(
String.format("exist same dimension bizName:%s", dimensionReq.getBizName()));
}
}
}
}
private void saveDimensionAndGenerateYaml(Dimension dimension, User user) throws Exception {
dimension.createdBy(user.getName());
saveDimension(dimension);
generateYamlFile(dimension.getDatasourceId(), dimension.getDomainId());
}
}

View File

@@ -3,24 +3,25 @@ package com.tencent.supersonic.semantic.core.application;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.util.mapper.BeanMapper;
import com.tencent.supersonic.semantic.api.core.request.DomainReq;
import com.tencent.supersonic.semantic.api.core.request.DomainSchemaFilterReq;
import com.tencent.supersonic.semantic.api.core.request.DomainUpdateReq;
import com.tencent.supersonic.semantic.api.core.response.DatasourceResp;
import com.tencent.supersonic.semantic.api.core.response.DimSchemaResp;
import com.tencent.supersonic.semantic.api.core.response.DimensionResp;
import com.tencent.supersonic.semantic.api.core.response.DomainResp;
import com.tencent.supersonic.semantic.api.core.response.DomainSchemaResp;
import com.tencent.supersonic.semantic.api.core.response.MetricResp;
import com.tencent.supersonic.semantic.api.core.response.MetricSchemaResp;
import com.tencent.supersonic.common.util.mapper.BeanMapper;
import com.tencent.supersonic.semantic.core.domain.dataobject.DomainDO;
import com.tencent.supersonic.semantic.core.domain.repository.DomainRepository;
import com.tencent.supersonic.semantic.core.domain.utils.DomainConvert;
import com.tencent.supersonic.semantic.core.domain.DatasourceService;
import com.tencent.supersonic.semantic.core.domain.DimensionService;
import com.tencent.supersonic.semantic.core.domain.DomainService;
import com.tencent.supersonic.semantic.core.domain.MetricService;
import com.tencent.supersonic.semantic.core.domain.dataobject.DomainDO;
import com.tencent.supersonic.semantic.core.domain.pojo.Domain;
import com.tencent.supersonic.semantic.core.domain.repository.DomainRepository;
import com.tencent.supersonic.semantic.core.domain.utils.DomainConvert;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -42,14 +43,15 @@ public class DomainServiceImpl implements DomainService {
private final DomainRepository domainRepository;
private final MetricService metricService;
private final DimensionService dimensionService;
private final DatasourceService datasourceService;
public DomainServiceImpl(DomainRepository domainRepository,
@Lazy MetricService metricService,
@Lazy DimensionService dimensionService) {
public DomainServiceImpl(DomainRepository domainRepository, @Lazy MetricService metricService,
@Lazy DimensionService dimensionService, @Lazy DatasourceService datasourceService) {
this.domainRepository = domainRepository;
this.metricService = metricService;
this.dimensionService = dimensionService;
this.datasourceService = datasourceService;
}
@@ -80,9 +82,20 @@ public class DomainServiceImpl implements DomainService {
@Override
public void deleteDomain(Long id) {
checkDelete(id);
domainRepository.deleteDomain(id);
}
private void checkDelete(Long id) {
List<MetricResp> metricResps = metricService.getMetrics(id);
List<DimensionResp> dimensionResps = dimensionService.getDimensions(id);
List<DatasourceResp> datasourceResps = datasourceService.getDatasourceList(id);
if (!CollectionUtils.isEmpty(metricResps) || !CollectionUtils.isEmpty(datasourceResps)
|| !CollectionUtils.isEmpty(dimensionResps)) {
throw new RuntimeException("exist datasource, dimension or metric in this domain, please check");
}
}
@Override
public String getDomainBizName(Long id) {
if (id == null) {
@@ -99,7 +112,7 @@ public class DomainServiceImpl implements DomainService {
@Override
public List<DomainResp> getDomainList() {
return convertList(domainRepository.getDomainList());
return convertList(domainRepository.getDomainList(), new HashMap<>(), new HashMap<>());
}
@@ -115,7 +128,11 @@ public class DomainServiceImpl implements DomainService {
List<DomainDO> domainDOS = domainRepository.getDomainList();
List<String> orgIds = Lists.newArrayList();
log.info("orgIds:{},userName:{}", orgIds, userName);
return convertList(domainDOS).stream()
Map<Long, List<MetricResp>> metricDomainMap = metricService.getMetrics().stream()
.collect(Collectors.groupingBy(MetricResp::getDomainId));
Map<Long, List<DimensionResp>> dimensionDomainMap = dimensionService.getDimensions().stream()
.collect(Collectors.groupingBy(DimensionResp::getDomainId));
return convertList(domainDOS, metricDomainMap, dimensionDomainMap).stream()
.filter(domainDesc -> checkAdminPermission(orgIds, userName, domainDesc))
.collect(Collectors.toList());
}
@@ -125,7 +142,7 @@ public class DomainServiceImpl implements DomainService {
List<DomainDO> domainDOS = domainRepository.getDomainList();
List<String> orgIds = Lists.newArrayList();
log.info("orgIds:{},userName:{}", orgIds, userName);
return convertList(domainDOS).stream()
return convertList(domainDOS, new HashMap<>(), new HashMap<>()).stream()
.filter(domainDesc -> checkViewerPermission(orgIds, userName, domainDesc))
.collect(Collectors.toList());
}
@@ -160,23 +177,23 @@ public class DomainServiceImpl implements DomainService {
}
private List<DomainResp> convertList(List<DomainDO> domainDOS) {
private List<DomainResp> convertList(List<DomainDO> domainDOS, Map<Long, List<MetricResp>> metricDomainMap,
Map<Long, List<DimensionResp>> dimensionDomainMap) {
List<DomainResp> domainDescs = Lists.newArrayList();
if (CollectionUtils.isEmpty(domainDOS)) {
return domainDescs;
}
Map<Long, String> fullDomainPathMap = getDomainFullPath();
return domainDOS.stream()
.map(domainDO -> DomainConvert.convert(domainDO, fullDomainPathMap))
.map(domainDO -> DomainConvert.convert(domainDO, fullDomainPathMap, dimensionDomainMap,
metricDomainMap))
.collect(Collectors.toList());
}
@Override
public Map<Long, DomainResp> getDomainMap() {
return getDomainList().stream().collect(Collectors.toMap(DomainResp::getId, a -> a, (k1, k2) -> k1));
}

View File

@@ -13,7 +13,6 @@ import com.tencent.supersonic.semantic.api.core.response.DomainResp;
import com.tencent.supersonic.semantic.api.core.response.MetricResp;
import com.tencent.supersonic.common.enums.SensitiveLevelEnum;
import com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO;
import com.tencent.supersonic.semantic.core.domain.manager.MetricYamlManager;
import com.tencent.supersonic.semantic.core.domain.pojo.MetricFilter;
import com.tencent.supersonic.semantic.core.domain.repository.MetricRepository;
import com.tencent.supersonic.semantic.core.domain.utils.MetricConverter;
@@ -27,6 +26,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -38,30 +38,26 @@ public class MetricServiceImpl implements MetricService {
private MetricRepository metricRepository;
private MetricYamlManager metricYamlManager;
private DomainService domainService;
public MetricServiceImpl(MetricRepository metricRepository,
MetricYamlManager metricYamlManager,
DomainService domainService) {
this.domainService = domainService;
this.metricRepository = metricRepository;
this.metricYamlManager = metricYamlManager;
}
@Override
public void creatExprMetric(MetricReq metricReq, User user) throws Exception {
public void creatExprMetric(MetricReq metricReq, User user) {
checkExist(Lists.newArrayList(metricReq));
Metric metric = MetricConverter.convert(metricReq);
metric.createdBy(user.getName());
log.info("[create metric] object:{}", JSONObject.toJSONString(metric));
saveMetricAndGenerateYaml(metric);
saveMetric(metric);
}
@Override
public void createMetricBatch(List<MetricReq> metricReqs, User user) throws Exception {
public void createMetricBatch(List<MetricReq> metricReqs, User user) {
if (CollectionUtils.isEmpty(metricReqs)) {
return;
}
@@ -74,8 +70,6 @@ public class MetricServiceImpl implements MetricService {
.filter(metric -> !metricDescMap.containsKey(metric.getBizName())).collect(Collectors.toList());
log.info("[insert metric] object:{}", JSONObject.toJSONString(metricToInsert));
saveMetricBatch(metricToInsert, user);
generateYamlFile(metrics.get(0).getDomainId());
}
@@ -84,6 +78,11 @@ public class MetricServiceImpl implements MetricService {
return convertList(metricRepository.getMetricList(domainId));
}
@Override
public List<MetricResp> getMetrics() {
return convertList(metricRepository.getMetricList());
}
@Override
public List<MetricResp> getMetrics(Long domainId, Long datasourceId) {
List<MetricResp> metricResps = convertList(metricRepository.getMetricList(domainId));
@@ -136,27 +135,15 @@ public class MetricServiceImpl implements MetricService {
}
@Override
public void updateExprMetric(MetricReq metricReq, User user) throws Exception {
public void updateExprMetric(MetricReq metricReq, User user) {
preCheckMetric(metricReq);
Metric metric = MetricConverter.convert(metricReq);
metric.updatedBy(user.getName());
log.info("[update metric] object:{}", JSONObject.toJSONString(metric));
updateMetric(metric);
generateYamlFile(metric.getDomainId());
}
public List<Metric> getMetricList(Long domainId) {
List<Metric> metrics = Lists.newArrayList();
List<MetricDO> metricDOS = metricRepository.getMetricList(domainId);
if (!CollectionUtils.isEmpty(metricDOS)) {
metrics = metricDOS.stream().map(MetricConverter::convert2Metric).collect(Collectors.toList());
}
return metrics;
}
//保存并获取自增ID
public void saveMetric(Metric metric) {
MetricDO metricDO = MetricConverter.convert2MetricDO(metric);
log.info("[save metric] metricDO:{}", JSONObject.toJSONString(metricDO));
@@ -205,20 +192,12 @@ public class MetricServiceImpl implements MetricService {
}
@Override
public void deleteMetric(Long id) throws Exception {
public void deleteMetric(Long id) {
MetricDO metricDO = metricRepository.getMetricById(id);
if (metricDO == null) {
throw new RuntimeException(String.format("the metric %s not exist", id));
}
metricRepository.deleteMetric(id);
generateYamlFile(metricDO.getDomainId());
}
protected void generateYamlFile(Long domainId) throws Exception {
List<Metric> metrics = getMetricList(domainId);
String fullPath = domainService.getDomainFullPath(domainId);
String domainBizName = domainService.getDomainBizName(domainId);
metricYamlManager.generateYamlFile(metrics, fullPath, domainBizName);
}
@@ -232,21 +211,14 @@ public class MetricServiceImpl implements MetricService {
metricRepository.createMetricBatch(metricDOS);
}
private void saveMetricAndGenerateYaml(Metric metric) throws Exception {
saveMetric(metric);
generateYamlFile(metric.getDomainId());
}
private void preCheckMetric(MetricReq exprMetricReq) {
MetricTypeParams typeParams = exprMetricReq.getTypeParams();
private void preCheckMetric(MetricReq metricReq) {
MetricTypeParams typeParams = metricReq.getTypeParams();
List<Measure> measures = typeParams.getMeasures();
if (CollectionUtils.isEmpty(measures)) {
throw new RuntimeException("measure can not be none");
}
for (Measure measure : measures) {
measure.setExpr(null);
if (StringUtils.isBlank(typeParams.getExpr())) {
throw new RuntimeException("expr can not be blank");
}
}

View File

@@ -24,4 +24,9 @@ public interface DatabaseService {
QueryResultWithSchemaResp queryWithColumns(SqlParserResp sqlParser);
QueryResultWithSchemaResp getDbNames(Long id);
QueryResultWithSchemaResp getTables(Long id, String db);
QueryResultWithSchemaResp getColumns(Long id, String db, String table);
}

View File

@@ -13,6 +13,8 @@ public interface DimensionService {
List<DimensionResp> getDimensions(Long domainId);
List<DimensionResp> getDimensions();
DimensionResp getDimension(String bizName, Long domainId);
void createDimension(DimensionReq dimensionReq, User user) throws Exception;

View File

@@ -13,6 +13,8 @@ public interface MetricService {
List<MetricResp> getMetrics(Long domainId);
List<MetricResp> getMetrics();
List<MetricResp> getMetrics(Long domainId, Long datasourceId);
void creatExprMetric(MetricReq metricReq, User user) throws Exception;

View File

@@ -27,4 +27,22 @@ public class ClickHouseAdaptor extends EngineAdaptor {
return column;
}
@Override
public String getDbMetaQueryTpl() {
return " "
+ " select "
+ " name from system.databases "
+ " where name not in('_temporary_and_external_tables','benchmark','default','system');";
}
@Override
public String getTableMetaQueryTpl() {
return "select name from system.tables where database = '%s';";
}
@Override
public String getColumnMetaQueryTpl() {
return "select name,type as dataType, comment from system.columns where database = '%s' and table='%s'";
}
}

View File

@@ -7,4 +7,9 @@ public abstract class EngineAdaptor {
public abstract String getDateFormat(String dateType, String dateFormat, String column);
public abstract String getColumnMetaQueryTpl();
public abstract String getDbMetaQueryTpl();
public abstract String getTableMetaQueryTpl();
}

View File

@@ -18,7 +18,7 @@ public class MysqlAdaptor extends EngineAdaptor {
} else if (TimeDimensionEnum.WEEK.name().equalsIgnoreCase(dateType)) {
return "to_monday(from_unixtime(unix_timestamp(%s), 'yyyy-MM-dd'))".replace("%s", column);
} else {
return "from_unixtime(unix_timestamp(%s), 'yyyy-MM-dd')".replace("%s", column);
return "date_format(str_to_date(%s, '%Y%m%d'),'%Y-%m-%d')".replace("%s", column);
}
} else if (dateFormat.equalsIgnoreCase(Constants.DAY_FORMAT)) {
if (TimeDimensionEnum.MONTH.name().equalsIgnoreCase(dateType)) {
@@ -33,4 +33,21 @@ public class MysqlAdaptor extends EngineAdaptor {
}
@Override
public String getDbMetaQueryTpl() {
return "select distinct TABLE_SCHEMA from information_schema.tables where TABLE_SCHEMA not in ('information_schema','mysql','performance_schema','sys');";
}
@Override
public String getTableMetaQueryTpl() {
return "select TABLE_NAME from information_schema.tables where TABLE_SCHEMA = '%s';";
}
@Override
public String getColumnMetaQueryTpl() {
return "SELECT COLUMN_NAME as name, DATA_TYPE as dataType, COLUMN_COMMENT as comment " +
"FROM information_schema.columns WHERE table_schema ='%s' AND table_name = '%s'";
}
}

View File

@@ -38,13 +38,6 @@ public class DatabaseDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DatabaseDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DatabaseDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DatabaseDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DatabaseDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DatabaseDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_database null
*/
@@ -812,38 +812,6 @@ public class DatabaseDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -879,5 +847,37 @@ public class DatabaseDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -38,13 +38,6 @@ public class DatasourceDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DatasourceDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DatasourceDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DatasourceDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DatasourceDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DatasourceDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_datasource null
*/
@@ -872,38 +872,6 @@ public class DatasourceDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -939,5 +907,37 @@ public class DatasourceDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -38,13 +38,6 @@ public class DatasourceRelaDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DatasourceRelaDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DatasourceRelaDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DatasourceRelaDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DatasourceRelaDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DatasourceRelaDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_datasource_rela null
*/
@@ -787,38 +787,6 @@ public class DatasourceRelaDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -854,5 +822,37 @@ public class DatasourceRelaDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -38,13 +38,6 @@ public class DictionaryDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DictionaryDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DictionaryDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DictionaryDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DictionaryDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DictionaryDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_dictionary null
*/
@@ -792,38 +792,6 @@ public class DictionaryDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -859,5 +827,37 @@ public class DictionaryDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -37,13 +37,6 @@ public class DictionaryTaskDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -54,8 +47,8 @@ public class DictionaryTaskDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -65,6 +58,13 @@ public class DictionaryTaskDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -116,13 +116,6 @@ public class DictionaryTaskDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -133,8 +126,8 @@ public class DictionaryTaskDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -144,6 +137,13 @@ public class DictionaryTaskDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_dictionary_task null
*/
@@ -461,38 +461,6 @@ public class DictionaryTaskDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -528,5 +496,37 @@ public class DictionaryTaskDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -74,6 +74,16 @@ public class DimensionDO {
*/
private String semanticType;
/**
*
*/
private String alias;
/**
* default values of dimension when query
*/
private String defaultValues;
/**
* 类型参数
*/
@@ -336,6 +346,38 @@ public class DimensionDO {
this.semanticType = semanticType == null ? null : semanticType.trim();
}
/**
* @return alias
*/
public String getAlias() {
return alias;
}
/**
* @param alias
*/
public void setAlias(String alias) {
this.alias = alias == null ? null : alias.trim();
}
/**
* default values of dimension when query
*
* @return default_values default values of dimension when query
*/
public String getDefaultValues() {
return defaultValues;
}
/**
* default values of dimension when query
*
* @param defaultValues default values of dimension when query
*/
public void setDefaultValues(String defaultValues) {
this.defaultValues = defaultValues == null ? null : defaultValues.trim();
}
/**
* 类型参数
*

View File

@@ -38,13 +38,6 @@ public class DimensionDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DimensionDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DimensionDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DimensionDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DimensionDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DimensionDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_dimension null
*/
@@ -665,6 +665,11 @@ public class DimensionDOExample {
return (Criteria) this;
}
public Criteria andSensitiveLevelGreaterThanOrEqualTo(Integer value) {
addCriterion("sensitive_level >=", value, "sensitiveLevel");
return (Criteria) this;
}
public Criteria andSensitiveLevelLessThan(Integer value) {
addCriterion("sensitive_level <", value, "sensitiveLevel");
return (Criteria) this;
@@ -1094,6 +1099,146 @@ public class DimensionDOExample {
addCriterion("semantic_type not between", value1, value2, "semanticType");
return (Criteria) this;
}
public Criteria andAliasIsNull() {
addCriterion("alias is null");
return (Criteria) this;
}
public Criteria andAliasIsNotNull() {
addCriterion("alias is not null");
return (Criteria) this;
}
public Criteria andAliasEqualTo(String value) {
addCriterion("alias =", value, "alias");
return (Criteria) this;
}
public Criteria andAliasNotEqualTo(String value) {
addCriterion("alias <>", value, "alias");
return (Criteria) this;
}
public Criteria andAliasGreaterThan(String value) {
addCriterion("alias >", value, "alias");
return (Criteria) this;
}
public Criteria andAliasGreaterThanOrEqualTo(String value) {
addCriterion("alias >=", value, "alias");
return (Criteria) this;
}
public Criteria andAliasLessThan(String value) {
addCriterion("alias <", value, "alias");
return (Criteria) this;
}
public Criteria andAliasLessThanOrEqualTo(String value) {
addCriterion("alias <=", value, "alias");
return (Criteria) this;
}
public Criteria andAliasLike(String value) {
addCriterion("alias like", value, "alias");
return (Criteria) this;
}
public Criteria andAliasNotLike(String value) {
addCriterion("alias not like", value, "alias");
return (Criteria) this;
}
public Criteria andAliasIn(List<String> values) {
addCriterion("alias in", values, "alias");
return (Criteria) this;
}
public Criteria andAliasNotIn(List<String> values) {
addCriterion("alias not in", values, "alias");
return (Criteria) this;
}
public Criteria andAliasBetween(String value1, String value2) {
addCriterion("alias between", value1, value2, "alias");
return (Criteria) this;
}
public Criteria andAliasNotBetween(String value1, String value2) {
addCriterion("alias not between", value1, value2, "alias");
return (Criteria) this;
}
public Criteria andDefaultValuesIsNull() {
addCriterion("default_values is null");
return (Criteria) this;
}
public Criteria andDefaultValuesIsNotNull() {
addCriterion("default_values is not null");
return (Criteria) this;
}
public Criteria andDefaultValuesEqualTo(String value) {
addCriterion("default_values =", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesNotEqualTo(String value) {
addCriterion("default_values <>", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesGreaterThan(String value) {
addCriterion("default_values >", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesGreaterThanOrEqualTo(String value) {
addCriterion("default_values >=", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesLessThan(String value) {
addCriterion("default_values <", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesLessThanOrEqualTo(String value) {
addCriterion("default_values <=", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesLike(String value) {
addCriterion("default_values like", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesNotLike(String value) {
addCriterion("default_values not like", value, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesIn(List<String> values) {
addCriterion("default_values in", values, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesNotIn(List<String> values) {
addCriterion("default_values not in", values, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesBetween(String value1, String value2) {
addCriterion("default_values between", value1, value2, "defaultValues");
return (Criteria) this;
}
public Criteria andDefaultValuesNotBetween(String value1, String value2) {
addCriterion("default_values not between", value1, value2, "defaultValues");
return (Criteria) this;
}
}
/**
@@ -1127,38 +1272,6 @@ public class DimensionDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -1194,5 +1307,37 @@ public class DimensionDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -38,13 +38,6 @@ public class DomainDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DomainDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DomainDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DomainDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DomainDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DomainDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_domain null
*/
@@ -1142,38 +1142,6 @@ public class DomainDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -1209,5 +1177,37 @@ public class DomainDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -38,13 +38,6 @@ public class DomainExtendDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class DomainExtendDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class DomainExtendDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class DomainExtendDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class DomainExtendDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class DomainExtendDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_domain_extend null
*/
@@ -727,38 +727,6 @@ public class DomainExtendDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -794,5 +762,37 @@ public class DomainExtendDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -74,6 +74,11 @@ public class MetricDO {
*/
private String dataFormat;
/**
*
*/
private String alias;
/**
* 类型参数
*/
@@ -327,6 +332,20 @@ public class MetricDO {
this.dataFormat = dataFormat == null ? null : dataFormat.trim();
}
/**
* @return alias
*/
public String getAlias() {
return alias;
}
/**
* @param alias
*/
public void setAlias(String alias) {
this.alias = alias == null ? null : alias.trim();
}
/**
* 类型参数
*

View File

@@ -38,13 +38,6 @@ public class MetricDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class MetricDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class MetricDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class MetricDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class MetricDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class MetricDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_metric null
*/
@@ -605,6 +605,11 @@ public class MetricDOExample {
return (Criteria) this;
}
public Criteria andSensitiveLevelGreaterThanOrEqualTo(Integer value) {
addCriterion("sensitive_level >=", value, "sensitiveLevel");
return (Criteria) this;
}
public Criteria andSensitiveLevelLessThan(Integer value) {
addCriterion("sensitive_level <", value, "sensitiveLevel");
return (Criteria) this;
@@ -990,6 +995,11 @@ public class MetricDOExample {
return (Criteria) this;
}
public Criteria andDataFormatTypeGreaterThanOrEqualTo(String value) {
addCriterion("data_format_type >=", value, "dataFormatType");
return (Criteria) this;
}
public Criteria andDataFormatTypeLessThan(String value) {
addCriterion("data_format_type <", value, "dataFormatType");
return (Criteria) this;
@@ -1099,6 +1109,76 @@ public class MetricDOExample {
addCriterion("data_format not between", value1, value2, "dataFormat");
return (Criteria) this;
}
public Criteria andAliasIsNull() {
addCriterion("alias is null");
return (Criteria) this;
}
public Criteria andAliasIsNotNull() {
addCriterion("alias is not null");
return (Criteria) this;
}
public Criteria andAliasEqualTo(String value) {
addCriterion("alias =", value, "alias");
return (Criteria) this;
}
public Criteria andAliasNotEqualTo(String value) {
addCriterion("alias <>", value, "alias");
return (Criteria) this;
}
public Criteria andAliasGreaterThan(String value) {
addCriterion("alias >", value, "alias");
return (Criteria) this;
}
public Criteria andAliasGreaterThanOrEqualTo(String value) {
addCriterion("alias >=", value, "alias");
return (Criteria) this;
}
public Criteria andAliasLessThan(String value) {
addCriterion("alias <", value, "alias");
return (Criteria) this;
}
public Criteria andAliasLessThanOrEqualTo(String value) {
addCriterion("alias <=", value, "alias");
return (Criteria) this;
}
public Criteria andAliasLike(String value) {
addCriterion("alias like", value, "alias");
return (Criteria) this;
}
public Criteria andAliasNotLike(String value) {
addCriterion("alias not like", value, "alias");
return (Criteria) this;
}
public Criteria andAliasIn(List<String> values) {
addCriterion("alias in", values, "alias");
return (Criteria) this;
}
public Criteria andAliasNotIn(List<String> values) {
addCriterion("alias not in", values, "alias");
return (Criteria) this;
}
public Criteria andAliasBetween(String value1, String value2) {
addCriterion("alias between", value1, value2, "alias");
return (Criteria) this;
}
public Criteria andAliasNotBetween(String value1, String value2) {
addCriterion("alias not between", value1, value2, "alias");
return (Criteria) this;
}
}
/**
@@ -1132,38 +1212,6 @@ public class MetricDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -1199,5 +1247,37 @@ public class MetricDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -38,13 +38,6 @@ public class ViewInfoDOExample {
oredCriteria = new ArrayList<Criteria>();
}
/**
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* @mbg.generated
*/
@@ -55,8 +48,8 @@ public class ViewInfoDOExample {
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
@@ -66,6 +59,13 @@ public class ViewInfoDOExample {
return distinct;
}
/**
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* @mbg.generated
*/
@@ -117,13 +117,6 @@ public class ViewInfoDOExample {
distinct = false;
}
/**
* @mbg.generated
*/
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
* @mbg.generated
*/
@@ -134,8 +127,8 @@ public class ViewInfoDOExample {
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
public void setLimitStart(Integer limitStart) {
this.limitStart = limitStart;
}
/**
@@ -145,6 +138,13 @@ public class ViewInfoDOExample {
return limitEnd;
}
/**
* @mbg.generated
*/
public void setLimitEnd(Integer limitEnd) {
this.limitEnd = limitEnd;
}
/**
* s2_view_info null
*/
@@ -672,38 +672,6 @@ public class ViewInfoDOExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@@ -739,5 +707,37 @@ public class ViewInfoDOExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@@ -10,66 +10,22 @@ import com.tencent.supersonic.semantic.api.core.pojo.yaml.DimensionYamlTpl;
import com.tencent.supersonic.semantic.api.core.pojo.yaml.IdentifyYamlTpl;
import com.tencent.supersonic.semantic.api.core.pojo.yaml.MeasureYamlTpl;
import com.tencent.supersonic.semantic.api.core.response.DatabaseResp;
import com.tencent.supersonic.semantic.api.core.response.DimensionResp;
import com.tencent.supersonic.common.enums.TypeEnums;
import com.tencent.supersonic.common.util.yaml.YamlUtils;
import com.tencent.supersonic.semantic.core.domain.utils.SysTimeDimensionBuilder;
import com.tencent.supersonic.semantic.core.domain.adaptor.engineadapter.EngineAdaptor;
import com.tencent.supersonic.semantic.core.domain.adaptor.engineadapter.EngineAdaptorFactory;
import com.tencent.supersonic.semantic.core.domain.pojo.Datasource;
import com.tencent.supersonic.semantic.core.domain.pojo.DatasourceQueryEnum;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@Service
@Slf4j
public class DatasourceYamlManager {
private YamlManager yamlManager;
public DatasourceYamlManager(YamlManager yamlManager) {
this.yamlManager = yamlManager;
}
public void generateYamlFile(Datasource datasource, DatabaseResp databaseResp, String fullPath,
List<DimensionResp> dimensionDescsExist) throws Exception {
if (!CollectionUtils.isEmpty(dimensionDescsExist)) {
List<String> dimensionBizNames = dimensionDescsExist.stream().map(DimensionResp::getBizName)
.collect(Collectors.toList());
datasource.getDatasourceDetail().getDimensions()
.removeIf(dim -> dimensionBizNames.contains(dim.getBizName()));
}
String yamlStr = convert2YamlStr(datasource, databaseResp);
log.info("generate yaml str :{} from datasource:{} full path:{}", yamlStr, datasource, fullPath);
yamlManager.generateYamlFile(yamlStr, fullPath, getYamlName(datasource.getBizName()));
}
public void deleteYamlFile(String datasourceBizName, String fullPath) throws Exception {
log.info("delete datasource yaml :{} ,fullPath:{}", datasourceBizName, fullPath);
yamlManager.deleteYamlFile(fullPath, getYamlName(datasourceBizName));
}
public String getYamlName(String name) {
return String.format("%s_%s", name, TypeEnums.DATASOURCE.getName());
}
public static String convert2YamlStr(Datasource datasource, DatabaseResp databaseResp) {
DatasourceYamlTpl datasourceYamlTpl = convert2YamlObj(datasource, databaseResp);
Map<String, Object> rootMap = new HashMap<>();
rootMap.put("data_source", datasourceYamlTpl);
return YamlUtils.toYamlWithoutNull(rootMap);
}
public static DatasourceYamlTpl convert2YamlObj(Datasource datasource, DatabaseResp databaseResp) {
DatasourceDetail datasourceDetail = datasource.getDatasourceDetail();
EngineAdaptor engineAdaptor = EngineAdaptorFactory.getEngineAdaptor(databaseResp.getType());

View File

@@ -21,44 +21,6 @@ import org.springframework.util.CollectionUtils;
public class DimensionYamlManager {
private YamlManager yamlManager;
public DimensionYamlManager(YamlManager yamlManager) {
this.yamlManager = yamlManager;
}
public void generateYamlFile(List<Dimension> dimensions, String fullPath, String datasourceBizName)
throws Exception {
String yamlStr = convert2YamlStr(dimensions, datasourceBizName);
log.info("generate yaml str :{} from metric:{} full path:{}", yamlStr, dimensions, fullPath);
yamlManager.generateYamlFile(yamlStr, fullPath, getYamlName(datasourceBizName));
}
public String getYamlName(String name) {
return String.format("%s_%s", name, TypeEnums.DIMENSION.getName());
}
public static String convert2YamlStr(List<Dimension> dimensions, String datasourceBizName) {
if (CollectionUtils.isEmpty(dimensions)) {
return "";
}
List<DimensionYamlTpl> dimensionYamlTpls = dimensions.stream()
.filter(dimension -> !dimension.getType().equalsIgnoreCase("primary"))
.map(DimensionConverter::convert2DimensionYamlTpl).collect(Collectors.toList());
if (CollectionUtils.isEmpty(dimensionYamlTpls)) {
return "";
}
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("source", datasourceBizName);
dataMap.put("dimensions", dimensionYamlTpls);
Map<String, Object> rootMap = new HashMap<>();
rootMap.put("dimension", dataMap);
return YamlUtils.toYamlWithoutNull(rootMap);
}
public static List<DimensionYamlTpl> convert2DimensionYaml(List<Dimension> dimensions) {
if (CollectionUtils.isEmpty(dimensions)) {
return new ArrayList<>();

View File

@@ -1,17 +1,12 @@
package com.tencent.supersonic.semantic.core.domain.manager;
import com.tencent.supersonic.semantic.api.core.pojo.yaml.MetricYamlTpl;
import com.tencent.supersonic.common.enums.TypeEnums;
import com.tencent.supersonic.common.util.yaml.YamlUtils;
import com.tencent.supersonic.semantic.core.domain.pojo.Metric;
import com.tencent.supersonic.semantic.core.domain.utils.MetricConverter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@Slf4j
@@ -19,37 +14,6 @@ import org.springframework.util.CollectionUtils;
public class MetricYamlManager {
private YamlManager yamlManager;
public MetricYamlManager(YamlManager yamlManager) {
this.yamlManager = yamlManager;
}
public void generateYamlFile(List<Metric> metrics, String fullPath, String domainBizName) throws Exception {
String yamlStr = convert2YamlStr(metrics);
log.info("generate yaml str :{} from metric:{} full path:{}", yamlStr, metrics, fullPath);
yamlManager.generateYamlFile(yamlStr, fullPath, getYamlName(domainBizName));
}
public String getYamlName(String name) {
return String.format("%s_%s", name, TypeEnums.METRIC.getName());
}
public static String convert2YamlStr(List<Metric> metrics) {
if (CollectionUtils.isEmpty(metrics)) {
return "";
}
StringBuilder yamlBuilder = new StringBuilder();
for (Metric metric : metrics) {
MetricYamlTpl metricYamlTpl = MetricConverter.convert2MetricYamlTpl(metric);
Map<String, Object> rootMap = new HashMap<>();
rootMap.put("metric", metricYamlTpl);
yamlBuilder.append(YamlUtils.toYamlWithoutNull(rootMap)).append("\n");
}
return yamlBuilder.toString();
}
public static List<MetricYamlTpl> convert2YamlObj(List<Metric> metrics) {
List<MetricYamlTpl> metricYamlTpls = new ArrayList<>();

View File

@@ -1,66 +0,0 @@
package com.tencent.supersonic.semantic.core.domain.manager;
import com.tencent.supersonic.common.constant.Constants;
import com.tencent.supersonic.semantic.core.domain.config.YamlConfig;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class YamlManager {
protected final YamlConfig yamlConfig;
// private final ParserService parserService;
public YamlManager(YamlConfig yamlConfig
// , @Lazy ParserService parserService
) {
this.yamlConfig = yamlConfig;
// this.parserService = parserService;
}
public void generateYamlFile(String yamlStr, String path, String name) throws Exception {
String localPath = generateLocalYamlPath(path, name);
File file = createMetaYamlFile(localPath);
FileUtils.writeStringToFile(file, yamlStr, StandardCharsets.UTF_8);
// parserService.reloadModels(path);
}
public void deleteYamlFile(String path, String fileName) {
String localPath = generateLocalYamlPath(path, fileName);
deleteMetaYamlFile(localPath);
}
private File createMetaYamlFile(String fullPath) throws IOException {
File file = new File(fullPath);
if (file.getParentFile().mkdirs() && file.createNewFile()) {
log.info("File :{} created: " + fullPath);
} else {
log.warn("File:{} create failed.", fullPath);
}
return file;
}
private void deleteMetaYamlFile(String fullPath) {
File file = new File(fullPath);
if (file.delete()) {
log.info("File :{} deleted: " + fullPath);
} else {
log.info("File :{} delete failed: " + fullPath);
}
}
private String generateLocalYamlPath(String path, String name) {
return yamlConfig.getmetaYamlFileDir() + path + name + Constants.YAML_FILES_SUFFIX;
}
}

View File

@@ -3,7 +3,7 @@ package com.tencent.supersonic.semantic.core.domain.pojo;
import com.tencent.supersonic.common.pojo.SchemaItem;
import lombok.Data;
import java.util.List;
@Data
public class Dimension extends SchemaItem {
@@ -15,9 +15,12 @@ public class Dimension extends SchemaItem {
private Long domainId;
private Long datasourceId;
private String semanticType;
private String alias;
private List<String> defaultValues;
}

View File

@@ -29,42 +29,9 @@ import org.springframework.stereotype.Component;
@Component
public class JdbcDataSource {
@Bean(name = "wallConfig")
WallConfig wallConfig() {
WallConfig config = new WallConfig();
config.setDeleteAllow(false);
config.setUpdateAllow(false);
config.setInsertAllow(false);
config.setReplaceAllow(false);
config.setMergeAllow(false);
config.setTruncateAllow(false);
config.setCreateTableAllow(false);
config.setAlterTableAllow(false);
config.setDropTableAllow(false);
config.setCommentAllow(true);
config.setUseAllow(false);
config.setDescribeAllow(false);
config.setShowAllow(false);
config.setSelectWhereAlwayTrueCheck(false);
config.setSelectHavingAlwayTrueCheck(false);
config.setSelectUnionCheck(false);
config.setConditionDoubleConstAllow(true);
config.setConditionAndAlwayTrueAllow(true);
config.setConditionAndAlwayFalseAllow(true);
return config;
}
@Bean(name = "wallFilter")
@DependsOn("wallConfig")
WallFilter wallFilter(WallConfig wallConfig) {
WallFilter wfilter = new WallFilter();
wfilter.setConfig(wallConfig);
return wfilter;
}
@Autowired
WallFilter wallFilter;
private static final Object lockLock = new Object();
private static volatile Map<String, DruidDataSource> dataSourceMap = new ConcurrentHashMap<>();
private static volatile Map<String, Lock> dataSourceLockMap = new ConcurrentHashMap<>();
@Value("${source.lock-time:30}")
@Getter
protected Long lockTime;
@@ -136,10 +103,41 @@ public class JdbcDataSource {
@Value("${source.filters:'stat'}")
@Getter
protected String filters;
@Autowired
WallFilter wallFilter;
private static volatile Map<String, DruidDataSource> dataSourceMap = new ConcurrentHashMap<>();
private static volatile Map<String, Lock> dataSourceLockMap = new ConcurrentHashMap<>();
private static final Object lockLock = new Object();
@Bean(name = "wallConfig")
WallConfig wallConfig() {
WallConfig config = new WallConfig();
config.setDeleteAllow(false);
config.setUpdateAllow(false);
config.setInsertAllow(false);
config.setReplaceAllow(false);
config.setMergeAllow(false);
config.setTruncateAllow(false);
config.setCreateTableAllow(false);
config.setAlterTableAllow(false);
config.setDropTableAllow(false);
config.setCommentAllow(true);
config.setUseAllow(false);
config.setDescribeAllow(false);
config.setShowAllow(false);
config.setSelectWhereAlwayTrueCheck(false);
config.setSelectHavingAlwayTrueCheck(false);
config.setSelectUnionCheck(false);
config.setConditionDoubleConstAllow(true);
config.setConditionAndAlwayTrueAllow(true);
config.setConditionAndAlwayFalseAllow(true);
return config;
}
@Bean(name = "wallFilter")
@DependsOn("wallConfig")
WallFilter wallFilter(WallConfig wallConfig) {
WallFilter wfilter = new WallFilter();
wfilter.setConfig(wallConfig);
return wfilter;
}
private Lock getDataSourceLock(String key) {
if (dataSourceLockMap.containsKey(key)) {

View File

@@ -21,4 +21,6 @@ public class Metric extends SchemaItem {
private DataFormat dataFormat;
private String alias;
}

View File

@@ -18,6 +18,8 @@ public interface DimensionRepository {
List<DimensionDO> getDimensionListOfDomain(Long domainId);
List<DimensionDO> getDimensionList();
List<DimensionDO> getDimensionListByIds(List<Long> ids);
DimensionDO getDimensionById(Long id);

View File

@@ -17,6 +17,8 @@ public interface MetricRepository {
List<MetricDO> getMetricList(Long domainId);
List<MetricDO> getMetricList();
List<MetricDO> getMetricListByIds(List<Long> ids);
MetricDO getMetricById(Long id);

View File

@@ -3,6 +3,7 @@ package com.tencent.supersonic.semantic.core.domain.utils;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.semantic.api.core.enums.MetricTypeEnum;
import com.tencent.supersonic.semantic.api.core.pojo.DatasourceDetail;
import com.tencent.supersonic.semantic.api.core.pojo.Dim;
import com.tencent.supersonic.semantic.api.core.pojo.Identify;
@@ -111,16 +112,17 @@ public class DatasourceConverter {
public static MetricReq convert(Measure measure, Datasource datasource) {
measure.setDatasourceId(datasource.getId());
MetricReq exprMetricReq = new MetricReq();
exprMetricReq.setName(measure.getName());
exprMetricReq.setBizName(measure.getBizName().replace(datasource.getBizName() + "_", ""));
exprMetricReq.setDescription(measure.getName());
exprMetricReq.setDomainId(datasource.getDomainId());
MetricReq metricReq = new MetricReq();
metricReq.setName(measure.getName());
metricReq.setBizName(measure.getBizName().replace(datasource.getBizName() + "_", ""));
metricReq.setDescription(measure.getName());
metricReq.setDomainId(datasource.getDomainId());
metricReq.setMetricType(MetricTypeEnum.ATOMIC);
MetricTypeParams exprTypeParams = new MetricTypeParams();
exprTypeParams.setExpr(measure.getBizName());
exprTypeParams.setMeasures(Lists.newArrayList(measure));
exprMetricReq.setTypeParams(exprTypeParams);
return exprMetricReq;
metricReq.setTypeParams(exprTypeParams);
return metricReq;
}
public static DimensionReq convert(Identify identify, Datasource datasource) {

View File

@@ -1,5 +1,6 @@
package com.tencent.supersonic.semantic.core.domain.utils;
import com.alibaba.fastjson.JSONObject;
import com.tencent.supersonic.semantic.api.core.pojo.yaml.DimensionYamlTpl;
import com.tencent.supersonic.semantic.api.core.request.DimensionReq;
import com.tencent.supersonic.semantic.api.core.response.DatasourceResp;
@@ -22,36 +23,34 @@ public class DimensionConverter {
public static DimensionDO convert(DimensionDO dimensionDO, Dimension dimension) {
BeanMapper.mapper(dimension, dimensionDO);
dimensionDO.setDefaultValues(JSONObject.toJSONString(dimension.getDefaultValues()));
return dimensionDO;
}
public static DimensionDO convert2DimensionDO(Dimension dimension) {
DimensionDO dimensionDO = new DimensionDO();
BeanUtils.copyProperties(dimension, dimensionDO);
dimensionDO.setDefaultValues(JSONObject.toJSONString(dimension.getDefaultValues()));
return dimensionDO;
}
public static DimensionResp convert2DimensionDesc(DimensionDO dimensionDO,
public static DimensionResp convert2DimensionResp(DimensionDO dimensionDO,
Map<Long, String> fullPathMap,
Map<Long, DatasourceResp> datasourceDescMap
) {
DimensionResp dimensionDesc = new DimensionResp();
BeanUtils.copyProperties(dimensionDO, dimensionDesc);
dimensionDesc.setFullPath(fullPathMap.get(dimensionDO.getDomainId()) + dimensionDO.getBizName());
dimensionDesc.setDatasourceId(
datasourceDescMap.getOrDefault(dimensionDesc.getDatasourceId(), new DatasourceResp()).getId());
dimensionDesc.setDatasourceName(
datasourceDescMap.getOrDefault(dimensionDesc.getDatasourceId(), new DatasourceResp()).getName());
dimensionDesc.setDatasourceBizName(
datasourceDescMap.getOrDefault(dimensionDesc.getDatasourceId(), new DatasourceResp()).getBizName());
return dimensionDesc;
}
public static Dimension convert2Dimension(DimensionDO dimensionDO) {
Dimension dimension = new Dimension();
BeanUtils.copyProperties(dimensionDO, dimension);
return dimension;
Map<Long, DatasourceResp> datasourceRespMap) {
DimensionResp dimensionResp = new DimensionResp();
BeanUtils.copyProperties(dimensionDO, dimensionResp);
dimensionResp.setFullPath(fullPathMap.get(dimensionDO.getDomainId()) + dimensionDO.getBizName());
dimensionResp.setDatasourceId(
datasourceRespMap.getOrDefault(dimensionResp.getDatasourceId(), new DatasourceResp()).getId());
dimensionResp.setDatasourceName(
datasourceRespMap.getOrDefault(dimensionResp.getDatasourceId(), new DatasourceResp()).getName());
dimensionResp.setDatasourceBizName(
datasourceRespMap.getOrDefault(dimensionResp.getDatasourceId(), new DatasourceResp()).getBizName());
if (dimensionDO.getDefaultValues() != null) {
dimensionResp.setDefaultValues(JSONObject.parseObject(dimensionDO.getDefaultValues(), List.class));
}
return dimensionResp;
}

View File

@@ -4,12 +4,15 @@ package com.tencent.supersonic.semantic.core.domain.utils;
import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.semantic.api.core.request.DomainReq;
import com.tencent.supersonic.semantic.api.core.response.DimensionResp;
import com.tencent.supersonic.semantic.api.core.response.DomainResp;
import com.tencent.supersonic.common.enums.StatusEnum;
import com.tencent.supersonic.semantic.api.core.response.MetricResp;
import com.tencent.supersonic.semantic.core.domain.dataobject.DomainDO;
import com.tencent.supersonic.semantic.core.domain.pojo.Domain;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@@ -38,18 +41,26 @@ public class DomainConvert {
}
public static DomainResp convert(DomainDO domainDO, Map<Long, String> domainFullPathMap) {
DomainResp domainDesc = new DomainResp();
BeanUtils.copyProperties(domainDO, domainDesc);
domainDesc.setFullPath(domainFullPathMap.get(domainDO.getId()));
domainDesc.setAdmins(StringUtils.isBlank(domainDO.getAdmin())
DomainResp domainResp = new DomainResp();
BeanUtils.copyProperties(domainDO, domainResp);
domainResp.setFullPath(domainFullPathMap.get(domainDO.getId()));
domainResp.setAdmins(StringUtils.isBlank(domainDO.getAdmin())
? Lists.newArrayList() : Arrays.asList(domainDO.getAdmin().split(",")));
domainDesc.setAdminOrgs(StringUtils.isBlank(domainDO.getAdminOrg())
domainResp.setAdminOrgs(StringUtils.isBlank(domainDO.getAdminOrg())
? Lists.newArrayList() : Arrays.asList(domainDO.getAdminOrg().split(",")));
domainDesc.setViewers(StringUtils.isBlank(domainDO.getViewer())
domainResp.setViewers(StringUtils.isBlank(domainDO.getViewer())
? Lists.newArrayList() : Arrays.asList(domainDO.getViewer().split(",")));
domainDesc.setViewOrgs(StringUtils.isBlank(domainDO.getViewOrg())
domainResp.setViewOrgs(StringUtils.isBlank(domainDO.getViewOrg())
? Lists.newArrayList() : Arrays.asList(domainDO.getViewOrg().split(",")));
return domainDesc;
return domainResp;
}
public static DomainResp convert(DomainDO domainDO, Map<Long, String> domainFullPathMap,
Map<Long, List<DimensionResp>> dimensionMap, Map<Long, List<MetricResp>> metricMap) {
DomainResp domainResp = convert(domainDO, domainFullPathMap);
domainResp.setDimensionCnt(dimensionMap.getOrDefault(domainResp.getId(), Lists.newArrayList()).size());
domainResp.setMetricCnt(metricMap.getOrDefault(domainResp.getId(), Lists.newArrayList()).size());
return domainResp;
}

View File

@@ -29,10 +29,9 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class JdbcDataSourceUtils {
private JdbcDataSource jdbcDataSource;
@Getter
private static Set releaseSourceSet = new HashSet();
private JdbcDataSource jdbcDataSource;
public JdbcDataSourceUtils(JdbcDataSource jdbcDataSource) {
this.jdbcDataSource = jdbcDataSource;
@@ -57,54 +56,6 @@ public class JdbcDataSourceUtils {
return false;
}
public DataSource getDataSource(DatabaseResp databaseResp) throws RuntimeException {
return jdbcDataSource.getDataSource(databaseResp);
}
public Connection getConnection(DatabaseResp databaseResp) throws RuntimeException {
Connection conn = getConnectionWithRetry(databaseResp);
if (conn == null) {
try {
releaseDataSource(databaseResp);
DataSource dataSource = getDataSource(databaseResp);
return dataSource.getConnection();
} catch (Exception e) {
log.error("Get connection error, jdbcUrl:{}, e:{}", databaseResp.getUrl(), e);
throw new RuntimeException("Get connection error, jdbcUrl:" + databaseResp.getUrl()
+ " you can try again later or reset datasource");
}
}
return conn;
}
private Connection getConnectionWithRetry(DatabaseResp databaseResp) {
int rc = 1;
for (; ; ) {
if (rc > 3) {
return null;
}
try {
Connection connection = getDataSource(databaseResp).getConnection();
if (connection != null && connection.isValid(5)) {
return connection;
}
} catch (Exception e) {
log.error("e", e);
}
try {
Thread.sleep((long) Math.pow(2, rc) * 1000);
} catch (InterruptedException e) {
log.error("e", e);
}
rc++;
}
}
public static void releaseConnection(Connection connection) {
if (null != connection) {
try {
@@ -177,11 +128,6 @@ public class JdbcDataSourceUtils {
throw new RuntimeException("Not supported data type: jdbcUrl=" + jdbcUrl);
}
public void releaseDataSource(DatabaseResp databaseResp) {
jdbcDataSource.removeDatasource(databaseResp);
}
public static String getKey(String name, String jdbcUrl, String username, String password, String version,
boolean isExt) {
@@ -199,4 +145,55 @@ public class JdbcDataSourceUtils {
return MD5Util.getMD5(sb.toString(), true, 64);
}
public DataSource getDataSource(DatabaseResp databaseResp) throws RuntimeException {
return jdbcDataSource.getDataSource(databaseResp);
}
public Connection getConnection(DatabaseResp databaseResp) throws RuntimeException {
Connection conn = getConnectionWithRetry(databaseResp);
if (conn == null) {
try {
releaseDataSource(databaseResp);
DataSource dataSource = getDataSource(databaseResp);
return dataSource.getConnection();
} catch (Exception e) {
log.error("Get connection error, jdbcUrl:{}, e:{}", databaseResp.getUrl(), e);
throw new RuntimeException("Get connection error, jdbcUrl:" + databaseResp.getUrl()
+ " you can try again later or reset datasource");
}
}
return conn;
}
private Connection getConnectionWithRetry(DatabaseResp databaseResp) {
int rc = 1;
for (; ; ) {
if (rc > 3) {
return null;
}
try {
Connection connection = getDataSource(databaseResp).getConnection();
if (connection != null && connection.isValid(5)) {
return connection;
}
} catch (Exception e) {
log.error("e", e);
}
try {
Thread.sleep((long) Math.pow(2, rc) * 1000);
} catch (InterruptedException e) {
log.error("e", e);
}
rc++;
}
}
public void releaseDataSource(DatabaseResp databaseResp) {
jdbcDataSource.removeDatasource(databaseResp);
}
}

View File

@@ -26,7 +26,7 @@ public class MetricConverter {
public static Metric convert(MetricReq metricReq) {
Metric metric = new Metric();
BeanUtils.copyProperties(metricReq, metric);
metric.setType(MetricTypeEnum.EXPR.getName());
metric.setType(metricReq.getMetricType().name());
metric.setTypeParams(metricReq.getTypeParams());
return metric;
}
@@ -75,7 +75,7 @@ public class MetricConverter {
return metric;
}
public static MetricYamlTpl convert2MetricYamlTpl(Metric metric) {
MetricYamlTpl metricYamlTpl = new MetricYamlTpl();
BeanUtils.copyProperties(metric, metricYamlTpl);

View File

@@ -47,6 +47,15 @@ public class SqlUtils {
@Getter
private JdbcDataSourceUtils jdbcDataSourceUtils;
public SqlUtils() {
}
public SqlUtils(DatabaseResp databaseResp) {
this.databaseResp = databaseResp;
this.dataTypeEnum = DataTypeEnum.urlOf(databaseResp.getUrl());
}
public SqlUtils init(DatabaseResp databaseResp) {
//todo Password decryption
return SqlUtilsBuilder
@@ -62,16 +71,6 @@ public class SqlUtils {
.build();
}
public SqlUtils() {
}
public SqlUtils(DatabaseResp databaseResp) {
this.databaseResp = databaseResp;
this.dataTypeEnum = DataTypeEnum.urlOf(databaseResp.getUrl());
}
public List<Map<String, Object>> execute(String sql) throws ServerException {
try {
List<Map<String, Object>> list = jdbcTemplate().queryForList(sql);
@@ -97,7 +96,6 @@ public class SqlUtils {
JdbcDataSourceUtils.releaseConnection(connection);
}
DataSource dataSource = jdbcDataSourceUtils.getDataSource(databaseResp);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.setDatabaseProductName(databaseResp.getName());
jdbcTemplate.setFetchSize(500);
@@ -232,4 +230,4 @@ public class SqlUtils {
return sqlUtils;
}
}
}
}

View File

@@ -23,7 +23,7 @@ public class SysTimeDimensionBuilder {
dims.add(generateSysDayDimension(timeDim, engineAdaptor));
dims.add(generateSysWeekDimension(timeDim, engineAdaptor));
dims.add(generateSysMonthDimension(timeDim, engineAdaptor));
log.info("addSysTimeDimension after:{}, engineAdaptor:{}", dims, engineAdaptor);
log.debug("addSysTimeDimension after:{}, engineAdaptor:{}", dims, engineAdaptor);
}

View File

@@ -3,9 +3,9 @@ package com.tencent.supersonic.semantic.core.infrastructure.mapper;
import com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO;
import com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface DimensionDOMapper {
@@ -59,4 +59,4 @@ public interface DimensionDOMapper {
* @mbg.generated
*/
int updateByPrimaryKey(DimensionDO record);
}
}

View File

@@ -48,4 +48,4 @@ public interface DomainDOMapper {
* @mbg.generated
*/
int updateByPrimaryKey(DomainDO record);
}
}

View File

@@ -53,7 +53,7 @@ public class DatasourceRepositoryImpl implements DatasourceRepository {
public DatasourceDO getDatasourceById(Long id) {
return datasourceMapper.selectByPrimaryKey(id);
}
@Override
public void deleteDatasource(Long id) {
datasourceMapper.deleteByPrimaryKey(id);

View File

@@ -56,6 +56,12 @@ public class DimensionRepositoryImpl implements DimensionRepository {
return dimensionDOMapper.selectByExampleWithBLOBs(dimensionDOExample);
}
@Override
public List<DimensionDO> getDimensionList() {
DimensionDOExample dimensionDOExample = new DimensionDOExample();
return dimensionDOMapper.selectByExampleWithBLOBs(dimensionDOExample);
}
@Override
public List<DimensionDO> getDimensionListByIds(List<Long> ids) {
DimensionDOExample dimensionDOExample = new DimensionDOExample();
@@ -86,7 +92,7 @@ public class DimensionRepositoryImpl implements DimensionRepository {
dimensionDOExample.getOredCriteria().get(0).andNameLike("%" + dimensionFilter.getName() + "%");
}
if (dimensionFilter.getBizName() != null) {
dimensionDOExample.getOredCriteria().get(0).andBizNameEqualTo("%" + dimensionFilter.getBizName() + "%");
dimensionDOExample.getOredCriteria().get(0).andBizNameLike("%" + dimensionFilter.getBizName() + "%");
}
if (dimensionFilter.getCreatedBy() != null) {
dimensionDOExample.getOredCriteria().get(0).andCreatedByEqualTo(dimensionFilter.getCreatedBy());
@@ -94,6 +100,9 @@ public class DimensionRepositoryImpl implements DimensionRepository {
if (dimensionFilter.getDomainId() != null) {
dimensionDOExample.getOredCriteria().get(0).andDomainIdEqualTo(dimensionFilter.getDomainId());
}
if (dimensionFilter.getSensitiveLevel() != null) {
dimensionDOExample.getOredCriteria().get(0).andSensitiveLevelEqualTo(dimensionFilter.getSensitiveLevel());
}
return dimensionDOMapper.selectByExampleWithBLOBs(dimensionDOExample);
}

View File

@@ -5,10 +5,13 @@ import com.tencent.supersonic.semantic.core.domain.dataobject.DomainDOExample;
import com.tencent.supersonic.semantic.core.domain.repository.DomainRepository;
import com.tencent.supersonic.semantic.core.infrastructure.mapper.DomainDOMapper;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DomainRepositoryImpl implements DomainRepository {
private DomainDOMapper domainDOMapper;

View File

@@ -48,6 +48,12 @@ public class MetricRepositoryImpl implements MetricRepository {
return metricDOMapper.selectByExampleWithBLOBs(metricDOExample);
}
@Override
public List<MetricDO> getMetricList() {
MetricDOExample metricDOExample = new MetricDOExample();
return metricDOMapper.selectByExampleWithBLOBs(metricDOExample);
}
@Override
public List<MetricDO> getMetricListByIds(List<Long> ids) {
MetricDOExample metricDOExample = new MetricDOExample();

View File

@@ -59,5 +59,24 @@ public class DatabaseController {
return databaseService.executeSql(sqlExecuteReq.getSql(), sqlExecuteReq.getDomainId());
}
@RequestMapping("/getDbNames/{id}")
public QueryResultWithSchemaResp getDbNames(@PathVariable("id") Long id) {
return databaseService.getDbNames(id);
}
@RequestMapping("/getTables/{id}/{db}")
public QueryResultWithSchemaResp getTables(@PathVariable("id") Long id,
@PathVariable("db") String db) {
return databaseService.getTables(id, db);
}
@RequestMapping("/getColumns/{id}/{db}/{table}")
public QueryResultWithSchemaResp getColumns(@PathVariable("id") Long id,
@PathVariable("db") String db,
@PathVariable("table") String table) {
return databaseService.getColumns(id, db, table);
}
}

View File

@@ -32,7 +32,7 @@ public class ViewInfoController {
@PostMapping("/createOrUpdateViewInfo")
public ViewInfoDO createOrUpdateViewInfo(@RequestBody ViewInfoReq viewInfoReq, HttpServletRequest request,
HttpServletResponse response) {
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return viewInfoServiceImpl.createOrUpdateViewInfo(viewInfoReq, user);
}

View File

@@ -1,338 +1,341 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tencent.supersonic.semantic.core.infrastructure.mapper.DimensionDOMapper">
<resultMap id="BaseResultMap"
type="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="domain_id" jdbcType="BIGINT" property="domainId"/>
<result column="datasource_id" jdbcType="BIGINT" property="datasourceId"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="biz_name" jdbcType="VARCHAR" property="bizName"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="sensitive_level" jdbcType="INTEGER" property="sensitiveLevel"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
<result column="semantic_type" jdbcType="VARCHAR" property="semanticType"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs"
type="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams"/>
<result column="expr" jdbcType="LONGVARCHAR" property="expr"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and
#{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem"
open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
<resultMap id="BaseResultMap" type="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="domain_id" jdbcType="BIGINT" property="domainId" />
<result column="datasource_id" jdbcType="BIGINT" property="datasourceId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="biz_name" jdbcType="VARCHAR" property="bizName" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="sensitive_level" jdbcType="INTEGER" property="sensitiveLevel" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="semantic_type" jdbcType="VARCHAR" property="semanticType" />
<result column="alias" jdbcType="VARCHAR" property="alias" />
<result column="default_values" jdbcType="VARCHAR" property="defaultValues" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams" />
<result column="expr" jdbcType="LONGVARCHAR" property="expr" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id
, domain_id, datasource_id, name, biz_name, description, status, sensitive_level,
type, created_at, created_by, updated_at, updated_by, semantic_type
</sql>
<sql id="Blob_Column_List">
type_params
, expr
</sql>
<select id="selectByExampleWithBLOBs"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample"
resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</trim>
</if>
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from s2_dimension
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample"
resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from s2_dimension
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limitStart != null and limitStart>=0">
limit #{limitStart} , #{limitEnd}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from s2_dimension
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from s2_dimension
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
insert into s2_dimension (id, domain_id, datasource_id,
name, biz_name, description,
status, sensitive_level, type,
created_at, created_by, updated_at,
updated_by, semantic_type, type_params,
expr)
values (#{id,jdbcType=BIGINT}, #{domainId,jdbcType=BIGINT}, #{datasourceId,jdbcType=BIGINT},
#{name,jdbcType=VARCHAR}, #{bizName,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{sensitiveLevel,jdbcType=INTEGER},
#{type,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR},
#{updatedAt,jdbcType=TIMESTAMP},
#{updatedBy,jdbcType=VARCHAR}, #{semanticType,jdbcType=VARCHAR},
#{typeParams,jdbcType=LONGVARCHAR},
#{expr,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
insert into s2_dimension
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="domainId != null">
domain_id,
</if>
<if test="datasourceId != null">
datasource_id,
</if>
<if test="name != null">
name,
</if>
<if test="bizName != null">
biz_name,
</if>
<if test="description != null">
description,
</if>
<if test="status != null">
status,
</if>
<if test="sensitiveLevel != null">
sensitive_level,
</if>
<if test="type != null">
type,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="createdBy != null">
created_by,
</if>
<if test="updatedAt != null">
updated_at,
</if>
<if test="updatedBy != null">
updated_by,
</if>
<if test="semanticType != null">
semantic_type,
</if>
<if test="typeParams != null">
type_params,
</if>
<if test="expr != null">
expr,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="domainId != null">
#{domainId,jdbcType=BIGINT},
</if>
<if test="datasourceId != null">
#{datasourceId,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
#{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
#{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
#{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
#{updatedBy,jdbcType=VARCHAR},
</if>
<if test="semanticType != null">
#{semanticType,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
#{typeParams,jdbcType=LONGVARCHAR},
</if>
<if test="expr != null">
#{expr,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample"
resultType="java.lang.Long">
select count(*) from s2_dimension
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByPrimaryKeySelective"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
update s2_dimension
<set>
<if test="domainId != null">
domain_id = #{domainId,jdbcType=BIGINT},
</if>
<if test="datasourceId != null">
datasource_id = #{datasourceId,jdbcType=BIGINT},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
biz_name = #{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
created_by = #{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
updated_by = #{updatedBy,jdbcType=VARCHAR},
</if>
<if test="semanticType != null">
semantic_type = #{semanticType,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
type_params = #{typeParams,jdbcType=LONGVARCHAR},
</if>
<if test="expr != null">
expr = #{expr,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
update s2_dimension
set domain_id = #{domainId,jdbcType=BIGINT},
datasource_id = #{datasourceId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
semantic_type = #{semanticType,jdbcType=VARCHAR},
type_params = #{typeParams,jdbcType=LONGVARCHAR},
expr = #{expr,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
update s2_dimension
set domain_id = #{domainId,jdbcType=BIGINT},
datasource_id = #{datasourceId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
semantic_type = #{semanticType,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, domain_id, datasource_id, name, biz_name, description, status, sensitive_level,
type, created_at, created_by, updated_at, updated_by, semantic_type, alias, default_values
</sql>
<sql id="Blob_Column_List">
type_params, expr
</sql>
<select id="selectByExampleWithBLOBs" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample" resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from s2_dimension
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from s2_dimension
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limitStart != null and limitStart>=0">
limit #{limitStart} , #{limitEnd}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from s2_dimension
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from s2_dimension
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
insert into s2_dimension (id, domain_id, datasource_id,
name, biz_name, description,
status, sensitive_level, type,
created_at, created_by, updated_at,
updated_by, semantic_type, alias,
default_values, type_params, expr
)
values (#{id,jdbcType=BIGINT}, #{domainId,jdbcType=BIGINT}, #{datasourceId,jdbcType=BIGINT},
#{name,jdbcType=VARCHAR}, #{bizName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER}, #{sensitiveLevel,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP},
#{updatedBy,jdbcType=VARCHAR}, #{semanticType,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR},
#{defaultValues,jdbcType=VARCHAR}, #{typeParams,jdbcType=LONGVARCHAR}, #{expr,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
insert into s2_dimension
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="domainId != null">
domain_id,
</if>
<if test="datasourceId != null">
datasource_id,
</if>
<if test="name != null">
name,
</if>
<if test="bizName != null">
biz_name,
</if>
<if test="description != null">
description,
</if>
<if test="status != null">
status,
</if>
<if test="sensitiveLevel != null">
sensitive_level,
</if>
<if test="type != null">
type,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="createdBy != null">
created_by,
</if>
<if test="updatedAt != null">
updated_at,
</if>
<if test="updatedBy != null">
updated_by,
</if>
<if test="semanticType != null">
semantic_type,
</if>
<if test="alias != null">
alias,
</if>
<if test="defaultValues != null">
default_values,
</if>
<if test="typeParams != null">
type_params,
</if>
<if test="expr != null">
expr,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="domainId != null">
#{domainId,jdbcType=BIGINT},
</if>
<if test="datasourceId != null">
#{datasourceId,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
#{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
#{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
#{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
#{updatedBy,jdbcType=VARCHAR},
</if>
<if test="semanticType != null">
#{semanticType,jdbcType=VARCHAR},
</if>
<if test="alias != null">
#{alias,jdbcType=VARCHAR},
</if>
<if test="defaultValues != null">
#{defaultValues,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
#{typeParams,jdbcType=LONGVARCHAR},
</if>
<if test="expr != null">
#{expr,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDOExample" resultType="java.lang.Long">
select count(*) from s2_dimension
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
update s2_dimension
<set>
<if test="domainId != null">
domain_id = #{domainId,jdbcType=BIGINT},
</if>
<if test="datasourceId != null">
datasource_id = #{datasourceId,jdbcType=BIGINT},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
biz_name = #{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
created_by = #{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
updated_by = #{updatedBy,jdbcType=VARCHAR},
</if>
<if test="semanticType != null">
semantic_type = #{semanticType,jdbcType=VARCHAR},
</if>
<if test="alias != null">
alias = #{alias,jdbcType=VARCHAR},
</if>
<if test="defaultValues != null">
default_values = #{defaultValues,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
type_params = #{typeParams,jdbcType=LONGVARCHAR},
</if>
<if test="expr != null">
expr = #{expr,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
update s2_dimension
set domain_id = #{domainId,jdbcType=BIGINT},
datasource_id = #{datasourceId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
semantic_type = #{semanticType,jdbcType=VARCHAR},
alias = #{alias,jdbcType=VARCHAR},
default_values = #{defaultValues,jdbcType=VARCHAR},
type_params = #{typeParams,jdbcType=LONGVARCHAR},
expr = #{expr,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.DimensionDO">
update s2_dimension
set domain_id = #{domainId,jdbcType=BIGINT},
datasource_id = #{datasourceId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
semantic_type = #{semanticType,jdbcType=VARCHAR},
alias = #{alias,jdbcType=VARCHAR},
default_values = #{defaultValues,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

View File

@@ -1,324 +1,316 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tencent.supersonic.semantic.core.infrastructure.mapper.MetricDOMapper">
<resultMap id="BaseResultMap"
type="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
<id column="id" jdbcType="BIGINT" property="id"/>
<result column="domain_id" jdbcType="BIGINT" property="domainId"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="biz_name" jdbcType="VARCHAR" property="bizName"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="sensitive_level" jdbcType="INTEGER" property="sensitiveLevel"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
<result column="data_format_type" jdbcType="VARCHAR" property="dataFormatType"/>
<result column="data_format" jdbcType="VARCHAR" property="dataFormat"/>
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs"
type="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams"/>
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and
#{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem"
open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
<resultMap id="BaseResultMap" type="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="domain_id" jdbcType="BIGINT" property="domainId" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="biz_name" jdbcType="VARCHAR" property="bizName" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="sensitive_level" jdbcType="INTEGER" property="sensitiveLevel" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="data_format_type" jdbcType="VARCHAR" property="dataFormatType" />
<result column="data_format" jdbcType="VARCHAR" property="dataFormat" />
<result column="alias" jdbcType="VARCHAR" property="alias" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id
, domain_id, name, biz_name, description, status, sensitive_level, type, created_at,
created_by, updated_at, updated_by, data_format_type, data_format
</sql>
<sql id="Blob_Column_List">
type_params
</sql>
<select id="selectByExampleWithBLOBs"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDOExample"
resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</trim>
</if>
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from s2_metric
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDOExample"
resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List"/>
from s2_metric
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limitStart != null and limitStart>=0">
limit #{limitStart} , #{limitEnd}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List"/>
,
<include refid="Blob_Column_List"/>
from s2_metric
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from s2_metric
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
insert into s2_metric (id, domain_id, name,
biz_name, description, status,
sensitive_level, type, created_at,
created_by, updated_at, updated_by,
data_format_type, data_format, type_params)
values (#{id,jdbcType=BIGINT}, #{domainId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{bizName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{status,jdbcType=INTEGER},
#{sensitiveLevel,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP},
#{createdBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP},
#{updatedBy,jdbcType=VARCHAR},
#{dataFormatType,jdbcType=VARCHAR}, #{dataFormat,jdbcType=VARCHAR},
#{typeParams,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
insert into s2_metric
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="domainId != null">
domain_id,
</if>
<if test="name != null">
name,
</if>
<if test="bizName != null">
biz_name,
</if>
<if test="description != null">
description,
</if>
<if test="status != null">
status,
</if>
<if test="sensitiveLevel != null">
sensitive_level,
</if>
<if test="type != null">
type,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="createdBy != null">
created_by,
</if>
<if test="updatedAt != null">
updated_at,
</if>
<if test="updatedBy != null">
updated_by,
</if>
<if test="dataFormatType != null">
data_format_type,
</if>
<if test="dataFormat != null">
data_format,
</if>
<if test="typeParams != null">
type_params,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="domainId != null">
#{domainId,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
#{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
#{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
#{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
#{updatedBy,jdbcType=VARCHAR},
</if>
<if test="dataFormatType != null">
#{dataFormatType,jdbcType=VARCHAR},
</if>
<if test="dataFormat != null">
#{dataFormat,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
#{typeParams,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDOExample"
resultType="java.lang.Long">
select count(*) from s2_metric
<if test="_parameter != null">
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByPrimaryKeySelective"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
update s2_metric
<set>
<if test="domainId != null">
domain_id = #{domainId,jdbcType=BIGINT},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
biz_name = #{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
created_by = #{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
updated_by = #{updatedBy,jdbcType=VARCHAR},
</if>
<if test="dataFormatType != null">
data_format_type = #{dataFormatType,jdbcType=VARCHAR},
</if>
<if test="dataFormat != null">
data_format = #{dataFormat,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
type_params = #{typeParams,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
update s2_metric
set domain_id = #{domainId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
data_format_type = #{dataFormatType,jdbcType=VARCHAR},
data_format = #{dataFormat,jdbcType=VARCHAR},
type_params = #{typeParams,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey"
parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
update s2_metric
set domain_id = #{domainId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
data_format_type = #{dataFormatType,jdbcType=VARCHAR},
data_format = #{dataFormat,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, domain_id, name, biz_name, description, status, sensitive_level, type, created_at,
created_by, updated_at, updated_by, data_format_type, data_format, alias
</sql>
<sql id="Blob_Column_List">
type_params
</sql>
<select id="selectByExampleWithBLOBs" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDOExample" resultMap="ResultMapWithBLOBs">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from s2_metric
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDOExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from s2_metric
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limitStart != null and limitStart>=0">
limit #{limitStart} , #{limitEnd}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from s2_metric
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from s2_metric
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
insert into s2_metric (id, domain_id, name,
biz_name, description, status,
sensitive_level, type, created_at,
created_by, updated_at, updated_by,
data_format_type, data_format, alias,
type_params)
values (#{id,jdbcType=BIGINT}, #{domainId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{bizName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{sensitiveLevel,jdbcType=INTEGER}, #{type,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP},
#{createdBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR},
#{dataFormatType,jdbcType=VARCHAR}, #{dataFormat,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR},
#{typeParams,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
insert into s2_metric
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="domainId != null">
domain_id,
</if>
<if test="name != null">
name,
</if>
<if test="bizName != null">
biz_name,
</if>
<if test="description != null">
description,
</if>
<if test="status != null">
status,
</if>
<if test="sensitiveLevel != null">
sensitive_level,
</if>
<if test="type != null">
type,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="createdBy != null">
created_by,
</if>
<if test="updatedAt != null">
updated_at,
</if>
<if test="updatedBy != null">
updated_by,
</if>
<if test="dataFormatType != null">
data_format_type,
</if>
<if test="dataFormat != null">
data_format,
</if>
<if test="alias != null">
alias,
</if>
<if test="typeParams != null">
type_params,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="domainId != null">
#{domainId,jdbcType=BIGINT},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
#{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
#{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
#{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
#{updatedBy,jdbcType=VARCHAR},
</if>
<if test="dataFormatType != null">
#{dataFormatType,jdbcType=VARCHAR},
</if>
<if test="dataFormat != null">
#{dataFormat,jdbcType=VARCHAR},
</if>
<if test="alias != null">
#{alias,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
#{typeParams,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDOExample" resultType="java.lang.Long">
select count(*) from s2_metric
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
update s2_metric
<set>
<if test="domainId != null">
domain_id = #{domainId,jdbcType=BIGINT},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="bizName != null">
biz_name = #{bizName,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="sensitiveLevel != null">
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
</if>
<if test="type != null">
type = #{type,jdbcType=VARCHAR},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="createdBy != null">
created_by = #{createdBy,jdbcType=VARCHAR},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedBy != null">
updated_by = #{updatedBy,jdbcType=VARCHAR},
</if>
<if test="dataFormatType != null">
data_format_type = #{dataFormatType,jdbcType=VARCHAR},
</if>
<if test="dataFormat != null">
data_format = #{dataFormat,jdbcType=VARCHAR},
</if>
<if test="alias != null">
alias = #{alias,jdbcType=VARCHAR},
</if>
<if test="typeParams != null">
type_params = #{typeParams,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
update s2_metric
set domain_id = #{domainId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
data_format_type = #{dataFormatType,jdbcType=VARCHAR},
data_format = #{dataFormat,jdbcType=VARCHAR},
alias = #{alias,jdbcType=VARCHAR},
type_params = #{typeParams,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.tencent.supersonic.semantic.core.domain.dataobject.MetricDO">
update s2_metric
set domain_id = #{domainId,jdbcType=BIGINT},
name = #{name,jdbcType=VARCHAR},
biz_name = #{bizName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
sensitive_level = #{sensitiveLevel,jdbcType=INTEGER},
type = #{type,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
created_by = #{createdBy,jdbcType=VARCHAR},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
updated_by = #{updatedBy,jdbcType=VARCHAR},
data_format_type = #{dataFormatType,jdbcType=VARCHAR},
data_format = #{dataFormat,jdbcType=VARCHAR},
alias = #{alias,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

View File

@@ -32,16 +32,23 @@
</insert>
<select id="getDateInfos" resultMap="BaseResultMap">
select *
select e.*
from s2_available_date_info e
inner join
(
select item_id, max(created_at) as created_at
from s2_available_date_info
where `type` = #{type}
<if test="itemIds != null and itemIds.size >0">
and item_id in
<foreach collection="itemIds" index="index" item="item" open="(" close=")"
separator=",">
separator=",">
#{item}
</foreach>
</if>
group by item_id
) t
on e.item_id=t.item_id and e.created_at=t.created_at
</select>
</mapper>

View File

@@ -12,6 +12,7 @@ import com.tencent.supersonic.semantic.query.domain.parser.dsl.SemanticModel;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -31,7 +32,6 @@ public class ParserServiceImpl implements ParserService {
}
@Override
public SqlParserResp physicalSql(ParseSqlReq sqlCommend) throws Exception {
return parser(sqlCommend);
@@ -107,6 +107,9 @@ public class ParserServiceImpl implements ParserService {
private String formatWhere(String where) {
if (StringUtils.isEmpty(where)) {
return where;
}
return where.replace("\"", "\\\\\"");
}
}

View File

@@ -1,28 +1,31 @@
package com.tencent.supersonic.semantic.query.application;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.enums.TaskStatusEnum;
import com.tencent.supersonic.common.util.cache.CacheUtils;
import com.tencent.supersonic.common.util.context.ContextUtils;
import com.tencent.supersonic.semantic.api.core.pojo.QueryStat;
import com.tencent.supersonic.semantic.api.core.request.DomainSchemaFilterReq;
import com.tencent.supersonic.semantic.api.core.response.DomainSchemaResp;
import com.tencent.supersonic.semantic.api.core.response.QueryResultWithSchemaResp;
import com.tencent.supersonic.semantic.api.core.response.SqlParserResp;
import com.tencent.supersonic.semantic.api.query.pojo.Cache;
import com.tencent.supersonic.semantic.api.query.request.ItemUseReq;
import com.tencent.supersonic.semantic.api.query.request.MetricReq;
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
import com.tencent.supersonic.semantic.api.query.request.QuerySqlReq;
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
import com.tencent.supersonic.semantic.api.query.response.ItemUseResp;
import com.tencent.supersonic.common.enums.TaskStatusEnum;
import com.tencent.supersonic.common.util.cache.CacheUtils;
import com.tencent.supersonic.semantic.core.domain.DatabaseService;
import com.tencent.supersonic.semantic.query.domain.ParserService;
import com.tencent.supersonic.semantic.query.domain.QueryService;
import com.tencent.supersonic.semantic.query.domain.SchemaService;
import com.tencent.supersonic.semantic.query.domain.annotation.DataPermission;
import com.tencent.supersonic.semantic.query.domain.utils.QueryReqConverter;
import com.tencent.supersonic.semantic.query.domain.utils.QueryStructUtils;
import com.tencent.supersonic.semantic.query.domain.utils.StatUtils;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -37,28 +40,37 @@ public class QueryServiceImpl implements QueryService {
private final QueryStructUtils queryStructUtils;
private final StatUtils statUtils;
private final CacheUtils cacheUtils;
private final QueryReqConverter queryReqConverter;
@Value("${query.cache.enable:true}")
private Boolean cacheEnable;
public QueryServiceImpl(ParserService parserService,
DatabaseService databaseService,
QueryStructUtils queryStructUtils,
StatUtils statUtils,
CacheUtils cacheUtils) {
DatabaseService databaseService,
QueryStructUtils queryStructUtils,
StatUtils statUtils,
CacheUtils cacheUtils,
QueryReqConverter queryReqConverter) {
this.parserService = parserService;
this.databaseService = databaseService;
this.queryStructUtils = queryStructUtils;
this.statUtils = statUtils;
this.cacheUtils = cacheUtils;
this.queryReqConverter = queryReqConverter;
}
@Override
public Object queryBySql(QuerySqlReq querySqlCmd) throws Exception {
//TODO QuerySqlCmd---> SqlCommend
MetricReq sqlCommend = new MetricReq();
public Object queryBySql(QuerySqlReq querySqlCmd, User user) throws Exception {
DomainSchemaFilterReq filter = new DomainSchemaFilterReq();
List<Long> domainIds = new ArrayList<>();
domainIds.add(querySqlCmd.getDomainId());
filter.setDomainIds(domainIds);
SchemaService schemaService = ContextUtils.getBean(SchemaService.class);
List<DomainSchemaResp> domainSchemas = schemaService.fetchDomainSchema(filter, user);
SqlParserResp sqlParser = queryReqConverter.convert(querySqlCmd, domainSchemas);
SqlParserResp sqlParser = parserService.physicalSql(sqlCommend);
return databaseService.executeSql(sqlParser.getSql(), querySqlCmd.getDomainId());
}
@@ -128,5 +140,4 @@ public class QueryServiceImpl implements QueryService {
}
}

View File

@@ -38,9 +38,9 @@ public class SchemaServiceImpl implements SchemaService {
private final MetricService metricService;
public SchemaServiceImpl(QueryService queryService,
DomainService domainService,
DimensionService dimensionService,
MetricService metricService) {
DomainService domainService,
DimensionService dimensionService,
MetricService metricService) {
this.queryService = queryService;
this.domainService = domainService;
this.dimensionService = dimensionService;
@@ -52,7 +52,7 @@ public class SchemaServiceImpl implements SchemaService {
public List<DomainSchemaResp> fetchDomainSchema(DomainSchemaFilterReq filter, User user) {
List<DomainSchemaResp> domainSchemaDescList = domainService.fetchDomainSchema(filter, user);
List<ItemUseResp> statInfos = queryService.getStatInfo(new ItemUseReq());
log.info("statInfos:{}", statInfos);
log.debug("statInfos:{}", statInfos);
fillCnt(domainSchemaDescList, statInfos);
return domainSchemaDescList;
@@ -66,7 +66,7 @@ public class SchemaServiceImpl implements SchemaService {
itemUseInfo -> itemUseInfo.getType() + AT_SYMBOL + AT_SYMBOL + itemUseInfo.getBizName(),
itemUseInfo -> itemUseInfo,
(item1, item2) -> item1));
log.info("typeIdAndStatPair:{}", typeIdAndStatPair);
log.debug("typeIdAndStatPair:{}", typeIdAndStatPair);
for (DomainSchemaResp domainSchemaDesc : domainSchemaDescList) {
fillDimCnt(domainSchemaDesc, typeIdAndStatPair);
fillMetricCnt(domainSchemaDesc, typeIdAndStatPair);

View File

@@ -38,18 +38,19 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@Slf4j
@Primary
@Service("SemanticSchemaManager")
public class SemanticSchemaManagerImpl implements SemanticSchemaManager {
@Autowired
private LoadingCache<String, SemanticModel> loadingCache;
private final DatasourceService datasourceService;
private final DomainService domainService;
@Autowired
private LoadingCache<String, SemanticModel> loadingCache;
public SemanticSchemaManagerImpl(DatasourceService datasourceService,
@@ -58,62 +59,14 @@ public class SemanticSchemaManagerImpl implements SemanticSchemaManager {
this.domainService = domainService;
}
@Override
public SemanticModel reload(String rootPath) {
SemanticModel semanticModel = new SemanticModel();
semanticModel.setRootPath(rootPath);
Map<Long, String> domainFullPathMap = domainService.getDomainFullPath();
log.info("domainFullPathMap {}", domainFullPathMap);
Set<Long> domainIds = domainFullPathMap.entrySet().stream().filter(e -> e.getValue().startsWith(rootPath))
.map(e -> e.getKey()).collect(Collectors.toSet());
if (domainIds.isEmpty()) {
log.error("get domainId empty {}", rootPath);
return semanticModel;
}
Map<String, List<DimensionYamlTpl>> dimensionYamlTpls = new HashMap<>();
List<DatasourceYamlTpl> datasourceYamlTpls = new ArrayList<>();
List<MetricYamlTpl> metricYamlTpls = new ArrayList<>();
datasourceService.getModelYamlTplByDomainIds(domainIds, dimensionYamlTpls, datasourceYamlTpls, metricYamlTpls);
if (!datasourceYamlTpls.isEmpty()) {
Map<String, DataSource> dataSourceMap = datasourceYamlTpls.stream().map(d -> getDatasource(d))
.collect(Collectors.toMap(DataSource::getName, item -> item));
semanticModel.setDatasourceMap(dataSourceMap);
}
if (!dimensionYamlTpls.isEmpty()) {
Map<String, List<Dimension>> dimensionMap = new HashMap<>();
for (Map.Entry<String, List<DimensionYamlTpl>> entry : dimensionYamlTpls.entrySet()) {
dimensionMap.put(entry.getKey(), getDimensions(entry.getValue()));
}
semanticModel.setDimensionMap(dimensionMap);
}
if (!metricYamlTpls.isEmpty()) {
semanticModel.setMetrics(getMetrics(metricYamlTpls));
}
return semanticModel;
}
//private Map<String, SemanticSchema> semanticSchemaMap = new HashMap<>();
@Override
public SemanticModel get(String rootPath) throws Exception {
rootPath = formatKey(rootPath);
SemanticModel schema = loadingCache.get(rootPath);
if (schema == null) {
return null;
}
return schema;
}
public static List<Metric> getMetrics(final List<MetricYamlTpl> t) {
return getMetricsByMetricYamlTpl(t);
}
public static List<Dimension> getDimensions(final List<DimensionYamlTpl> t) {
return getDimension(t);
}
public static DataSource getDatasource(final DatasourceYamlTpl d) {
DataSource datasource = new DataSource();
datasource.setSqlQuery(d.getSqlQuery());
@@ -197,7 +150,6 @@ public class SemanticSchemaManagerImpl implements SemanticSchemaManager {
return identifies;
}
public static void update(SemanticSchema schema, List<Metric> metric) throws Exception {
if (schema != null) {
updateMetric(metric, schema.getMetrics());
@@ -273,6 +225,51 @@ public class SemanticSchemaManagerImpl implements SemanticSchemaManager {
return key;
}
@Override
public SemanticModel reload(String rootPath) {
SemanticModel semanticModel = new SemanticModel();
semanticModel.setRootPath(rootPath);
Map<Long, String> domainFullPathMap = domainService.getDomainFullPath();
log.info("domainFullPathMap {}", domainFullPathMap);
Set<Long> domainIds = domainFullPathMap.entrySet().stream().filter(e -> e.getValue().startsWith(rootPath))
.map(e -> e.getKey()).collect(Collectors.toSet());
if (domainIds.isEmpty()) {
log.error("get domainId empty {}", rootPath);
return semanticModel;
}
Map<String, List<DimensionYamlTpl>> dimensionYamlTpls = new HashMap<>();
List<DatasourceYamlTpl> datasourceYamlTpls = new ArrayList<>();
List<MetricYamlTpl> metricYamlTpls = new ArrayList<>();
datasourceService.getModelYamlTplByDomainIds(domainIds, dimensionYamlTpls, datasourceYamlTpls, metricYamlTpls);
if (!datasourceYamlTpls.isEmpty()) {
Map<String, DataSource> dataSourceMap = datasourceYamlTpls.stream().map(d -> getDatasource(d))
.collect(Collectors.toMap(DataSource::getName, item -> item));
semanticModel.setDatasourceMap(dataSourceMap);
}
if (!dimensionYamlTpls.isEmpty()) {
Map<String, List<Dimension>> dimensionMap = new HashMap<>();
for (Map.Entry<String, List<DimensionYamlTpl>> entry : dimensionYamlTpls.entrySet()) {
dimensionMap.put(entry.getKey(), getDimensions(entry.getValue()));
}
semanticModel.setDimensionMap(dimensionMap);
}
if (!metricYamlTpls.isEmpty()) {
semanticModel.setMetrics(getMetrics(metricYamlTpls));
}
return semanticModel;
}
//private Map<String, SemanticSchema> semanticSchemaMap = new HashMap<>();
@Override
public SemanticModel get(String rootPath) throws Exception {
rootPath = formatKey(rootPath);
SemanticModel schema = loadingCache.get(rootPath);
if (schema == null) {
return null;
}
return schema;
}
@Configuration
@EnableCaching
public class GuavaCacheConfig {

View File

@@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
public interface QueryService {
Object queryBySql(QuerySqlReq querySqlCmd) throws Exception;
Object queryBySql(QuerySqlReq querySqlCmd, User user) throws Exception;
QueryResultWithSchemaResp queryByStruct(QueryStructReq queryStructCmd, User user) throws Exception;

View File

@@ -27,6 +27,11 @@ public class Configuration {
public static RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
public static SqlOperatorTable operatorTable = SqlStdOperatorTable.instance();
public static CalciteConnectionConfig config = new CalciteConnectionConfigImpl(configProperties);
public static SqlValidator.Config validatorConfig = SqlValidator.Config.DEFAULT
.withLenientOperatorLookup(config.lenientOperatorLookup())
.withSqlConformance(SemanticSqlDialect.DEFAULT.getConformance())
.withDefaultNullCollation(config.defaultNullCollation())
.withIdentifierExpansion(true);
static {
configProperties.put(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), Boolean.TRUE.toString());
@@ -34,12 +39,6 @@ public class Configuration {
configProperties.put(CalciteConnectionProperty.QUOTED_CASING.camelName(), Casing.TO_LOWER.toString());
}
public static SqlValidator.Config validatorConfig = SqlValidator.Config.DEFAULT
.withLenientOperatorLookup(config.lenientOperatorLookup())
.withSqlConformance(SemanticSqlDialect.DEFAULT.getConformance())
.withDefaultNullCollation(config.defaultNullCollation())
.withIdentifierExpansion(true);
public static SqlParser.Config getParserConfig() {
CalciteConnectionConfig config = new CalciteConnectionConfigImpl(configProperties);
SqlParser.ConfigBuilder parserConfig = SqlParser.configBuilder();

View File

@@ -25,21 +25,6 @@ public abstract class Renderer {
protected TableView tableView = new TableView();
public void setTable(SqlNode table) {
tableView.setTable(table);
}
public SqlNode builder() {
return tableView.build();
}
public SqlNode builderAs(String alias) throws Exception {
return SemanticNode.buildAs(alias, tableView.build());
}
public abstract void render(MetricReq metricCommand, List<DataSource> dataSources, SqlValidatorScope scope,
SemanticSchema schema, boolean nonAgg) throws Exception;
public static Optional<Dimension> getDimensionByName(String name, DataSource datasource) {
return datasource.getDimensions().stream().filter(d -> d.getName().equalsIgnoreCase(name)).findFirst();
}
@@ -58,7 +43,6 @@ public abstract class Renderer {
return datasource.getIdentifiers().stream().filter(i -> i.getName().equalsIgnoreCase(name)).findFirst();
}
public static MetricNode buildMetricNode(String metric, DataSource datasource, SqlValidatorScope scope,
SemanticSchema schema, boolean nonAgg, String alias) throws Exception {
Optional<Metric> metricOpt = getMetricByName(metric, schema);
@@ -105,4 +89,19 @@ public abstract class Renderer {
Set<String> tmp = new HashSet<>(list);
return tmp.stream().collect(Collectors.toList());
}
public void setTable(SqlNode table) {
tableView.setTable(table);
}
public SqlNode builder() {
return tableView.build();
}
public SqlNode builderAs(String alias) throws Exception {
return SemanticNode.buildAs(alias, tableView.build());
}
public abstract void render(MetricReq metricCommand, List<DataSource> dataSources, SqlValidatorScope scope,
SemanticSchema schema, boolean nonAgg) throws Exception;
}

View File

@@ -5,6 +5,13 @@ import org.apache.calcite.sql.validate.SqlValidatorScope;
public class AggFunctionNode extends SemanticNode {
public static SqlNode build(String agg, String name, SqlValidatorScope scope) throws Exception {
if (AggFunction.COUNT_DISTINCT.name().equalsIgnoreCase(agg)) {
return parse(AggFunction.COUNT.name() + " ( " + AggFunction.DISTINCT.name() + " " + name + " ) ", scope);
}
return parse(agg + " ( " + name + " ) ", scope);
}
public static enum AggFunction {
AVG,
COUNT_DISTINCT,
@@ -15,12 +22,5 @@ public class AggFunctionNode extends SemanticNode {
DISTINCT
}
public static SqlNode build(String agg, String name, SqlValidatorScope scope) throws Exception {
if (AggFunction.COUNT_DISTINCT.name().equalsIgnoreCase(agg)) {
return parse(AggFunction.COUNT.name() + " ( " + AggFunction.DISTINCT.name() + " " + name + " ) ", scope);
}
return parse(agg + " ( " + name + " ) ", scope);
}
}

View File

@@ -24,10 +24,6 @@ import org.apache.commons.lang3.StringUtils;
public abstract class SemanticNode {
public void accept(Optimization optimization) {
optimization.visit(this);
}
public static SqlNode parse(String expression, SqlValidatorScope scope) throws Exception {
SqlParser sqlParser = SqlParser.create(expression, Configuration.getParserConfig());
SqlNode sqlNode = sqlParser.parseExpression();
@@ -77,7 +73,6 @@ public abstract class SemanticNode {
return sqlNode instanceof SqlIdentifier;
}
public static SqlNode getAlias(SqlNode sqlNode, SqlValidatorScope scope) throws Exception {
if (sqlNode instanceof SqlBasicCall) {
SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
@@ -117,5 +112,9 @@ public abstract class SemanticNode {
return sqlNode;
}
public void accept(Optimization optimization) {
optimization.visit(this);
}
}

View File

@@ -90,7 +90,7 @@ public class JoinRender extends Renderer {
fieldWhere.add(identify.getName());
}
}
TableView tableView = SourceRender.renderOne(false, "", fieldWhere, queryMetrics, queryDimension,
TableView tableView = SourceRender.renderOne("", fieldWhere, queryMetrics, queryDimension,
metricCommand.getWhere(), dataSources.get(i), scope, schema, true);
log.info("tableView {}", tableView.getTable().toString());
String alias = Constants.JOIN_TABLE_PREFIX + dataSource.getName();

View File

@@ -33,30 +33,7 @@ import org.springframework.util.CollectionUtils;
@Slf4j
public class SourceRender extends Renderer {
public void render(MetricReq metricCommand, List<DataSource> dataSources, SqlValidatorScope scope,
SemanticSchema schema, boolean nonAgg) throws Exception {
String queryWhere = metricCommand.getWhere();
Set<String> whereFields = new HashSet<>();
List<String> fieldWhere = new ArrayList<>();
if (queryWhere != null && !queryWhere.isEmpty()) {
SqlNode sqlNode = SemanticNode.parse(queryWhere, scope);
FilterNode.getFilterField(sqlNode, whereFields);
fieldWhere = whereFields.stream().collect(Collectors.toList());
}
if (dataSources.size() == 1) {
DataSource dataSource = dataSources.get(0);
super.tableView = renderOne(false, "", fieldWhere, metricCommand.getMetrics(),
metricCommand.getDimensions(),
metricCommand.getWhere(), dataSource, scope, schema, nonAgg);
return;
}
JoinRender joinRender = new JoinRender();
joinRender.render(metricCommand, dataSources, scope, schema, nonAgg);
super.tableView = joinRender.getTableView();
}
public static TableView renderOne(boolean addWhere, String alias, List<String> fieldWhere,
public static TableView renderOne(String alias, List<String> fieldWhere,
List<String> reqMetrics, List<String> reqDimensions, String queryWhere, DataSource datasource,
SqlValidatorScope scope, SemanticSchema schema, boolean nonAgg) throws Exception {
@@ -65,10 +42,10 @@ public class SourceRender extends Renderer {
List<String> queryMetrics = new ArrayList<>(reqMetrics);
List<String> queryDimensions = new ArrayList<>(reqDimensions);
if (!fieldWhere.isEmpty()) {
SqlNode sqlNode = SemanticNode.parse(queryWhere, scope);
if (addWhere) {
output.getFilter().add(sqlNode);
}
// SqlNode sqlNode = SemanticNode.parse(queryWhere, scope);
// if (addWhere) {
// output.getFilter().add(sqlNode);
// }
Set<String> dimensions = new HashSet<>();
Set<String> metrics = new HashSet<>();
whereDimMetric(fieldWhere, queryMetrics, queryDimensions, datasource, schema, dimensions, metrics);
@@ -104,7 +81,6 @@ public class SourceRender extends Renderer {
return output;
}
private static void buildDimension(String alias, String dimension, DataSource datasource, SemanticSchema schema,
boolean nonAgg, TableView dataSet, TableView output, SqlValidatorScope scope) throws Exception {
List<Dimension> dimensionList = schema.getDimension().get(datasource.getName());
@@ -160,7 +136,6 @@ public class SourceRender extends Renderer {
}
}
private static boolean isWhereHasMetric(List<String> fields, DataSource datasource) {
Long metricNum = datasource.getMeasures().stream().filter(m -> fields.contains(m.getName().toLowerCase()))
.count();
@@ -227,7 +202,6 @@ public class SourceRender extends Renderer {
//getWhere(outputSet,fields,queryMetrics,queryDimensions,datasource,scope,schema);
}
public static void whereDimMetric(List<String> fields, List<String> queryMetrics,
List<String> queryDimensions, DataSource datasource, SemanticSchema schema, Set<String> dimensions,
Set<String> metrics) {
@@ -291,7 +265,6 @@ public class SourceRender extends Renderer {
return false;
}
private static void expandWhere(MetricReq metricCommand, TableView tableView, SqlValidatorScope scope)
throws Exception {
if (metricCommand.getWhere() != null && !metricCommand.getWhere().isEmpty()) {
@@ -303,5 +276,27 @@ public class SourceRender extends Renderer {
}
}
public void render(MetricReq metricCommand, List<DataSource> dataSources, SqlValidatorScope scope,
SemanticSchema schema, boolean nonAgg) throws Exception {
String queryWhere = metricCommand.getWhere();
Set<String> whereFields = new HashSet<>();
List<String> fieldWhere = new ArrayList<>();
if (queryWhere != null && !queryWhere.isEmpty()) {
SqlNode sqlNode = SemanticNode.parse(queryWhere, scope);
FilterNode.getFilterField(sqlNode, whereFields);
fieldWhere = whereFields.stream().collect(Collectors.toList());
}
if (dataSources.size() == 1) {
DataSource dataSource = dataSources.get(0);
super.tableView = renderOne("", fieldWhere, metricCommand.getMetrics(),
metricCommand.getDimensions(),
metricCommand.getWhere(), dataSource, scope, schema, nonAgg);
return;
}
JoinRender joinRender = new JoinRender();
joinRender.render(metricCommand, dataSources, scope, schema, nonAgg);
super.tableView = joinRender.getTableView();
}
}

View File

@@ -9,18 +9,13 @@ import lombok.Data;
public class Dimension implements SemanticItem {
String name;
private String owners;
private String type;
private String expr;
private DimensionTimeTypeParams dimensionTimeTypeParams;
@Override
public String getName() {
return name;
}
private String owners;
private String type;
private String expr;
private DimensionTimeTypeParams dimensionTimeTypeParams;
}

View File

@@ -10,16 +10,12 @@ import lombok.Data;
public class Metric implements SemanticItem {
private String name;
private List<String> owners;
private String type;
private MetricTypeParams metricTypeParams;
@Override
public String getName() {
return name;
}
private List<String> owners;
private String type;
private MetricTypeParams metricTypeParams;
}

View File

@@ -8,6 +8,7 @@ import lombok.Data;
@Data
public class SemanticModel {
private String rootPath;
private List<Metric> metrics = new ArrayList<>();
private Map<String, DataSource> datasourceMap = new HashMap<>();

View File

@@ -39,11 +39,14 @@ public class DataSourceTable extends AbstractTable implements ScannableTable, Tr
this.statistic = statistic;
}
public static Builder newBuilder(String tableName) {
return new Builder(tableName);
}
public String getTableName() {
return tableName;
}
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
if (rowType == null) {
@@ -71,11 +74,6 @@ public class DataSourceTable extends AbstractTable implements ScannableTable, Tr
throw new UnsupportedOperationException("Not implemented");
}
public static Builder newBuilder(String tableName) {
return new Builder(tableName);
}
public RelNode toRel(RelOptTable.ToRelContext toRelContext, RelOptTable relOptTable) {
List<RelHint> hint = new ArrayList<>();
return new LogicalTableScan(toRelContext.getCluster(), toRelContext.getCluster().traitSet(), hint, relOptTable);

View File

@@ -26,6 +26,10 @@ public class SemanticSchema extends AbstractSchema {
this.tableMap = tableMap;
}
public static Builder newBuilder(String rootPath) {
return new Builder(rootPath);
}
public String getRootPath() {
return rootPath;
}
@@ -40,27 +44,22 @@ public class SemanticSchema extends AbstractSchema {
return this;
}
public static Builder newBuilder(String rootPath) {
return new Builder(rootPath);
public Map<String, DataSource> getDatasource() {
return semanticModel.getDatasourceMap();
}
public void setDatasource(Map<String, DataSource> datasource) {
semanticModel.setDatasourceMap(datasource);
}
public void setDimension(Map<String, List<Dimension>> dimensions) {
semanticModel.setDimensionMap(dimensions);
}
public Map<String, DataSource> getDatasource() {
return semanticModel.getDatasourceMap();
}
public Map<String, List<Dimension>> getDimension() {
return semanticModel.getDimensionMap();
}
public void setDimension(Map<String, List<Dimension>> dimensions) {
semanticModel.setDimensionMap(dimensions);
}
public List<Metric> getMetrics() {
return semanticModel.getMetrics();
}

View File

@@ -12,7 +12,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class SemanticSqlDialect extends SqlDialect {
private static final SqlConformance tagTdwSqlConformance = new SemanticSqlConformance();
public static final Context DEFAULT_CONTEXT = SqlDialect.EMPTY_CONTEXT
.withDatabaseProduct(DatabaseProduct.BIG_QUERY)
.withLiteralQuoteString("'")
@@ -22,13 +21,37 @@ public class SemanticSqlDialect extends SqlDialect {
.withUnquotedCasing(Casing.UNCHANGED)
.withQuotedCasing(Casing.UNCHANGED)
.withCaseSensitive(false);
public static final SqlDialect DEFAULT = new SemanticSqlDialect(DEFAULT_CONTEXT);
private static final SqlConformance tagTdwSqlConformance = new SemanticSqlConformance();
public SemanticSqlDialect(Context context) {
super(context);
}
public static void unparseFetchUsingAnsi(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) {
Preconditions.checkArgument(fetch != null || offset != null);
SqlWriter.Frame fetchFrame;
writer.newlineAndIndent();
fetchFrame = writer.startList(SqlWriter.FrameTypeEnum.OFFSET);
writer.keyword("LIMIT");
if (offset != null) {
//writer.keyword("OFFSET");
offset.unparse(writer, -1, -1);
//writer.keyword("ROWS");
}
if (fetch != null) {
//writer.newlineAndIndent();
//fetchFrame = writer.startList(SqlWriter.FrameTypeEnum.FETCH);
writer.keyword(",");
//writer.keyword("NEXT");
fetch.unparse(writer, -1, -1);
}
writer.endList(fetchFrame);
}
@Override
public void quoteStringLiteralUnicode(StringBuilder buf, String val) {
buf.append("'");
@@ -36,7 +59,6 @@ public class SemanticSqlDialect extends SqlDialect {
buf.append("'");
}
@Override
public void quoteStringLiteral(StringBuilder buf, String charsetName, String val) {
buf.append(literalQuoteString);
@@ -70,28 +92,4 @@ public class SemanticSqlDialect extends SqlDialect {
public void unparseOffsetFetch(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) {
unparseFetchUsingAnsi(writer, offset, fetch);
}
public static void unparseFetchUsingAnsi(SqlWriter writer, @Nullable SqlNode offset, @Nullable SqlNode fetch) {
Preconditions.checkArgument(fetch != null || offset != null);
SqlWriter.Frame fetchFrame;
writer.newlineAndIndent();
fetchFrame = writer.startList(SqlWriter.FrameTypeEnum.OFFSET);
writer.keyword("LIMIT");
if (offset != null) {
//writer.keyword("OFFSET");
offset.unparse(writer, -1, -1);
//writer.keyword("ROWS");
}
if (fetch != null) {
//writer.newlineAndIndent();
//fetchFrame = writer.startList(SqlWriter.FrameTypeEnum.FETCH);
writer.keyword(",");
//writer.keyword("NEXT");
fetch.unparse(writer, -1, -1);
}
writer.endList(fetchFrame);
}
}

View File

@@ -10,22 +10,22 @@ public class ParserSvrResponse<T> {
return code;
}
public String getMsg() {
return msg;
}
public T getData() {
return data;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}

View File

@@ -57,26 +57,20 @@ import org.springframework.util.CollectionUtils;
@Slf4j
public class DataPermissionAOP {
@Autowired
private QueryStructUtils queryStructUtils;
@Autowired
private AuthService authService;
@Autowired
private DimensionService dimensionService;
@Autowired
private MetricService metricService;
@Autowired
private DomainService domainService;
@Value("${permission.data.enable:true}")
private Boolean permissionDataEnable;
private static final ObjectMapper MAPPER = new ObjectMapper().setDateFormat(
new SimpleDateFormat(Constants.DAY_FORMAT));
@Autowired
private QueryStructUtils queryStructUtils;
@Autowired
private AuthService authService;
@Autowired
private DimensionService dimensionService;
@Autowired
private MetricService metricService;
@Autowired
private DomainService domainService;
@Value("${permission.data.enable:true}")
private Boolean permissionDataEnable;
@Pointcut("@annotation(com.tencent.supersonic.semantic.query.domain.annotation.DataPermission)")
public void dataPermissionAOP() {
@@ -179,7 +173,7 @@ public class DataPermissionAOP {
}
private void addPromptInfoInfo(Long domainId, QueryResultWithSchemaResp queryResultWithColumns,
AuthorizedResourceResp authorizedResource) {
AuthorizedResourceResp authorizedResource) {
List<DimensionFilter> filters = authorizedResource.getFilters();
if (!CollectionUtils.isEmpty(filters)) {
log.debug("dimensionFilters:{}", filters);
@@ -258,7 +252,7 @@ public class DataPermissionAOP {
}
private AuthorizedResourceResp getAuthorizedResource(User user, HttpServletRequest request, Long domainId,
Set<String> sensitiveResReq) {
Set<String> sensitiveResReq) {
List<AuthRes> resourceReqList = new ArrayList<>();
sensitiveResReq.stream().forEach(res -> resourceReqList.add(new AuthRes(domainId.toString(), res)));
QueryAuthResReq queryAuthResReq = new QueryAuthResReq();
@@ -375,7 +369,7 @@ public class DataPermissionAOP {
}
private void doFilterCheckLogic(QueryStructReq queryStructCmd, Set<String> resAuthName,
Set<String> sensitiveResReq) {
Set<String> sensitiveResReq) {
Set<String> resFilterSet = queryStructUtils.getFilterResNameEnExceptInternalCol(queryStructCmd);
Set<String> need2Apply = resFilterSet.stream()
.filter(res -> !resAuthName.contains(res) && sensitiveResReq.contains(res)).collect(Collectors.toSet());
@@ -405,7 +399,7 @@ public class DataPermissionAOP {
private AuthorizedResourceResp fetchAuthRes(HttpServletRequest request, QueryAuthResReq queryAuthResReq) {
log.info("Authorization:{}", request.getHeader("Authorization"));
log.info("queryAuthResReq:{}", queryAuthResReq);
return authService.queryAuthorizedResources(request, queryAuthResReq);
return authService.queryAuthorizedResources(queryAuthResReq, request);
}
}

View File

@@ -1,14 +1,16 @@
package com.tencent.supersonic.domain.semantic.query.domain.utils;
package com.tencent.supersonic.semantic.query.domain.utils;
import static com.tencent.supersonic.common.constant.Constants.APOSTROPHE;
import static com.tencent.supersonic.common.constant.Constants.COMMA;
import static com.tencent.supersonic.common.constant.Constants.DAY;
import static com.tencent.supersonic.common.constant.Constants.DAY_FORMAT;
import static com.tencent.supersonic.common.constant.Constants.MONTH;
import static com.tencent.supersonic.common.constant.Constants.MONTH_FORMAT;
import static com.tencent.supersonic.common.constant.Constants.WEEK;
import com.google.common.base.Strings;
import com.tencent.supersonic.semantic.api.core.response.ItemDateResp;
import com.tencent.supersonic.common.pojo.DateConf;
import com.tencent.supersonic.semantic.api.core.response.ItemDateResp;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
@@ -29,6 +31,10 @@ public class DateUtils {
@Value("${query.parameter.sys.date:sys_imp_date}")
private String sysDateCol;
@Value("${query.parameter.sys.month:sys_imp_month}")
private String sysDateMonthCol;
@Value("${query.parameter.sys.month:sys_imp_week}")
private String sysDateWeekCol;
public Boolean recentMode(DateConf dateInfo) {
if (Objects.nonNull(dateInfo) && DateConf.DateMode.RECENT_UNITS == dateInfo.getDateMode()
@@ -125,6 +131,29 @@ public class DateUtils {
return String.format("(%s >= '%s' and %s <= '%s')", sysDateCol, start, sysDateCol, dateDate.getEndDate());
}
public String recentMonthStr(ItemDateResp dateDate, DateConf dateInfo) {
String dateFormatStr = MONTH_FORMAT;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormatStr);
LocalDate end = LocalDate.parse(dateDate.getEndDate(), formatter);
String endStr = end.format(formatter);
Integer unit = dateInfo.getUnit() - 1;
String start = end.minusMonths(unit).format(formatter);
return String.format("(%s >= '%s' and %s <= '%s')", sysDateMonthCol, start, sysDateMonthCol, endStr);
}
public String recentWeekStr(ItemDateResp dateDate, DateConf dateInfo) {
String dateFormatStr = dateDate.getDateFormat();
if (Strings.isNullOrEmpty(dateFormatStr)) {
dateFormatStr = DAY_FORMAT;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormatStr);
LocalDate end = LocalDate.parse(dateDate.getEndDate(), formatter);
Integer unit = dateInfo.getUnit() - 1;
String start = end.minusDays(unit * 7).format(formatter);
return String.format("(%s >= '%s' and %s <= '%s')", sysDateWeekCol, start, sysDateWeekCol,
dateDate.getEndDate());
}
private Long getInterval(String startDate, String endDate, String dateFormat, ChronoUnit chronoUnit) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
try {
@@ -142,6 +171,12 @@ public class DateUtils {
if (DAY.equalsIgnoreCase(dateInfo.getPeriod())) {
return recentDayStr(dateDate, dateInfo);
}
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
return recentMonthStr(dateDate, dateInfo);
}
if (WEEK.equalsIgnoreCase(dateInfo.getPeriod())) {
return recentWeekStr(dateDate, dateInfo);
}
return "";
}

View File

@@ -30,12 +30,11 @@ public class ParserCommandConverter {
private final ParserService parserService;
private final DomainService domainService;
private final CalculateConverterAgg calculateCoverterAgg;
private final DimensionService dimensionService;
private final QueryStructUtils queryStructUtils;
@Value("${internal.metric.cnt.suffix:internal_cnt}")
private String internalMetricNameSuffix;
private final DimensionService dimensionService;
private List<CalculateConverter> calculateCoverters = new LinkedList<>();
private final QueryStructUtils queryStructUtils;
public ParserCommandConverter(ParserService parserService,
DomainService domainService,
@@ -78,11 +77,14 @@ public class ParserCommandConverter {
sqlCommend.setLimit(queryStructCmd.getLimit());
String rootPath = domainService.getDomainFullPath(queryStructCmd.getDomainId());
sqlCommend.setRootPath(rootPath);
// todo tmp delete
// support detail query
if (queryStructCmd.getNativeQuery() && CollectionUtils.isEmpty(sqlCommend.getMetrics())) {
String internalMetricName = generateInternalMetricName(queryStructCmd);
sqlCommend.getMetrics().add(internalMetricName);
}
return sqlCommend;
}

View File

@@ -0,0 +1,72 @@
package com.tencent.supersonic.semantic.query.domain.utils;
import com.tencent.supersonic.common.util.calcite.SqlParseUtils;
import com.tencent.supersonic.common.util.calcite.SqlParserInfo;
import com.tencent.supersonic.semantic.api.core.response.DomainSchemaResp;
import com.tencent.supersonic.semantic.api.core.response.SqlParserResp;
import com.tencent.supersonic.semantic.api.query.pojo.MetricTable;
import com.tencent.supersonic.semantic.api.query.request.ParseSqlReq;
import com.tencent.supersonic.semantic.api.query.request.QuerySqlReq;
import com.tencent.supersonic.semantic.core.domain.DomainService;
import com.tencent.supersonic.semantic.query.domain.ParserService;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@Component
public class QueryReqConverter {
@Autowired
private DomainService domainService;
@Autowired
private ParserService parserService;
public SqlParserResp convert(QuerySqlReq databaseReq, List<DomainSchemaResp> domainSchemas) throws Exception {
List<MetricTable> tables = new ArrayList<>();
MetricTable metricTable = new MetricTable();
String sql = databaseReq.getSql();
SqlParserInfo sqlParseInfo = SqlParseUtils.getSqlParseInfo(sql);
List<String> allFields = sqlParseInfo.getAllFields();
if (CollectionUtils.isEmpty(domainSchemas)) {
return new SqlParserResp();
}
Set<String> dimensions = domainSchemas.get(0).getDimensions().stream()
.map(entry -> entry.getBizName().toLowerCase())
.collect(Collectors.toSet());
dimensions.addAll(QueryStructUtils.internalCols);
Set<String> metrics = domainSchemas.get(0).getMetrics().stream().map(entry -> entry.getBizName().toLowerCase())
.collect(Collectors.toSet());
metricTable.setMetrics(allFields.stream().filter(entry -> metrics.contains(entry.toLowerCase()))
.map(entry -> entry.toLowerCase()).collect(Collectors.toList()));
Set<String> collect = allFields.stream().filter(entry -> dimensions.contains(entry.toLowerCase()))
.map(entry -> entry.toLowerCase()).collect(Collectors.toSet());
for (String internalCol : QueryStructUtils.internalCols) {
if (sql.contains(internalCol)) {
collect.add(internalCol);
}
}
metricTable.setDimensions(new ArrayList<>(collect));
metricTable.setAlias(sqlParseInfo.getTableName().toLowerCase());
tables.add(metricTable);
ParseSqlReq result = new ParseSqlReq();
BeanUtils.copyProperties(databaseReq, result);
result.setRootPath(domainService.getDomainFullPath(databaseReq.getDomainId()));
result.setTables(tables);
return parserService.physicalSql(result);
}
}

View File

@@ -42,6 +42,8 @@ import org.springframework.util.CollectionUtils;
@Component
public class QueryStructUtils {
public static Set<String> internalCols = new HashSet<>(
Arrays.asList("dayno", "plat_sys_var", "sys_imp_date", "sys_imp_week", "sys_imp_month"));
private final DatabaseService databaseService;
private final QueryUtils queryUtils;
private final ParserService parserService;
@@ -50,16 +52,12 @@ public class QueryStructUtils {
private final DimensionService dimensionService;
private final MetricService metricService;
private final DatasourceService datasourceService;
private final com.tencent.supersonic.domain.semantic.query.domain.utils.DateUtils dateUtils;
private final DateUtils dateUtils;
private final SqlFilterUtils sqlFilterUtils;
private final CacheUtils cacheUtils;
@Value("${query.cache.enable:true}")
private Boolean cacheEnable;
Set<String> internalCols = new HashSet<>(
Arrays.asList("dayno", "plat_sys_var", "sys_imp_date", "sys_imp_week", "sys_imp_month"));
public QueryStructUtils(DatabaseService databaseService,
QueryUtils queryUtils,
ParserService parserService,
@@ -68,7 +66,7 @@ public class QueryStructUtils {
DimensionService dimensionService,
MetricService metricService,
DatasourceService datasourceService,
com.tencent.supersonic.domain.semantic.query.domain.utils.DateUtils dateUtils,
DateUtils dateUtils,
SqlFilterUtils sqlFilterUtils,
CacheUtils cacheUtils) {
this.databaseService = databaseService;
@@ -118,7 +116,10 @@ public class QueryStructUtils {
queryUtils.checkSqlParse(sqlParser);
log.info("sqlParser:{}", sqlParser);
queryUtils.handleDetail(queryStructCmd, sqlParser);
// todo tmp delete
//queryUtils.handleDetail(queryStructCmd, sqlParser);
queryUtils.handleNoMetric(queryStructCmd, sqlParser);
QueryResultWithSchemaResp queryResultWithColumns = databaseService.queryWithColumns(sqlParser);
queryUtils.fillItemNameInfo(queryResultWithColumns, queryStructCmd.getDomainId());

View File

@@ -42,6 +42,23 @@ import org.springframework.util.CollectionUtils;
public class QueryUtils {
private final Set<Pattern> patterns = new HashSet<>();
private final MetricService metricService;
private final DimensionService dimensionService;
private final ParserCommandConverter parserCommandConverter;
public QueryUtils(MetricService metricService,
DimensionService dimensionService,
@Lazy ParserCommandConverter parserCommandConverter) {
this.metricService = metricService;
this.dimensionService = dimensionService;
this.parserCommandConverter = parserCommandConverter;
}
private static void addSysTimeDimension(Map<String, String> namePair, Map<String, String> nameTypePair) {
for (TimeDimensionEnum timeDimensionEnum : TimeDimensionEnum.values()) {
namePair.put(timeDimensionEnum.getName(), "date");
nameTypePair.put(timeDimensionEnum.getName(), "DATE");
}
}
@PostConstruct
public void fillPattern() {
@@ -52,19 +69,6 @@ public class QueryUtils {
}
}
private final MetricService metricService;
private final DimensionService dimensionService;
private final ParserCommandConverter parserCommandConverter;
public QueryUtils(MetricService metricService,
DimensionService dimensionService,
@Lazy ParserCommandConverter parserCommandConverter) {
this.metricService = metricService;
this.dimensionService = dimensionService;
this.parserCommandConverter = parserCommandConverter;
}
public void checkSqlParse(SqlParserResp sqlParser) {
if (Strings.isNullOrEmpty(sqlParser.getSql()) || Strings.isNullOrEmpty(sqlParser.getSourceId())) {
throw new RuntimeException("parse Exception: " + sqlParser.getErrMsg());
@@ -76,6 +80,23 @@ public class QueryUtils {
queryStructCmd.getMetrics());
}
public SqlParserResp handleNoMetric(QueryStructReq queryStructCmd, SqlParserResp sqlParser) {
String sqlRaw = sqlParser.getSql().trim();
if (Strings.isNullOrEmpty(sqlRaw)) {
throw new RuntimeException("sql is empty or null");
}
log.info("before handleNoMetric, sql:{}", sqlRaw);
if (isDetailQuery(queryStructCmd)) {
if (queryStructCmd.getMetrics().size() == 0) {
String sql = String.format("select %s from ( %s ) src_no_metric",
queryStructCmd.getGroups().stream().collect(Collectors.joining(",")), sqlRaw);
sqlParser.setSql(sql);
}
}
log.info("after handleNoMetric, sql:{}", sqlParser.getSql());
return sqlParser;
}
public SqlParserResp handleDetail(QueryStructReq queryStructCmd, SqlParserResp sqlParser) {
String sqlRaw = sqlParser.getSql().trim();
if (Strings.isNullOrEmpty(sqlRaw)) {
@@ -223,11 +244,4 @@ public class QueryUtils {
}
return map;
}
private static void addSysTimeDimension(Map<String, String> namePair, Map<String, String> nameTypePair) {
for (TimeDimensionEnum timeDimensionEnum : TimeDimensionEnum.values()) {
namePair.put(timeDimensionEnum.getName(), "date");
nameTypePair.put(timeDimensionEnum.getName(), "DATE");
}
}
}

View File

@@ -13,13 +13,6 @@ import org.springframework.util.CollectionUtils;
@Slf4j
public class SqlGenerateUtils {
public String getLimit(QueryStructReq queryStructCmd) {
if (queryStructCmd.getLimit() > 0) {
return " limit " + String.valueOf(queryStructCmd.getLimit());
}
return "";
}
public static String getUnionSelect(QueryStructReq queryStructCmd) {
StringBuilder sb = new StringBuilder();
int locate = 0;
@@ -41,6 +34,12 @@ public class SqlGenerateUtils {
return selectSql;
}
public String getLimit(QueryStructReq queryStructCmd) {
if (queryStructCmd.getLimit() > 0) {
return " limit " + String.valueOf(queryStructCmd.getLimit());
}
return "";
}
public String getSelect(QueryStructReq queryStructCmd) {
String aggStr = queryStructCmd.getAggregators().stream().map(this::getSelectField)

View File

@@ -22,7 +22,7 @@ public class SqlParserUtils {
public SqlParserResp getSqlParserWithoutCache(QueryStructReq queryStructCmd) throws Exception {
log.info("stat getSqlParser without cache");
multiSourceJoinUtils.buildJoinPrefix(queryStructCmd);
//multiSourceJoinUtils.buildJoinPrefix(queryStructCmd);
SqlParserResp sqlParser = parserCommandConverter.getSqlParser(queryStructCmd);
return sqlParser;
}

View File

@@ -25,12 +25,11 @@ import org.springframework.stereotype.Component;
@Slf4j
public class StatUtils {
private static final TransmittableThreadLocal<QueryStat> STATS = new TransmittableThreadLocal<>();
private final StatRepository statRepository;
private final SqlFilterUtils sqlFilterUtils;
private final ObjectMapper objectMapper = new ObjectMapper();
private static final TransmittableThreadLocal<QueryStat> STATS = new TransmittableThreadLocal<>();
public StatUtils(StatRepository statRepository,
SqlFilterUtils sqlFilterUtils) {

View File

@@ -2,15 +2,15 @@ package com.tencent.supersonic.semantic.query.rest;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.semantic.api.query.request.ItemUseReq;
import com.tencent.supersonic.semantic.api.query.request.QueryMultiStructReq;
import com.tencent.supersonic.semantic.api.query.request.QuerySqlReq;
import com.tencent.supersonic.semantic.api.query.request.QueryStructReq;
import com.tencent.supersonic.semantic.api.core.response.SqlParserResp;
import com.tencent.supersonic.semantic.api.query.request.*;
import com.tencent.supersonic.semantic.api.query.response.ItemUseResp;
import com.tencent.supersonic.semantic.query.domain.ParserService;
import com.tencent.supersonic.semantic.query.domain.QueryService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -20,17 +20,25 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/semantic/query")
@Slf4j
public class QueryController {
@Autowired
private QueryService queryService;
@Autowired
private ParserService parserService;
@PostMapping("/sql")
public Object queryBySql(@RequestBody QuerySqlReq querySqlReq) throws Exception {
return queryService.queryBySql(querySqlReq);
public Object queryBySql(@RequestBody QuerySqlReq querySqlReq,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
User user = UserHolder.findUser(request, response);
Object queryBySql = queryService.queryBySql(querySqlReq, user);
log.info("queryBySql:{},queryBySql");
return queryBySql;
}
@PostMapping("/struct")
public Object queryByStruct(@RequestBody QueryStructReq queryStructReq,
HttpServletRequest request,
@@ -39,6 +47,14 @@ public class QueryController {
return queryService.queryByStruct(queryStructReq, user, request);
}
@PostMapping("/struct/parse")
public SqlParserResp parseByStruct(@RequestBody ParseSqlReq parseSqlReq,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
User user = UserHolder.findUser(request, response);
return parserService.physicalSql(parseSqlReq);
}
/**
* queryByMultiStruct
*/
@@ -61,5 +77,4 @@ public class QueryController {
return queryService.getStatInfo(itemUseReq);
}
}

View File

@@ -32,8 +32,8 @@ public class SchemaController {
@PostMapping
public List<DomainSchemaResp> fetchDomainSchema(@RequestBody DomainSchemaFilterReq filter,
HttpServletRequest request,
HttpServletResponse response) {
HttpServletRequest request,
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return schemaService.fetchDomainSchema(filter, user);
}
@@ -45,23 +45,23 @@ public class SchemaController {
*/
@GetMapping("/domain/list")
public List<DomainResp> getDomainList(HttpServletRequest request,
HttpServletResponse response) {
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return schemaService.getDomainListForAdmin(user);
}
@PostMapping("/dimension/page")
public PageInfo<DimensionResp> queryDimension(@RequestBody PageDimensionReq pageDimensionCmd,
HttpServletRequest request,
HttpServletResponse response) {
HttpServletRequest request,
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return schemaService.queryDimension(pageDimensionCmd, user);
}
@PostMapping("/metric/page")
public PageInfo<MetricResp> queryMetric(@RequestBody PageMetricReq pageMetricCmd,
HttpServletRequest request,
HttpServletResponse response) {
HttpServletRequest request,
HttpServletResponse response) {
User user = UserHolder.findUser(request, response);
return schemaService.queryMetric(pageMetricCmd, user);
}

View File

@@ -47,6 +47,66 @@ class SemanticParserServiceTest {
return sqlParser;
}
private static void addDepartment(SemanticSchema semanticSchema) {
DatasourceYamlTpl datasource = new DatasourceYamlTpl();
datasource.setName("user_department");
datasource.setSourceId(1L);
datasource.setSqlQuery("SELECT imp_date,user_name,department FROM s2_user_department");
MeasureYamlTpl measure = new MeasureYamlTpl();
measure.setAgg("count");
measure.setName("user_department_internal_cnt");
measure.setCreateMetric("true");
measure.setExpr("1");
List<MeasureYamlTpl> measures = new ArrayList<>();
measures.add(measure);
datasource.setMeasures(measures);
DimensionYamlTpl dimension = new DimensionYamlTpl();
dimension.setName("sys_imp_date");
dimension.setExpr("imp_date");
dimension.setType("time");
DimensionTimeTypeParamsTpl dimensionTimeTypeParams = new DimensionTimeTypeParamsTpl();
dimensionTimeTypeParams.setIsPrimary("true");
dimensionTimeTypeParams.setTimeGranularity("day");
dimension.setTypeParams(dimensionTimeTypeParams);
List<DimensionYamlTpl> dimensions = new ArrayList<>();
dimensions.add(dimension);
DimensionYamlTpl dimension3 = new DimensionYamlTpl();
dimension3.setName("sys_imp_week");
dimension3.setExpr("to_monday(from_unixtime(unix_timestamp(imp_date), 'yyyy-MM-dd'))");
dimension3.setType("time");
DimensionTimeTypeParamsTpl dimensionTimeTypeParams3 = new DimensionTimeTypeParamsTpl();
dimensionTimeTypeParams3.setIsPrimary("true");
dimensionTimeTypeParams3.setTimeGranularity("week");
dimension3.setTypeParams(dimensionTimeTypeParams3);
dimensions.add(dimension3);
datasource.setDimensions(dimensions);
List<IdentifyYamlTpl> identifies = new ArrayList<>();
IdentifyYamlTpl identify = new IdentifyYamlTpl();
identify.setName("user_name");
identify.setType("primary");
identifies.add(identify);
datasource.setIdentifiers(identifies);
semanticSchema.getDatasource().put("user_department", SemanticSchemaManagerImpl.getDatasource(datasource));
DimensionYamlTpl dimension1 = new DimensionYamlTpl();
dimension1.setExpr("department");
dimension1.setName("department");
dimension1.setType("categorical");
List<DimensionYamlTpl> dimensionYamlTpls = new ArrayList<>();
dimensionYamlTpls.add(dimension1);
semanticSchema.getDimension()
.put("user_department", SemanticSchemaManagerImpl.getDimensions(dimensionYamlTpls));
}
//@Test
public void test() throws Exception {
@@ -189,65 +249,4 @@ class SemanticParserServiceTest {
}
private static void addDepartment(SemanticSchema semanticSchema) {
DatasourceYamlTpl datasource = new DatasourceYamlTpl();
datasource.setName("user_department");
datasource.setSourceId(1L);
datasource.setSqlQuery("SELECT imp_date,user_name,department FROM s2_user_department");
MeasureYamlTpl measure = new MeasureYamlTpl();
measure.setAgg("count");
measure.setName("user_department_internal_cnt");
measure.setCreateMetric("true");
measure.setExpr("1");
List<MeasureYamlTpl> measures = new ArrayList<>();
measures.add(measure);
datasource.setMeasures(measures);
DimensionYamlTpl dimension = new DimensionYamlTpl();
dimension.setName("sys_imp_date");
dimension.setExpr("imp_date");
dimension.setType("time");
DimensionTimeTypeParamsTpl dimensionTimeTypeParams = new DimensionTimeTypeParamsTpl();
dimensionTimeTypeParams.setIsPrimary("true");
dimensionTimeTypeParams.setTimeGranularity("day");
dimension.setTypeParams(dimensionTimeTypeParams);
List<DimensionYamlTpl> dimensions = new ArrayList<>();
dimensions.add(dimension);
DimensionYamlTpl dimension3 = new DimensionYamlTpl();
dimension3.setName("sys_imp_week");
dimension3.setExpr("to_monday(from_unixtime(unix_timestamp(imp_date), 'yyyy-MM-dd'))");
dimension3.setType("time");
DimensionTimeTypeParamsTpl dimensionTimeTypeParams3 = new DimensionTimeTypeParamsTpl();
dimensionTimeTypeParams3.setIsPrimary("true");
dimensionTimeTypeParams3.setTimeGranularity("week");
dimension3.setTypeParams(dimensionTimeTypeParams3);
dimensions.add(dimension3);
datasource.setDimensions(dimensions);
List<IdentifyYamlTpl> identifies = new ArrayList<>();
IdentifyYamlTpl identify = new IdentifyYamlTpl();
identify.setName("user_name");
identify.setType("primary");
identifies.add(identify);
datasource.setIdentifiers(identifies);
semanticSchema.getDatasource().put("user_department", SemanticSchemaManagerImpl.getDatasource(datasource));
DimensionYamlTpl dimension1 = new DimensionYamlTpl();
dimension1.setExpr("department");
dimension1.setName("department");
dimension1.setType("categorical");
List<DimensionYamlTpl> dimensionYamlTpls = new ArrayList<>();
dimensionYamlTpls.add(dimension1);
semanticSchema.getDimension()
.put("user_department", SemanticSchemaManagerImpl.getDimensions(dimensionYamlTpls));
}
}