mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 20:25:12 +00:00
[release](project)update version 0.7.4 backend (#66)
This commit is contained in:
@@ -34,6 +34,11 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tencent.supersonic</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
@@ -73,9 +78,6 @@
|
||||
<version>${pagehelper.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
@@ -98,4 +100,4 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -49,12 +48,7 @@ public class CatalogImpl implements Catalog {
|
||||
}
|
||||
|
||||
public DatabaseResp getDatabaseByModelId(Long modelId) {
|
||||
List<DatasourceResp> datasourceResps = datasourceService.getDatasourceList(modelId);
|
||||
if (!CollectionUtils.isEmpty(datasourceResps)) {
|
||||
Long databaseId = datasourceResps.iterator().next().getDatabaseId();
|
||||
return databaseService.getDatabase(databaseId);
|
||||
}
|
||||
return null;
|
||||
return modelService.getDatabaseByModelId(modelId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +71,7 @@ public class CatalogImpl implements Catalog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getModelYamlTplByMoldelIds(Set<Long> modelIds, Map<String, List<DimensionYamlTpl>> dimensionYamlMap,
|
||||
public void getModelYamlTplByModelIds(Set<Long> modelIds, Map<String, List<DimensionYamlTpl>> dimensionYamlMap,
|
||||
List<DatasourceYamlTpl> datasourceYamlTplList, List<MetricYamlTpl> metricYamlTplList) {
|
||||
datasourceService.getModelYamlTplByModelIds(modelIds, dimensionYamlMap, datasourceYamlTplList,
|
||||
metricYamlTplList);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class DatabaseServiceImpl implements DatabaseService {
|
||||
databaseResp.setHasEditPermission(true);
|
||||
databaseResp.setHasUsePermission(true);
|
||||
}
|
||||
if (databaseResp.getViewers().contains(databaseResp.getCreatedBy())) {
|
||||
if (databaseResp.getViewers().contains(user.getName())) {
|
||||
databaseResp.setHasUsePermission(true);
|
||||
}
|
||||
});
|
||||
@@ -108,8 +108,10 @@ public class DatabaseServiceImpl implements DatabaseService {
|
||||
return new QueryResultWithSchemaResp();
|
||||
}
|
||||
List<String> admins = databaseResp.getAdmins();
|
||||
List<String> viewers = databaseResp.getViewers();
|
||||
if (!admins.contains(user.getName())
|
||||
|| !databaseResp.getCreatedBy().equalsIgnoreCase(user.getName())) {
|
||||
&& !viewers.contains(user.getName())
|
||||
&& !databaseResp.getCreatedBy().equalsIgnoreCase(user.getName())) {
|
||||
String message = String.format("您暂无当前数据库%s权限, 请联系数据库管理员%s开通",
|
||||
databaseResp.getName(),
|
||||
String.join(",", admins));
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.DatasourceDetail;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.ItemDateFilter;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
||||
import com.tencent.supersonic.semantic.api.model.yaml.DatasourceYamlTpl;
|
||||
@@ -175,8 +176,17 @@ public class DatasourceServiceImpl implements DatasourceService {
|
||||
|
||||
private void preCheck(DatasourceReq datasourceReq) {
|
||||
List<Dim> dims = datasourceReq.getDimensions();
|
||||
List<Measure> measures = datasourceReq.getMeasures();
|
||||
List<Dim> timeDims = datasourceReq.getTimeDimension();
|
||||
List<Identify> identifies = datasourceReq.getIdentifiers();
|
||||
if (CollectionUtils.isEmpty(dims)) {
|
||||
throw new RuntimeException("lack of dimension");
|
||||
throw new RuntimeException("缺少维度信息");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(identifies)) {
|
||||
throw new RuntimeException("缺少主键信息");
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(measures) && CollectionUtils.isEmpty(timeDims)) {
|
||||
throw new RuntimeException("有度量时, 不可缺少时间维度");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +251,7 @@ public class DatasourceServiceImpl implements DatasourceService {
|
||||
List<MetricResp> metricResps = metricService.getMetrics(modelId, 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");
|
||||
throw new RuntimeException("存在基于该数据源创建的指标和维度, 暂不能删除, 请确认");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.DataAddEvent;
|
||||
import com.tencent.supersonic.common.pojo.DataDeleteEvent;
|
||||
import com.tencent.supersonic.common.pojo.DataUpdateEvent;
|
||||
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
||||
import com.tencent.supersonic.common.util.ChatGptHelper;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.DatasourceDetail;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.DimValueMap;
|
||||
@@ -18,12 +22,12 @@ import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
||||
import com.tencent.supersonic.common.pojo.enums.SensitiveLevelEnum;
|
||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||
import com.tencent.supersonic.semantic.model.domain.DatabaseService;
|
||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||
import com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO;
|
||||
import com.tencent.supersonic.semantic.model.domain.repository.DimensionRepository;
|
||||
import com.tencent.supersonic.semantic.model.domain.utils.DimensionConverter;
|
||||
import com.tencent.supersonic.semantic.model.domain.DatasourceService;
|
||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||
import com.tencent.supersonic.semantic.model.domain.DomainService;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.Dimension;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
|
||||
|
||||
@@ -35,6 +39,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -48,19 +54,22 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
|
||||
private DatasourceService datasourceService;
|
||||
|
||||
private DomainService domainService;
|
||||
private ModelService modelService;
|
||||
|
||||
private ChatGptHelper chatGptHelper;
|
||||
|
||||
private DatabaseService databaseService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
|
||||
public DimensionServiceImpl(DimensionRepository dimensionRepository,
|
||||
DomainService domainService,
|
||||
ModelService modelService,
|
||||
DatasourceService datasourceService,
|
||||
ChatGptHelper chatGptHelper,
|
||||
DatabaseService databaseService) {
|
||||
this.domainService = domainService;
|
||||
this.modelService = modelService;
|
||||
this.dimensionRepository = dimensionRepository;
|
||||
this.datasourceService = datasourceService;
|
||||
this.chatGptHelper = chatGptHelper;
|
||||
@@ -75,6 +84,11 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
log.info("[create dimension] object:{}", JSONObject.toJSONString(dimension));
|
||||
dimension.createdBy(user.getName());
|
||||
saveDimension(dimension);
|
||||
//动态更新字典
|
||||
String type = DictWordType.DIMENSION.getType();
|
||||
DimensionResp dimensionResp = getDimension(dimension.getBizName(), dimension.getModelId());
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DataAddEvent(this, dimension.getName(), dimension.getModelId(), dimensionResp.getId(), type));
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +116,20 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
Dimension dimension = DimensionConverter.convert(dimensionReq);
|
||||
dimension.updatedBy(user.getName());
|
||||
log.info("[update dimension] object:{}", JSONObject.toJSONString(dimension));
|
||||
List<DimensionResp> dimensionRespList = getDimensions(dimensionReq.getModelId()).stream().filter(
|
||||
o -> o.getId().equals(dimensionReq.getId())).collect(Collectors.toList());
|
||||
updateDimension(dimension);
|
||||
//动态更新字典
|
||||
String type = DictWordType.DIMENSION.getType();
|
||||
if (!CollectionUtils.isEmpty(dimensionRespList)) {
|
||||
log.info("dimensionRespList size:{}", dimensionRespList.size());
|
||||
log.info("name:{}", dimensionRespList.get(0).getName());
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DataUpdateEvent(this, dimensionRespList.get(0).getName(),
|
||||
dimensionReq.getName(),
|
||||
dimension.getModelId(),
|
||||
dimensionRespList.get(0).getId(), type));
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateDimension(Dimension dimension) {
|
||||
@@ -148,10 +175,10 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
public List<DimensionResp> getDimensions(List<Long> ids) {
|
||||
List<DimensionResp> dimensionResps = Lists.newArrayList();
|
||||
List<DimensionDO> dimensionDOS = dimensionRepository.getDimensionListByIds(ids);
|
||||
Map<Long, String> fullDomainPathMap = domainService.getDomainFullPath();
|
||||
Map<Long, String> modelFullPathMap = modelService.getModelFullPathMap();
|
||||
if (!CollectionUtils.isEmpty(dimensionDOS)) {
|
||||
dimensionResps = dimensionDOS.stream()
|
||||
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, fullDomainPathMap,
|
||||
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, modelFullPathMap,
|
||||
new HashMap<>()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -184,10 +211,10 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
private List<DimensionResp> convertList(List<DimensionDO> dimensionDOS,
|
||||
Map<Long, DatasourceResp> datasourceRespMap) {
|
||||
List<DimensionResp> dimensionResps = Lists.newArrayList();
|
||||
Map<Long, String> fullDomainPathMap = domainService.getDomainFullPath();
|
||||
Map<Long, String> modelFullPathMap = modelService.getModelFullPathMap();
|
||||
if (!CollectionUtils.isEmpty(dimensionDOS)) {
|
||||
dimensionResps = dimensionDOS.stream()
|
||||
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, fullDomainPathMap,
|
||||
.map(dimensionDO -> DimensionConverter.convert2DimensionResp(dimensionDO, modelFullPathMap,
|
||||
datasourceRespMap))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -256,6 +283,11 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
throw new RuntimeException(String.format("the dimension %s not exist", id));
|
||||
}
|
||||
dimensionRepository.deleteDimension(id);
|
||||
//动态更新字典
|
||||
String type = DictWordType.DIMENSION.getType();
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DataDeleteEvent(this, dimensionDO.getName(), dimensionDO.getModelId(), dimensionDO.getId(), type));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -300,10 +332,19 @@ public class DimensionServiceImpl implements DimensionService {
|
||||
int i = 0;
|
||||
for (Map<String, Object> stringObjectMap : resultList) {
|
||||
DimValueMap dimValueMap = new DimValueMap();
|
||||
dimValueMap.setTechName((String) stringObjectMap.get(dimensionReq.getBizName()));
|
||||
dimValueMap.setBizName(jsonObject.getJSONArray("tran").getString(i));
|
||||
dimValueMap.setAlias(jsonObject.getJSONObject("alias").getJSONArray(
|
||||
(String) stringObjectMap.get(dimensionReq.getBizName())).toJavaList(String.class));
|
||||
dimValueMap.setTechName(String.valueOf(stringObjectMap.get(dimensionReq.getBizName())));
|
||||
try {
|
||||
String tran = jsonObject.getJSONArray("tran").getString(i);
|
||||
dimValueMap.setBizName(tran);
|
||||
} catch (Exception exception) {
|
||||
dimValueMap.setBizName("");
|
||||
}
|
||||
try {
|
||||
dimValueMap.setAlias(jsonObject.getJSONObject("alias")
|
||||
.getJSONArray(stringObjectMap.get(dimensionReq.getBizName()) + "").toJavaList(String.class));
|
||||
} catch (Exception exception) {
|
||||
dimValueMap.setAlias(null);
|
||||
}
|
||||
dimValueMapsResp.add(dimValueMap);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ public class DomainServiceImpl implements DomainService {
|
||||
|
||||
@Override
|
||||
public void deleteDomain(Long id) {
|
||||
List<ModelResp> modelResps = modelService.getModelByDomainIds(Lists.newArrayList(id));
|
||||
if (!CollectionUtils.isEmpty(modelResps)) {
|
||||
throw new RuntimeException("该主题域下还存在模型, 暂不能删除, 请确认");
|
||||
}
|
||||
domainRepository.deleteDomain(id);
|
||||
}
|
||||
|
||||
@@ -124,7 +128,9 @@ public class DomainServiceImpl implements DomainService {
|
||||
List<Long> domainIds = domainWithAuth.stream().map(DomainResp::getId)
|
||||
.collect(Collectors.toList());
|
||||
//get all child domain
|
||||
return getDomainChildren(domainIds);
|
||||
return getDomainChildren(domainIds).stream()
|
||||
.peek(domainResp -> domainResp.setHasEditPermission(true))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private Set<DomainResp> getParentDomain(List<Long> ids) {
|
||||
|
||||
@@ -6,6 +6,10 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.DataAddEvent;
|
||||
import com.tencent.supersonic.common.pojo.DataDeleteEvent;
|
||||
import com.tencent.supersonic.common.pojo.DataUpdateEvent;
|
||||
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
||||
import com.tencent.supersonic.common.util.ChatGptHelper;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.MetricTypeParams;
|
||||
@@ -23,14 +27,18 @@ import com.tencent.supersonic.semantic.model.domain.repository.MetricRepository;
|
||||
import com.tencent.supersonic.semantic.model.domain.utils.MetricConverter;
|
||||
import com.tencent.supersonic.semantic.model.domain.MetricService;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.Metric;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -46,6 +54,9 @@ public class MetricServiceImpl implements MetricService {
|
||||
|
||||
private ChatGptHelper chatGptHelper;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
public MetricServiceImpl(MetricRepository metricRepository,
|
||||
ModelService modelService,
|
||||
DomainService domainService,
|
||||
@@ -63,6 +74,11 @@ public class MetricServiceImpl implements MetricService {
|
||||
metric.createdBy(user.getName());
|
||||
log.info("[create metric] object:{}", JSONObject.toJSONString(metric));
|
||||
saveMetric(metric);
|
||||
//动态更新字典
|
||||
String type = DictWordType.METRIC.getType();
|
||||
MetricResp metricResp = getMetric(metric.getModelId(), metric.getBizName());
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DataAddEvent(this, metric.getName(), metric.getModelId(), metricResp.getId(), type));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,7 +166,21 @@ public class MetricServiceImpl implements MetricService {
|
||||
Metric metric = MetricConverter.convert(metricReq);
|
||||
metric.updatedBy(user.getName());
|
||||
log.info("[update metric] object:{}", JSONObject.toJSONString(metric));
|
||||
List<MetricResp> metricRespList = getMetrics(metricReq.getModelId()).stream().filter(
|
||||
o -> o.getId().equals(metricReq.getId())).collect(Collectors.toList());
|
||||
updateMetric(metric);
|
||||
//动态更新字典
|
||||
String type = DictWordType.METRIC.getType();
|
||||
//MetricResp metricResp = getMetric(metric.getModelId(), metric.getBizName());
|
||||
if (!CollectionUtils.isEmpty(metricRespList)) {
|
||||
log.info("metricRespList size:{}", metricRespList.size());
|
||||
log.info("name:{}", metricRespList.get(0).getName());
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DataUpdateEvent(this, metricRespList.get(0).getName(),
|
||||
metricReq.getName(),
|
||||
metric.getModelId(),
|
||||
metricRespList.get(0).getId(), type));
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMetric(Metric metric) {
|
||||
@@ -205,6 +235,10 @@ public class MetricServiceImpl implements MetricService {
|
||||
throw new RuntimeException(String.format("the metric %s not exist", id));
|
||||
}
|
||||
metricRepository.deleteMetric(id);
|
||||
//动态更新字典
|
||||
String type = DictWordType.METRIC.getType();
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DataDeleteEvent(this, metricDO.getName(), metricDO.getModelId(), metricDO.getId(), type));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,7 +251,6 @@ public class MetricServiceImpl implements MetricService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void saveMetricBatch(List<Metric> metrics, User user) {
|
||||
if (CollectionUtils.isEmpty(metrics)) {
|
||||
return;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
||||
import com.tencent.supersonic.semantic.api.model.request.ModelSchemaFilterReq;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DomainResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DimensionResp;
|
||||
@@ -17,6 +18,7 @@ import com.tencent.supersonic.semantic.api.model.response.DimSchemaResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.MetricSchemaResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatasourceResp;
|
||||
import com.tencent.supersonic.semantic.model.domain.DatabaseService;
|
||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||
import com.tencent.supersonic.semantic.model.domain.DomainService;
|
||||
import com.tencent.supersonic.semantic.model.domain.DimensionService;
|
||||
@@ -51,16 +53,19 @@ public class ModelServiceImpl implements ModelService {
|
||||
private final DatasourceService datasourceService;
|
||||
private final DomainService domainService;
|
||||
private final UserService userService;
|
||||
private final DatabaseService databaseService;
|
||||
|
||||
public ModelServiceImpl(ModelRepository modelRepository, @Lazy MetricService metricService,
|
||||
@Lazy DimensionService dimensionService, @Lazy DatasourceService datasourceService,
|
||||
@Lazy DomainService domainService, UserService userService) {
|
||||
@Lazy DomainService domainService, UserService userService,
|
||||
@Lazy DatabaseService databaseService) {
|
||||
this.modelRepository = modelRepository;
|
||||
this.metricService = metricService;
|
||||
this.dimensionService = dimensionService;
|
||||
this.datasourceService = datasourceService;
|
||||
this.domainService = domainService;
|
||||
this.userService = userService;
|
||||
this.databaseService = databaseService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,7 +177,7 @@ public class ModelServiceImpl implements ModelService {
|
||||
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 model, please check");
|
||||
throw new RuntimeException("该模型下存在数据源、指标或者维度, 暂不能删除, 请确认");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +282,16 @@ public class ModelServiceImpl implements ModelService {
|
||||
return modelSchemaRespList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseResp getDatabaseByModelId(Long modelId) {
|
||||
List<DatasourceResp> datasourceResps = datasourceService.getDatasourceList(modelId);
|
||||
if (!CollectionUtils.isEmpty(datasourceResps)) {
|
||||
Long databaseId = datasourceResps.iterator().next().getDatabaseId();
|
||||
return databaseService.getDatabase(databaseId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<MetricSchemaResp> generateMetricSchema(Long modelId) {
|
||||
List<MetricSchemaResp> metricSchemaDescList = new ArrayList<>();
|
||||
List<MetricResp> metricDescList = metricService.getMetrics(modelId);
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface Catalog {
|
||||
|
||||
List<MetricResp> getMetrics(Long modelId);
|
||||
|
||||
void getModelYamlTplByMoldelIds(Set<Long> modelIds, Map<String, List<DimensionYamlTpl>> dimensionYamlMap,
|
||||
void getModelYamlTplByModelIds(Set<Long> modelIds, Map<String, List<DimensionYamlTpl>> dimensionYamlMap,
|
||||
List<DatasourceYamlTpl> datasourceYamlTplList, List<MetricYamlTpl> metricYamlTplList);
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
||||
import com.tencent.supersonic.semantic.api.model.request.ModelSchemaFilterReq;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||
|
||||
@@ -39,4 +40,6 @@ public interface ModelService {
|
||||
ModelSchemaResp fetchSingleModelSchema(Long modelId);
|
||||
|
||||
List<ModelSchemaResp> fetchModelSchema(ModelSchemaFilterReq modelSchemaFilterReq);
|
||||
|
||||
DatabaseResp getDatabaseByModelId(Long modelId);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.tencent.supersonic.semantic.model.domain.adaptor.engineadapter;
|
||||
|
||||
import com.tencent.supersonic.common.util.jsqlparser.SqlParserUpdateHelper;
|
||||
import com.tencent.supersonic.semantic.api.model.enums.TimeDimensionEnum;
|
||||
import com.tencent.supersonic.common.pojo.Constants;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ClickHouseAdaptor extends EngineAdaptor {
|
||||
|
||||
@@ -40,6 +43,15 @@ public class ClickHouseAdaptor extends EngineAdaptor {
|
||||
return "select name from system.tables where database = '%s';";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String functionNameCorrector(String sql) {
|
||||
Map<String, String> functionMap = new HashMap<>();
|
||||
functionMap.put("MONTH".toLowerCase(), "toMonth");
|
||||
functionMap.put("DAY".toLowerCase(), "toDayOfMonth");
|
||||
functionMap.put("YEAR".toLowerCase(), "toYear");
|
||||
return SqlParserUpdateHelper.replaceFunction(sql, functionMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnMetaQueryTpl() {
|
||||
return "select name,type as dataType, comment from system.columns where database = '%s' and table='%s'";
|
||||
|
||||
@@ -12,4 +12,6 @@ public abstract class EngineAdaptor {
|
||||
public abstract String getDbMetaQueryTpl();
|
||||
|
||||
public abstract String getTableMetaQueryTpl();
|
||||
|
||||
public abstract String functionNameCorrector(String sql);
|
||||
}
|
||||
|
||||
@@ -43,4 +43,9 @@ public class H2Adaptor extends EngineAdaptor {
|
||||
return "SELECT TABLE_NAME as name FROM INFORMATION_SCHEMA.TABLES "
|
||||
+ "WHERE STORAGE_TYPE = 'MEMORY' AND TABLE_SCHEMA = '%s'";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String functionNameCorrector(String sql) {
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ public class MysqlAdaptor extends EngineAdaptor {
|
||||
return "select TABLE_NAME as name from information_schema.tables where TABLE_SCHEMA = '%s';";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String functionNameCorrector(String sql) {
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnMetaQueryTpl() {
|
||||
return "SELECT COLUMN_NAME as name, DATA_TYPE as dataType, COLUMN_COMMENT as comment "
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.tencent.supersonic.semantic.model.domain.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class YamlConfig {
|
||||
|
||||
|
||||
@Value("${model.yaml.file.dir: conf/models/}")
|
||||
private String metaYamlFileDir;
|
||||
|
||||
public String getmetaYamlFileDir() {
|
||||
return metaYamlFileDir;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,6 +58,7 @@ public class DatasourceDO {
|
||||
*/
|
||||
private String datasourceDetail;
|
||||
|
||||
|
||||
/**
|
||||
* @return id
|
||||
*/
|
||||
@@ -251,4 +252,6 @@ public class DatasourceDO {
|
||||
public void setDatasourceDetail(String datasourceDetail) {
|
||||
this.datasourceDetail = datasourceDetail == null ? null : datasourceDetail.trim();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,144 +3,318 @@ package com.tencent.supersonic.semantic.model.domain.dataobject;
|
||||
import java.util.Date;
|
||||
|
||||
public class ModelDO {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String bizName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long domainId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String alias;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String viewer;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String viewOrg;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String admin;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String adminOrg;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Integer isOpen;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Date createdAt;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String updatedBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Date updatedAt;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String entity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name == null ? null : name.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return biz_name
|
||||
*/
|
||||
public String getBizName() {
|
||||
return bizName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bizName
|
||||
*/
|
||||
public void setBizName(String bizName) {
|
||||
this.bizName = bizName == null ? null : bizName.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return domain_id
|
||||
*/
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param domainId
|
||||
*/
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param alias
|
||||
*/
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias == null ? null : alias.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return viewer
|
||||
*/
|
||||
public String getViewer() {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param viewer
|
||||
*/
|
||||
public void setViewer(String viewer) {
|
||||
this.viewer = viewer == null ? null : viewer.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return view_org
|
||||
*/
|
||||
public String getViewOrg() {
|
||||
return viewOrg;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param viewOrg
|
||||
*/
|
||||
public void setViewOrg(String viewOrg) {
|
||||
this.viewOrg = viewOrg == null ? null : viewOrg.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return admin
|
||||
*/
|
||||
public String getAdmin() {
|
||||
return admin;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param admin
|
||||
*/
|
||||
public void setAdmin(String admin) {
|
||||
this.admin = admin == null ? null : admin.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return admin_org
|
||||
*/
|
||||
public String getAdminOrg() {
|
||||
return adminOrg;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param adminOrg
|
||||
*/
|
||||
public void setAdminOrg(String adminOrg) {
|
||||
this.adminOrg = adminOrg == null ? null : adminOrg.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return is_open
|
||||
*/
|
||||
public Integer getIsOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param isOpen
|
||||
*/
|
||||
public void setIsOpen(Integer isOpen) {
|
||||
this.isOpen = isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return created_by
|
||||
*/
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param createdBy
|
||||
*/
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy == null ? null : createdBy.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return created_at
|
||||
*/
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param createdAt
|
||||
*/
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return updated_by
|
||||
*/
|
||||
public String getUpdatedBy() {
|
||||
return updatedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param updatedBy
|
||||
*/
|
||||
public void setUpdatedBy(String updatedBy) {
|
||||
this.updatedBy = updatedBy == null ? null : updatedBy.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return updated_at
|
||||
*/
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param updatedAt
|
||||
*/
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return entity
|
||||
*/
|
||||
public String getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
public void setEntity(String entity) {
|
||||
this.entity = entity == null ? null : entity.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class ModelDOExample {
|
||||
protected Integer limitEnd;
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public ModelDOExample() {
|
||||
@@ -38,6 +39,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
@@ -45,6 +47,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getOrderByClause() {
|
||||
@@ -52,6 +55,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setDistinct(boolean distinct) {
|
||||
@@ -59,6 +63,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public boolean isDistinct() {
|
||||
@@ -66,6 +71,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public List<Criteria> getOredCriteria() {
|
||||
@@ -73,6 +79,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void or(Criteria criteria) {
|
||||
@@ -80,6 +87,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Criteria or() {
|
||||
@@ -89,6 +97,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Criteria createCriteria() {
|
||||
@@ -100,6 +109,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
protected Criteria createCriteriaInternal() {
|
||||
@@ -108,6 +118,7 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void clear() {
|
||||
@@ -117,13 +128,15 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setLimitStart(Integer limitStart) {
|
||||
this.limitStart = limitStart;
|
||||
this.limitStart=limitStart;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getLimitStart() {
|
||||
@@ -131,13 +144,15 @@ public class ModelDOExample {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setLimitEnd(Integer limitEnd) {
|
||||
this.limitEnd = limitEnd;
|
||||
this.limitEnd=limitEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getLimitEnd() {
|
||||
@@ -448,6 +463,76 @@ public class ModelDOExample {
|
||||
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 andViewerIsNull() {
|
||||
addCriterion("viewer is null");
|
||||
return (Criteria) this;
|
||||
@@ -1079,6 +1164,38 @@ public class ModelDOExample {
|
||||
|
||||
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;
|
||||
@@ -1114,37 +1231,5 @@ public class ModelDOExample {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,17 @@ import com.tencent.supersonic.semantic.api.model.pojo.DatasourceDetail;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Dim;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Identify;
|
||||
import com.tencent.supersonic.semantic.api.model.pojo.Measure;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||
import com.tencent.supersonic.semantic.api.model.yaml.DatasourceYamlTpl;
|
||||
import com.tencent.supersonic.semantic.api.model.yaml.DimensionTimeTypeParamsTpl;
|
||||
import com.tencent.supersonic.semantic.api.model.yaml.DimensionYamlTpl;
|
||||
import com.tencent.supersonic.semantic.api.model.yaml.IdentifyYamlTpl;
|
||||
import com.tencent.supersonic.semantic.api.model.yaml.MeasureYamlTpl;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||
import com.tencent.supersonic.semantic.model.domain.utils.SysTimeDimensionBuilder;
|
||||
import com.tencent.supersonic.semantic.model.domain.adaptor.engineadapter.EngineAdaptor;
|
||||
import com.tencent.supersonic.semantic.model.domain.adaptor.engineadapter.EngineAdaptorFactory;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.Datasource;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.DatasourceQueryEnum;
|
||||
import com.tencent.supersonic.semantic.model.domain.utils.SysTimeDimensionBuilder;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
@@ -16,4 +16,5 @@ public class Datasource extends SchemaItem {
|
||||
private DatasourceDetail datasourceDetail;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
@Data
|
||||
public class MetaFilter {
|
||||
|
||||
private Long id;
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -21,4 +21,6 @@ public class MetaFilter {
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String key;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,4 @@ public class MetricFilter extends MetaFilter {
|
||||
|
||||
private String type;
|
||||
|
||||
private String key;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ public class Model extends SchemaItem {
|
||||
|
||||
private Integer isOpen;
|
||||
|
||||
private String alias;
|
||||
|
||||
private List<String> viewers;
|
||||
|
||||
private List<String> viewOrgs;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DimensionConverter {
|
||||
Map<Long, DatasourceResp> datasourceRespMap) {
|
||||
DimensionResp dimensionResp = new DimensionResp();
|
||||
BeanUtils.copyProperties(dimensionDO, dimensionResp);
|
||||
dimensionResp.setFullPath(fullPathMap.get(dimensionDO.getModelId()) + dimensionDO.getBizName());
|
||||
dimensionResp.setFullPath(fullPathMap.get(dimensionDO.getModelId()) + "/" + dimensionDO.getBizName());
|
||||
dimensionResp.setDatasourceId(
|
||||
datasourceRespMap.getOrDefault(dimensionResp.getDatasourceId(), new DatasourceResp()).getId());
|
||||
dimensionResp.setDatasourceName(
|
||||
|
||||
@@ -2,8 +2,9 @@ package com.tencent.supersonic.semantic.model.domain.utils;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.AT_SYMBOL;
|
||||
|
||||
import com.tencent.supersonic.semantic.api.model.enums.DataTypeEnum;
|
||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||
import com.tencent.supersonic.common.util.DateUtils;
|
||||
import com.tencent.supersonic.semantic.api.model.enums.DataTypeEnum;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.QueryResultWithSchemaResp;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.JdbcDataSource;
|
||||
@@ -12,7 +13,11 @@ import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -147,11 +152,26 @@ public class SqlUtils {
|
||||
for (QueryColumn queryColumn : queryColumns) {
|
||||
String colName = queryColumn.getNameEn();
|
||||
Object value = rs.getObject(colName);
|
||||
map.put(colName, value instanceof byte[] ? new String((byte[]) value) : value);
|
||||
map.put(colName, getValue(value));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private Object getValue(Object value) {
|
||||
if (value instanceof LocalDate) {
|
||||
LocalDate localDate = (LocalDate) value;
|
||||
return localDate.format(DateTimeFormatter.ofPattern(DateUtils.DATE_FORMAT));
|
||||
} else if (value instanceof LocalDateTime) {
|
||||
LocalDateTime localDateTime = (LocalDateTime) value;
|
||||
return localDateTime.format(DateTimeFormatter.ofPattern(DateUtils.TIME_FORMAT));
|
||||
} else if (value instanceof Date) {
|
||||
Date date = (Date) value;
|
||||
return DateUtils.format(date);
|
||||
} else if (value instanceof byte[]) {
|
||||
return new String((byte[]) value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static final class SqlUtilsBuilder {
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.tencent.supersonic.semantic.model.infrastructure.mapper;
|
||||
|
||||
|
||||
import com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO;
|
||||
|
||||
import java.util.List;
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
@@ -13,4 +13,5 @@ public interface DimensionDOCustomMapper {
|
||||
|
||||
void batchUpdate(List<DimensionDO> dimensionDOS);
|
||||
|
||||
List<DimensionDO> query(DimensionFilter dimensionFilter);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import com.tencent.supersonic.semantic.model.domain.repository.DimensionReposito
|
||||
import com.tencent.supersonic.semantic.model.domain.pojo.DimensionFilter;
|
||||
import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOCustomMapper;
|
||||
import com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@@ -84,27 +81,7 @@ public class DimensionRepositoryImpl implements DimensionRepository {
|
||||
|
||||
@Override
|
||||
public List<DimensionDO> getDimension(DimensionFilter dimensionFilter) {
|
||||
DimensionDOExample dimensionDOExample = new DimensionDOExample();
|
||||
dimensionDOExample.createCriteria();
|
||||
if (dimensionFilter.getId() != null) {
|
||||
dimensionDOExample.getOredCriteria().get(0).andIdEqualTo(dimensionFilter.getId());
|
||||
}
|
||||
if (dimensionFilter.getName() != null) {
|
||||
dimensionDOExample.getOredCriteria().get(0).andNameLike("%" + dimensionFilter.getName() + "%");
|
||||
}
|
||||
if (dimensionFilter.getBizName() != null) {
|
||||
dimensionDOExample.getOredCriteria().get(0).andBizNameLike("%" + dimensionFilter.getBizName() + "%");
|
||||
}
|
||||
if (dimensionFilter.getCreatedBy() != null) {
|
||||
dimensionDOExample.getOredCriteria().get(0).andCreatedByEqualTo(dimensionFilter.getCreatedBy());
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(dimensionFilter.getModelIds())) {
|
||||
dimensionDOExample.getOredCriteria().get(0).andModelIdIn(dimensionFilter.getModelIds());
|
||||
}
|
||||
if (dimensionFilter.getSensitiveLevel() != null) {
|
||||
dimensionDOExample.getOredCriteria().get(0).andSensitiveLevelEqualTo(dimensionFilter.getSensitiveLevel());
|
||||
}
|
||||
return dimensionDOMapper.selectByExampleWithBLOBs(dimensionDOExample);
|
||||
return dimensionDOCustomMapper.query(dimensionFilter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.semantic.api.model.request.ModelReq;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DatabaseResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.ModelResp;
|
||||
import com.tencent.supersonic.semantic.model.domain.ModelService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -74,4 +75,9 @@ public class ModelController {
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@GetMapping("/getModelDatabase/{modelId}")
|
||||
public DatabaseResp getModelDatabase(@PathVariable("modelId") Long modelId) {
|
||||
return modelService.getDatabaseByModelId(modelId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="biz_name" jdbcType="VARCHAR" property="bizName" />
|
||||
<result column="domain_id" jdbcType="BIGINT" property="domainId" />
|
||||
<result column="alias" jdbcType="VARCHAR" property="alias" />
|
||||
<result column="viewer" jdbcType="VARCHAR" property="viewer" />
|
||||
<result column="view_org" jdbcType="VARCHAR" property="viewOrg" />
|
||||
<result column="admin" jdbcType="VARCHAR" property="admin" />
|
||||
@@ -78,8 +79,8 @@
|
||||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, name, biz_name, domain_id, viewer, view_org, admin, admin_org, is_open, created_by,
|
||||
created_at, updated_by, updated_at
|
||||
id, name, biz_name, domain_id, alias, viewer, view_org, admin, admin_org, is_open,
|
||||
created_by, created_at, updated_by, updated_at
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
entity
|
||||
@@ -131,15 +132,17 @@
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.tencent.supersonic.semantic.model.domain.dataobject.ModelDO">
|
||||
insert into s2_model (id, name, biz_name,
|
||||
domain_id, viewer, view_org,
|
||||
admin, admin_org, is_open,
|
||||
created_by, created_at, updated_by,
|
||||
updated_at, entity)
|
||||
domain_id, alias, viewer,
|
||||
view_org, admin, admin_org,
|
||||
is_open, created_by, created_at,
|
||||
updated_by, updated_at, entity
|
||||
)
|
||||
values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{bizName,jdbcType=VARCHAR},
|
||||
#{domainId,jdbcType=BIGINT}, #{viewer,jdbcType=VARCHAR}, #{viewOrg,jdbcType=VARCHAR},
|
||||
#{admin,jdbcType=VARCHAR}, #{adminOrg,jdbcType=VARCHAR}, #{isOpen,jdbcType=INTEGER},
|
||||
#{createdBy,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR},
|
||||
#{updatedAt,jdbcType=TIMESTAMP}, #{entity,jdbcType=LONGVARCHAR})
|
||||
#{domainId,jdbcType=BIGINT}, #{alias,jdbcType=VARCHAR}, #{viewer,jdbcType=VARCHAR},
|
||||
#{viewOrg,jdbcType=VARCHAR}, #{admin,jdbcType=VARCHAR}, #{adminOrg,jdbcType=VARCHAR},
|
||||
#{isOpen,jdbcType=INTEGER}, #{createdBy,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP},
|
||||
#{updatedBy,jdbcType=VARCHAR}, #{updatedAt,jdbcType=TIMESTAMP}, #{entity,jdbcType=LONGVARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.tencent.supersonic.semantic.model.domain.dataobject.ModelDO">
|
||||
insert into s2_model
|
||||
@@ -156,6 +159,9 @@
|
||||
<if test="domainId != null">
|
||||
domain_id,
|
||||
</if>
|
||||
<if test="alias != null">
|
||||
alias,
|
||||
</if>
|
||||
<if test="viewer != null">
|
||||
viewer,
|
||||
</if>
|
||||
@@ -200,6 +206,9 @@
|
||||
<if test="domainId != null">
|
||||
#{domainId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="alias != null">
|
||||
#{alias,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="viewer != null">
|
||||
#{viewer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
@@ -253,6 +262,9 @@
|
||||
<if test="record.domainId != null">
|
||||
domain_id = #{record.domainId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="record.alias != null">
|
||||
alias = #{record.alias,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.viewer != null">
|
||||
viewer = #{record.viewer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
@@ -294,6 +306,7 @@
|
||||
name = #{record.name,jdbcType=VARCHAR},
|
||||
biz_name = #{record.bizName,jdbcType=VARCHAR},
|
||||
domain_id = #{record.domainId,jdbcType=BIGINT},
|
||||
alias = #{record.alias,jdbcType=VARCHAR},
|
||||
viewer = #{record.viewer,jdbcType=VARCHAR},
|
||||
view_org = #{record.viewOrg,jdbcType=VARCHAR},
|
||||
admin = #{record.admin,jdbcType=VARCHAR},
|
||||
@@ -314,6 +327,7 @@
|
||||
name = #{record.name,jdbcType=VARCHAR},
|
||||
biz_name = #{record.bizName,jdbcType=VARCHAR},
|
||||
domain_id = #{record.domainId,jdbcType=BIGINT},
|
||||
alias = #{record.alias,jdbcType=VARCHAR},
|
||||
viewer = #{record.viewer,jdbcType=VARCHAR},
|
||||
view_org = #{record.viewOrg,jdbcType=VARCHAR},
|
||||
admin = #{record.admin,jdbcType=VARCHAR},
|
||||
@@ -339,6 +353,9 @@
|
||||
<if test="domainId != null">
|
||||
domain_id = #{domainId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="alias != null">
|
||||
alias = #{alias,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="viewer != null">
|
||||
viewer = #{viewer,jdbcType=VARCHAR},
|
||||
</if>
|
||||
@@ -377,6 +394,7 @@
|
||||
set name = #{name,jdbcType=VARCHAR},
|
||||
biz_name = #{bizName,jdbcType=VARCHAR},
|
||||
domain_id = #{domainId,jdbcType=BIGINT},
|
||||
alias = #{alias,jdbcType=VARCHAR},
|
||||
viewer = #{viewer,jdbcType=VARCHAR},
|
||||
view_org = #{viewOrg,jdbcType=VARCHAR},
|
||||
admin = #{admin,jdbcType=VARCHAR},
|
||||
@@ -394,6 +412,7 @@
|
||||
set name = #{name,jdbcType=VARCHAR},
|
||||
biz_name = #{bizName,jdbcType=VARCHAR},
|
||||
domain_id = #{domainId,jdbcType=BIGINT},
|
||||
alias = #{alias,jdbcType=VARCHAR},
|
||||
viewer = #{viewer,jdbcType=VARCHAR},
|
||||
view_org = #{viewOrg,jdbcType=VARCHAR},
|
||||
admin = #{admin,jdbcType=VARCHAR},
|
||||
|
||||
@@ -2,23 +2,28 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.tencent.supersonic.semantic.model.infrastructure.mapper.DimensionDOCustomMapper">
|
||||
<resultMap id="BaseResultMap"
|
||||
type="com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<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="model_id" jdbcType="BIGINT" property="modelId"/>
|
||||
<result column="type" jdbcType="VARCHAR" property="type"/>
|
||||
<result column="type_params" jdbcType="VARCHAR" property="typeParams"/>
|
||||
<result column="expr" jdbcType="VARCHAR" property="expr"/>
|
||||
<result column="datasource_id" jdbcType="BIGINT" property="datasourceId"/>
|
||||
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
|
||||
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
|
||||
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
|
||||
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
|
||||
<result column="semantic_type" jdbcType="VARCHAR" property="semanticType"/>
|
||||
<resultMap id="BaseResultMap" type="com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO">
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="model_id" jdbcType="BIGINT" property="modelId" />
|
||||
<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" />
|
||||
<result column="dim_value_maps" jdbcType="VARCHAR" property="dimValueMaps" />
|
||||
</resultMap>
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tencent.supersonic.semantic.model.domain.dataobject.DimensionDO">
|
||||
<result column="type_params" jdbcType="LONGVARCHAR" property="typeParams" />
|
||||
<result column="expr" jdbcType="LONGVARCHAR" property="expr" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
@@ -102,5 +107,36 @@
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<select id="query" resultMap="ResultMapWithBLOBs">
|
||||
select *
|
||||
from s2_dimension
|
||||
where 1=1
|
||||
<if test="key != null and key != ''">
|
||||
and ( id like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
|
||||
name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
|
||||
biz_name like CONCAT('%',#{key , jdbcType=VARCHAR},'%') or
|
||||
description like CONCAT('%',#{key , jdbcType=VARCHAR},'%') )
|
||||
</if>
|
||||
<if test="id != null">
|
||||
and id like CONCAT('%',#{id , jdbcType=VARCHAR},'%')
|
||||
</if>
|
||||
<if test="name != null and name != '' ">
|
||||
and name like CONCAT('%',#{name , jdbcType=VARCHAR},'%')
|
||||
</if>
|
||||
<if test="bizName != null and bizName != ''">
|
||||
and biz_name like CONCAT('%',#{bizName , jdbcType=VARCHAR},'%')
|
||||
</if>
|
||||
<if test="sensitiveLevel != null">
|
||||
and sensitive_level = #{sensitiveLevel}
|
||||
</if>
|
||||
<if test="modelIds != null and modelIds.size >0">
|
||||
and model_id in
|
||||
<foreach collection="modelIds" index="index" item="model" open="(" close=")"
|
||||
separator=",">
|
||||
#{model}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -35,4 +35,4 @@ CREATE TABLE IF NOT EXISTS `s2_datasource`
|
||||
(
|
||||
100
|
||||
) NOT NULL COMMENT '更新人'
|
||||
) comment '数据源表'
|
||||
) comment '数据源表'
|
||||
Reference in New Issue
Block a user