mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-04-26 01:34:53 +08:00
Compare commits
22 Commits
6c5f8fce40
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ff1a76a9e | ||
|
|
aa86e3f02a | ||
|
|
0bbab5e7b1 | ||
|
|
d373567cef | ||
|
|
80a1f62d3f | ||
|
|
4379af4bd4 | ||
|
|
8a4bccab10 | ||
|
|
507af43b73 | ||
|
|
c1d50f978d | ||
|
|
18ce934bba | ||
|
|
6fe0ebcb9d | ||
|
|
77d8d63df7 | ||
|
|
0876f5eae8 | ||
|
|
ddbaf53ad4 | ||
|
|
4c97d01eab | ||
|
|
008f1443cb | ||
|
|
29c1119ee2 | ||
|
|
d658e437fb | ||
|
|
b6f561f18c | ||
|
|
593d26a072 | ||
|
|
9162b922c4 | ||
|
|
1d9324f689 |
113
CLAUDE.md
Normal file
113
CLAUDE.md
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Build Commands
|
||||||
|
|
||||||
|
### Backend (Java/Maven)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clean build (skip tests)
|
||||||
|
mvn clean package -DskipTests -Dspotless.skip=true
|
||||||
|
|
||||||
|
# Run all tests
|
||||||
|
mvn test
|
||||||
|
|
||||||
|
# Run single test class
|
||||||
|
mvn test -Dtest=ClassName
|
||||||
|
|
||||||
|
# Full CI build
|
||||||
|
mvn -B package --file pom.xml
|
||||||
|
```
|
||||||
|
|
||||||
|
**Requirements:** Java 21, Maven
|
||||||
|
|
||||||
|
### Frontend (pnpm/React)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd webapp
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
pnpm install
|
||||||
|
|
||||||
|
# Start dev server (port 9000)
|
||||||
|
pnpm dev
|
||||||
|
|
||||||
|
# Production build
|
||||||
|
pnpm build
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
pnpm test
|
||||||
|
```
|
||||||
|
|
||||||
|
**Requirements:** Node.js >=16, pnpm 9.12.3+
|
||||||
|
|
||||||
|
### Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build full release
|
||||||
|
./assembly/bin/supersonic-build.sh standalone
|
||||||
|
|
||||||
|
# Start service
|
||||||
|
./assembly/bin/supersonic-daemon.sh start
|
||||||
|
|
||||||
|
# Stop service
|
||||||
|
./assembly/bin/supersonic-daemon.sh stop
|
||||||
|
```
|
||||||
|
|
||||||
|
Visit http://localhost:9080 after startup.
|
||||||
|
|
||||||
|
## Architecture Overview
|
||||||
|
|
||||||
|
SuperSonic unifies **Chat BI** (LLM-powered) and **Headless BI** (semantic layer) paradigms.
|
||||||
|
|
||||||
|
### Core Modules
|
||||||
|
|
||||||
|
```
|
||||||
|
supersonic/
|
||||||
|
├── auth/ # Authentication & authorization (SPI-based)
|
||||||
|
├── chat/ # Chat BI module - LLM-powered Q&A interface
|
||||||
|
├── common/ # Shared utilities
|
||||||
|
├── headless/ # Headless BI - semantic layer with open API
|
||||||
|
├── launchers/ # Application entry points
|
||||||
|
│ ├── standalone/ # Combined Chat + Headless (default)
|
||||||
|
│ ├── chat/ # Chat-only service
|
||||||
|
│ └── headless/ # Headless-only service
|
||||||
|
└── webapp/ # Frontend React app (UmiJS 4 + Ant Design)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Data Flow
|
||||||
|
|
||||||
|
1. **Knowledge Base**: Extracts schema from semantic models, builds dictionary/index for schema mapping
|
||||||
|
2. **Schema Mapper**: Identifies metrics/dimensions/entities/values in user queries
|
||||||
|
3. **Semantic Parser**: Generates S2SQL (semantic SQL) using rule-based and LLM-based parsers
|
||||||
|
4. **Semantic Corrector**: Validates and corrects semantic queries
|
||||||
|
5. **Semantic Translator**: Converts S2SQL to executable SQL
|
||||||
|
|
||||||
|
### Key Entry Points
|
||||||
|
|
||||||
|
- `StandaloneLauncher.java` - Combined service with `scanBasePackages: ["com.tencent.supersonic", "dev.langchain4j"]`
|
||||||
|
- `ChatLauncher.java` - Chat BI only
|
||||||
|
- `HeadlessLauncher.java` - Headless BI only
|
||||||
|
|
||||||
|
## Key Technologies
|
||||||
|
|
||||||
|
**Backend:** Spring Boot 3.3.9, MyBatis-Plus 3.5.10.1, LangChain4j 0.36.2, JSqlParser 4.9, Calcite 1.38.0
|
||||||
|
|
||||||
|
**Frontend:** React 18, UmiJS 4, Ant Design 5.17.4, ECharts 5.0.2, AntV G6/X6
|
||||||
|
|
||||||
|
**Databases:** MySQL, PostgreSQL (with pgvector), H2, ClickHouse, StarRocks, Presto, Trino, DuckDB
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
**Java tests:** JUnit 5, Mockito. Located in `src/test/java/` of each module.
|
||||||
|
|
||||||
|
**Frontend tests:** Jest with Puppeteer environment in `webapp/packages/supersonic-fe/`
|
||||||
|
|
||||||
|
**Evaluation scripts:** Python scripts in `evaluation/` directory for Text2SQL accuracy testing.
|
||||||
|
|
||||||
|
## Related Documentation
|
||||||
|
|
||||||
|
- [README.md](README.md) - English documentation
|
||||||
|
- [README_CN.md](README_CN.md) - Chinese documentation
|
||||||
|
- [Evaluation Guide](evaluation/README.md) - Text2SQL evaluation process
|
||||||
@@ -15,4 +15,6 @@ public class UserReq {
|
|||||||
|
|
||||||
@NotBlank(message = "password can not be null")
|
@NotBlank(message = "password can not be null")
|
||||||
private String newPassword;
|
private String newPassword;
|
||||||
|
|
||||||
|
private String role;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public class QueryResp {
|
|||||||
private Long questionId;
|
private Long questionId;
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
private Long chatId;
|
private Long chatId;
|
||||||
|
private Integer agentId;
|
||||||
private Integer score;
|
private Integer score;
|
||||||
private String feedback;
|
private String feedback;
|
||||||
private String queryText;
|
private String queryText;
|
||||||
|
|||||||
@@ -18,4 +18,6 @@ public interface ChatParseMapper {
|
|||||||
List<ChatParseDO> getParseInfoList(List<Long> questionIds);
|
List<ChatParseDO> getParseInfoList(List<Long> questionIds);
|
||||||
|
|
||||||
List<ChatParseDO> getContextualParseInfo(Integer chatId);
|
List<ChatParseDO> getContextualParseInfo(Integer chatId);
|
||||||
|
|
||||||
|
int deleteByQuestionId(Long questionId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,4 +52,6 @@ public interface ChatManageService {
|
|||||||
List<ChatParseDO> batchAddParse(ChatParseReq chatParseReq, ChatParseResp chatParseResp);
|
List<ChatParseDO> batchAddParse(ChatParseReq chatParseReq, ChatParseResp chatParseResp);
|
||||||
|
|
||||||
SemanticParseInfo getParseInfo(Long questionId, int parseId);
|
SemanticParseInfo getParseInfo(Long questionId, int parseId);
|
||||||
|
|
||||||
|
List<SemanticParseInfo> getParseInfos(Long questionId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,4 +244,13 @@ public class ChatManageServiceImpl implements ChatManageService {
|
|||||||
return JSONObject.parseObject(chatParseDO.getParseInfo(), SemanticParseInfo.class);
|
return JSONObject.parseObject(chatParseDO.getParseInfo(), SemanticParseInfo.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SemanticParseInfo> getParseInfos(Long questionId) {
|
||||||
|
List<ChatParseDO> chatParseDOs =
|
||||||
|
chatQueryRepository.getParseInfoList(Collections.singletonList(questionId));
|
||||||
|
return chatParseDOs.stream().map(chatParseDO -> JSONObject
|
||||||
|
.parseObject(chatParseDO.getParseInfo(), SemanticParseInfo.class))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.tencent.supersonic.chat.server.service.impl;
|
package com.tencent.supersonic.chat.server.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatExecuteReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatExecuteReq;
|
||||||
@@ -22,7 +21,11 @@ import com.tencent.supersonic.chat.server.service.ChatManageService;
|
|||||||
import com.tencent.supersonic.chat.server.service.ChatQueryService;
|
import com.tencent.supersonic.chat.server.service.ChatQueryService;
|
||||||
import com.tencent.supersonic.chat.server.util.ComponentFactory;
|
import com.tencent.supersonic.chat.server.util.ComponentFactory;
|
||||||
import com.tencent.supersonic.chat.server.util.QueryReqConverter;
|
import com.tencent.supersonic.chat.server.util.QueryReqConverter;
|
||||||
import com.tencent.supersonic.common.jsqlparser.*;
|
import com.tencent.supersonic.common.jsqlparser.FieldExpression;
|
||||||
|
import com.tencent.supersonic.common.jsqlparser.SqlAddHelper;
|
||||||
|
import com.tencent.supersonic.common.jsqlparser.SqlRemoveHelper;
|
||||||
|
import com.tencent.supersonic.common.jsqlparser.SqlReplaceHelper;
|
||||||
|
import com.tencent.supersonic.common.jsqlparser.SqlSelectHelper;
|
||||||
import com.tencent.supersonic.common.pojo.User;
|
import com.tencent.supersonic.common.pojo.User;
|
||||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||||
import com.tencent.supersonic.common.util.DateUtils;
|
import com.tencent.supersonic.common.util.DateUtils;
|
||||||
@@ -48,7 +51,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.sf.jsqlparser.expression.Expression;
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
import net.sf.jsqlparser.expression.LongValue;
|
import net.sf.jsqlparser.expression.LongValue;
|
||||||
import net.sf.jsqlparser.expression.StringValue;
|
import net.sf.jsqlparser.expression.StringValue;
|
||||||
import net.sf.jsqlparser.expression.operators.relational.*;
|
import net.sf.jsqlparser.expression.operators.relational.ComparisonOperator;
|
||||||
|
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
|
||||||
|
import net.sf.jsqlparser.expression.operators.relational.InExpression;
|
||||||
|
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
|
||||||
|
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
|
||||||
import net.sf.jsqlparser.schema.Column;
|
import net.sf.jsqlparser.schema.Column;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
@@ -57,7 +64,14 @@ import org.springframework.context.annotation.Lazy;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -114,6 +128,8 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!parseContext.needFeedback()) {
|
if (!parseContext.needFeedback()) {
|
||||||
|
parseContext.getResponse().getParseTimeCost().setParseTime(System.currentTimeMillis()
|
||||||
|
- parseContext.getResponse().getParseTimeCost().getParseStartTime());
|
||||||
chatManageService.batchAddParse(chatParseReq, parseContext.getResponse());
|
chatManageService.batchAddParse(chatParseReq, parseContext.getResponse());
|
||||||
chatManageService.updateParseCostTime(parseContext.getResponse());
|
chatManageService.updateParseCostTime(parseContext.getResponse());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,4 +52,9 @@
|
|||||||
where chat_id = #{chatId} order by question_id desc limit 10
|
where chat_id = #{chatId} order by question_id desc limit 10
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<delete id="deleteByQuestionId">
|
||||||
|
delete from s2_chat_parse
|
||||||
|
where question_id = #{questionId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -118,22 +118,26 @@ public class SqlReplaceHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void getFromSelect(FromItem fromItem, List<PlainSelect> plainSelectList) {
|
public static void getFromSelect(FromItem fromItem, List<PlainSelect> plainSelectList) {
|
||||||
if (!(fromItem instanceof ParenthesedSelect)) {
|
if (!(fromItem instanceof ParenthesedSelect parenthesedSelect)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ParenthesedSelect parenthesedSelect = (ParenthesedSelect) fromItem;
|
|
||||||
Select select = parenthesedSelect.getSelect();
|
Select select = parenthesedSelect.getSelect();
|
||||||
if (select instanceof PlainSelect) {
|
if (select instanceof PlainSelect plainSelect) {
|
||||||
PlainSelect plainSelect = (PlainSelect) select;
|
|
||||||
plainSelectList.add(plainSelect);
|
plainSelectList.add(plainSelect);
|
||||||
getFromSelect(plainSelect.getFromItem(), plainSelectList);
|
getFromSelect(plainSelect.getFromItem(), plainSelectList);
|
||||||
} else if (select instanceof SetOperationList) {
|
} else if (select instanceof SetOperationList setOperationList) {
|
||||||
SetOperationList setOperationList = (SetOperationList) select;
|
|
||||||
if (!CollectionUtils.isEmpty(setOperationList.getSelects())) {
|
if (!CollectionUtils.isEmpty(setOperationList.getSelects())) {
|
||||||
setOperationList.getSelects().forEach(subSelectBody -> {
|
setOperationList.getSelects().forEach(subSelectBody -> {
|
||||||
PlainSelect subPlainSelect = (PlainSelect) subSelectBody;
|
if (subSelectBody instanceof PlainSelect subPlainSelect) {
|
||||||
plainSelectList.add(subPlainSelect);
|
plainSelectList.add(subPlainSelect);
|
||||||
getFromSelect(subPlainSelect.getFromItem(), plainSelectList);
|
getFromSelect(subPlainSelect.getFromItem(), plainSelectList);
|
||||||
|
} else if (subSelectBody instanceof ParenthesedSelect subParenthesedSelect) {
|
||||||
|
Select innerSelect = subParenthesedSelect.getSelect();
|
||||||
|
if (innerSelect instanceof PlainSelect innerPlainSelect) {
|
||||||
|
plainSelectList.add(innerPlainSelect);
|
||||||
|
getFromSelect(innerPlainSelect.getFromItem(), plainSelectList);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,8 +192,14 @@ public class SqlReplaceHelper {
|
|||||||
SetOperationList setOperationList = (SetOperationList) select;
|
SetOperationList setOperationList = (SetOperationList) select;
|
||||||
if (!CollectionUtils.isEmpty(setOperationList.getSelects())) {
|
if (!CollectionUtils.isEmpty(setOperationList.getSelects())) {
|
||||||
setOperationList.getSelects().forEach(subSelectBody -> {
|
setOperationList.getSelects().forEach(subSelectBody -> {
|
||||||
PlainSelect subPlainSelect = (PlainSelect) subSelectBody;
|
if (subSelectBody instanceof PlainSelect) {
|
||||||
replaceFieldsInPlainOneSelect(fieldNameMap, exactReplace, subPlainSelect);
|
PlainSelect subPlainSelect = (PlainSelect) subSelectBody;
|
||||||
|
replaceFieldsInPlainOneSelect(fieldNameMap, exactReplace,
|
||||||
|
subPlainSelect);
|
||||||
|
} else if (subSelectBody instanceof ParenthesedSelect) {
|
||||||
|
replaceFieldsInPlainOneSelect(fieldNameMap, exactReplace,
|
||||||
|
((ParenthesedSelect) subSelectBody).getPlainSelect());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,6 @@ public class TextSegmentConvert {
|
|||||||
if (Objects.isNull(textSegment) || Objects.isNull(textSegment.metadata())) {
|
if (Objects.isNull(textSegment) || Objects.isNull(textSegment.metadata())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return textSegment.metadata().get(QUERY_ID);
|
return textSegment.metadata().getString(QUERY_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ public class DictSingleTaskReq {
|
|||||||
private TypeEnums type;
|
private TypeEnums type;
|
||||||
@NotNull
|
@NotNull
|
||||||
private Long itemId;
|
private Long itemId;
|
||||||
|
private String startDate;
|
||||||
|
private String endDate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.tencent.supersonic.headless.api.pojo.DimValueMap;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: kanedai
|
* @author: kanedai
|
||||||
* @date: 2024/10/31
|
* @date: 2024/10/31
|
||||||
@@ -15,7 +17,7 @@ public class DimValueAliasReq {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alias为空代表删除 否则更新
|
* alias 为空代表删除 否则更新
|
||||||
*/
|
*/
|
||||||
DimValueMap dimValueMaps;
|
private List<DimValueMap> dimValueMaps;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class PageSchemaItemReq extends PageBaseReq {
|
|||||||
private String createdBy;
|
private String createdBy;
|
||||||
private List<Long> domainIds = Lists.newArrayList();
|
private List<Long> domainIds = Lists.newArrayList();
|
||||||
private List<Long> modelIds = Lists.newArrayList();
|
private List<Long> modelIds = Lists.newArrayList();
|
||||||
|
private Long dataSetId;
|
||||||
private Integer sensitiveLevel;
|
private Integer sensitiveLevel;
|
||||||
private Integer status;
|
private Integer status;
|
||||||
private String key;
|
private String key;
|
||||||
|
|||||||
@@ -8,43 +8,107 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class KnowledgeBaseService {
|
public class KnowledgeBaseService {
|
||||||
private static volatile Map<Long, List<DictWord>> dimValueAliasMap = new HashMap<>();
|
private static final Map<Long, List<DictWord>> dimValueAliasMap = new ConcurrentHashMap<>();
|
||||||
|
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get dimension value alias map (read-only).
|
||||||
|
*
|
||||||
|
* @return unmodifiable view of the map
|
||||||
|
*/
|
||||||
public static Map<Long, List<DictWord>> getDimValueAlias() {
|
public static Map<Long, List<DictWord>> getDimValueAlias() {
|
||||||
return dimValueAliasMap;
|
return Collections.unmodifiableMap(dimValueAliasMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add dimension value aliases with deduplication. Thread-safe implementation using
|
||||||
|
* ConcurrentHashMap.
|
||||||
|
*
|
||||||
|
* @param dimId dimension ID
|
||||||
|
* @param newWords new words to add
|
||||||
|
* @return updated list of aliases for the dimension
|
||||||
|
*/
|
||||||
public static List<DictWord> addDimValueAlias(Long dimId, List<DictWord> newWords) {
|
public static List<DictWord> addDimValueAlias(Long dimId, List<DictWord> newWords) {
|
||||||
List<DictWord> dimValueAlias =
|
if (dimId == null || CollectionUtils.isEmpty(newWords)) {
|
||||||
dimValueAliasMap.containsKey(dimId) ? dimValueAliasMap.get(dimId)
|
return dimValueAliasMap.get(dimId);
|
||||||
: new ArrayList<>();
|
}
|
||||||
Set<String> wordSet =
|
|
||||||
dimValueAlias
|
// Use computeIfAbsent and synchronized block for thread safety
|
||||||
.stream().map(word -> String.format("%s_%s_%s",
|
synchronized (dimValueAliasMap) {
|
||||||
word.getNatureWithFrequency(), word.getWord(), word.getAlias()))
|
List<DictWord> dimValueAlias =
|
||||||
.collect(Collectors.toSet());
|
dimValueAliasMap.computeIfAbsent(dimId, k -> new ArrayList<>());
|
||||||
for (DictWord dictWord : newWords) {
|
|
||||||
String key = String.format("%s_%s_%s", dictWord.getNatureWithFrequency(),
|
// Build deduplication key set
|
||||||
dictWord.getWord(), dictWord.getAlias());
|
Set<String> existingKeys = dimValueAlias.stream().map(word -> buildDedupKey(word))
|
||||||
if (!wordSet.contains(key)) {
|
.collect(Collectors.toSet());
|
||||||
dimValueAlias.add(dictWord);
|
|
||||||
}
|
// Add new words with deduplication
|
||||||
|
for (DictWord dictWord : newWords) {
|
||||||
|
String key = buildDedupKey(dictWord);
|
||||||
|
if (!existingKeys.contains(key)) {
|
||||||
|
dimValueAlias.add(dictWord);
|
||||||
|
existingKeys.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dimValueAlias;
|
||||||
}
|
}
|
||||||
dimValueAliasMap.put(dimId, dimValueAlias);
|
|
||||||
return dimValueAlias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateSemanticKnowledge(List<DictWord> natures) {
|
/**
|
||||||
|
* Remove dimension value aliases by dimension ID.
|
||||||
|
*
|
||||||
|
* @param dimId dimension ID to remove, or null to clear all
|
||||||
|
*/
|
||||||
|
public static void removeDimValueAlias(Long dimId) {
|
||||||
|
if (dimId == null) {
|
||||||
|
dimValueAliasMap.clear();
|
||||||
|
log.info("Cleared all dimension value aliases");
|
||||||
|
} else {
|
||||||
|
dimValueAliasMap.remove(dimId);
|
||||||
|
log.info("Removed dimension value alias for dimId: {}", dimId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build deduplication key for DictWord.
|
||||||
|
*
|
||||||
|
* @param word the DictWord object
|
||||||
|
* @return deduplication key string
|
||||||
|
*/
|
||||||
|
private static String buildDedupKey(DictWord word) {
|
||||||
|
return String.format("%s_%s_%s", word.getNatureWithFrequency(), word.getWord(),
|
||||||
|
word.getAlias());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update semantic knowledge (incremental add, no clearing). Use this method to add new words
|
||||||
|
* without removing existing data.
|
||||||
|
*
|
||||||
|
* @param natures the words to add
|
||||||
|
*/
|
||||||
|
public void updateSemanticKnowledge(List<DictWord> natures) {
|
||||||
|
lock.writeLock().lock();
|
||||||
|
try {
|
||||||
|
updateSemanticKnowledgeInternal(natures);
|
||||||
|
} finally {
|
||||||
|
lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSemanticKnowledgeInternal(List<DictWord> natures) {
|
||||||
List<DictWord> prefixes = natures.stream().filter(
|
List<DictWord> prefixes = natures.stream().filter(
|
||||||
entry -> !entry.getNatureWithFrequency().contains(DictWordType.SUFFIX.getType()))
|
entry -> !entry.getNatureWithFrequency().contains(DictWordType.SUFFIX.getType()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -60,52 +124,82 @@ public class KnowledgeBaseService {
|
|||||||
SearchService.loadSuffix(suffixes);
|
SearchService.loadSuffix(suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload all knowledge (full replacement with clearing). Use this method to rebuild the entire
|
||||||
|
* knowledge base.
|
||||||
|
*
|
||||||
|
* @param natures all words to load
|
||||||
|
*/
|
||||||
public void reloadAllData(List<DictWord> natures) {
|
public void reloadAllData(List<DictWord> natures) {
|
||||||
// 1. reload custom knowledge
|
// 1. reload custom knowledge (executed outside lock to avoid long blocking)
|
||||||
try {
|
try {
|
||||||
HanlpHelper.reloadCustomDictionary();
|
HanlpHelper.reloadCustomDictionary();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("reloadCustomDictionary error", e);
|
log.error("reloadCustomDictionary error", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. update online knowledge
|
// 2. acquire write lock, clear trie and rebuild (short operation)
|
||||||
if (CollectionUtils.isNotEmpty(dimValueAliasMap)) {
|
lock.writeLock().lock();
|
||||||
for (Long dimId : dimValueAliasMap.keySet()) {
|
|
||||||
natures.addAll(dimValueAliasMap.get(dimId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateOnlineKnowledge(natures);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateOnlineKnowledge(List<DictWord> natures) {
|
|
||||||
try {
|
try {
|
||||||
updateSemanticKnowledge(natures);
|
SearchService.clear();
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("updateSemanticKnowledge error", e);
|
if (CollectionUtils.isNotEmpty(dimValueAliasMap)) {
|
||||||
|
for (Long dimId : dimValueAliasMap.keySet()) {
|
||||||
|
natures.addAll(dimValueAliasMap.get(dimId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateSemanticKnowledgeInternal(natures);
|
||||||
|
} finally {
|
||||||
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<S2Term> getTerms(String text, Map<Long, List<Long>> modelIdToDataSetIds) {
|
public List<S2Term> getTerms(String text, Map<Long, List<Long>> modelIdToDataSetIds) {
|
||||||
return HanlpHelper.getTerms(text, modelIdToDataSetIds);
|
lock.readLock().lock();
|
||||||
|
try {
|
||||||
|
return HanlpHelper.getTerms(text, modelIdToDataSetIds);
|
||||||
|
} finally {
|
||||||
|
lock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HanlpMapResult> prefixSearch(String key, int limit,
|
public List<HanlpMapResult> prefixSearch(String key, int limit,
|
||||||
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
||||||
return prefixSearchByModel(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
lock.readLock().lock();
|
||||||
|
try {
|
||||||
|
return prefixSearchByModel(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
||||||
|
} finally {
|
||||||
|
lock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HanlpMapResult> prefixSearchByModel(String key, int limit,
|
public List<HanlpMapResult> prefixSearchByModel(String key, int limit,
|
||||||
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
||||||
return SearchService.prefixSearch(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
lock.readLock().lock();
|
||||||
|
try {
|
||||||
|
return SearchService.prefixSearch(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
||||||
|
} finally {
|
||||||
|
lock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HanlpMapResult> suffixSearch(String key, int limit,
|
public List<HanlpMapResult> suffixSearch(String key, int limit,
|
||||||
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
||||||
return suffixSearchByModel(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
lock.readLock().lock();
|
||||||
|
try {
|
||||||
|
return suffixSearchByModel(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
||||||
|
} finally {
|
||||||
|
lock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HanlpMapResult> suffixSearchByModel(String key, int limit,
|
public List<HanlpMapResult> suffixSearchByModel(String key, int limit,
|
||||||
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
Map<Long, List<Long>> modelIdToDataSetIds, Set<Long> detectDataSetIds) {
|
||||||
return SearchService.suffixSearch(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
lock.readLock().lock();
|
||||||
|
try {
|
||||||
|
return SearchService.suffixSearch(key, limit, modelIdToDataSetIds, detectDataSetIds);
|
||||||
|
} finally {
|
||||||
|
lock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import java.util.stream.Collectors;
|
|||||||
public class SearchService {
|
public class SearchService {
|
||||||
|
|
||||||
public static final int SEARCH_SIZE = 200;
|
public static final int SEARCH_SIZE = 200;
|
||||||
private static BinTrie<List<String>> trie;
|
private static volatile BinTrie<List<String>> trie;
|
||||||
private static BinTrie<List<String>> suffixTrie;
|
private static volatile BinTrie<List<String>> suffixTrie;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
trie = new BinTrie<>();
|
trie = new BinTrie<>();
|
||||||
|
|||||||
@@ -100,8 +100,6 @@ public class HanlpHelper {
|
|||||||
FileHelper.deleteCacheFile(HanLP.Config.CustomDictionaryPath);
|
FileHelper.deleteCacheFile(HanLP.Config.CustomDictionaryPath);
|
||||||
FileHelper.resetCustomPath(getDynamicCustomDictionary());
|
FileHelper.resetCustomPath(getDynamicCustomDictionary());
|
||||||
}
|
}
|
||||||
// 3.clear trie
|
|
||||||
SearchService.clear();
|
|
||||||
|
|
||||||
boolean reload = getDynamicCustomDictionary().reload();
|
boolean reload = getDynamicCustomDictionary().reload();
|
||||||
if (reload) {
|
if (reload) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class DbAdaptorFactory {
|
|||||||
dbAdaptorMap.put(EngineType.PRESTO.getName(), new PrestoAdaptor());
|
dbAdaptorMap.put(EngineType.PRESTO.getName(), new PrestoAdaptor());
|
||||||
dbAdaptorMap.put(EngineType.TRINO.getName(), new TrinoAdaptor());
|
dbAdaptorMap.put(EngineType.TRINO.getName(), new TrinoAdaptor());
|
||||||
dbAdaptorMap.put(EngineType.ORACLE.getName(), new OracleAdaptor());
|
dbAdaptorMap.put(EngineType.ORACLE.getName(), new OracleAdaptor());
|
||||||
|
dbAdaptorMap.put(EngineType.TDW.getName(), new DefaultDbAdaptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DbAdaptor getEngineAdaptor(String engineType) {
|
public static DbAdaptor getEngineAdaptor(String engineType) {
|
||||||
|
|||||||
@@ -43,14 +43,7 @@ public class DataModelNode extends SemanticNode {
|
|||||||
}
|
}
|
||||||
} else if (dataModel.getModelDetail().getTableQuery() != null
|
} else if (dataModel.getModelDetail().getTableQuery() != null
|
||||||
&& !dataModel.getModelDetail().getTableQuery().isEmpty()) {
|
&& !dataModel.getModelDetail().getTableQuery().isEmpty()) {
|
||||||
if (dataModel.getModelDetail().getDbType()
|
sqlTable = "SELECT * FROM " + dataModel.getModelDetail().getTableQuery();
|
||||||
.equalsIgnoreCase(EngineType.POSTGRESQL.getName())) {
|
|
||||||
String fullTableName = String.join(".public.",
|
|
||||||
dataModel.getModelDetail().getTableQuery().split("\\."));
|
|
||||||
sqlTable = "SELECT * FROM " + fullTableName;
|
|
||||||
} else {
|
|
||||||
sqlTable = "SELECT * FROM " + dataModel.getModelDetail().getTableQuery();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String filterSql = dataModel.getFilterSql();
|
// String filterSql = dataModel.getFilterSql();
|
||||||
|
|||||||
@@ -123,7 +123,9 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
|||||||
|
|
||||||
// 3 translate query
|
// 3 translate query
|
||||||
QueryStatement queryStatement = buildQueryStatement(queryReq, user);
|
QueryStatement queryStatement = buildQueryStatement(queryReq, user);
|
||||||
semanticTranslator.translate(queryStatement);
|
if (!queryStatement.isTranslated()) {
|
||||||
|
semanticTranslator.translate(queryStatement);
|
||||||
|
}
|
||||||
|
|
||||||
// Check whether the dimensions of the metric drill-down are correct temporarily,
|
// Check whether the dimensions of the metric drill-down are correct temporarily,
|
||||||
// add the abstraction of a validator later.
|
// add the abstraction of a validator later.
|
||||||
|
|||||||
@@ -17,12 +17,11 @@ import com.tencent.supersonic.headless.server.service.DimensionService;
|
|||||||
import com.tencent.supersonic.headless.server.utils.DictUtils;
|
import com.tencent.supersonic.headless.server.utils.DictUtils;
|
||||||
import com.xkzhangsan.time.utils.CollectionUtil;
|
import com.xkzhangsan.time.utils.CollectionUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class MetricRepositoryImpl implements MetricRepository {
|
|||||||
if (StringUtils.isNotBlank(metricFilter.getCreatedBy())) {
|
if (StringUtils.isNotBlank(metricFilter.getCreatedBy())) {
|
||||||
queryWrapper.lambda().eq(MetricDO::getCreatedBy, metricFilter.getCreatedBy());
|
queryWrapper.lambda().eq(MetricDO::getCreatedBy, metricFilter.getCreatedBy());
|
||||||
}
|
}
|
||||||
if (Objects.nonNull(metricFilter.getIsPublish()) && metricFilter.getIsPublish() == 1) {
|
if (Objects.nonNull(metricFilter.getIsPublish())) {
|
||||||
queryWrapper.lambda().eq(MetricDO::getIsPublish, metricFilter.getIsPublish());
|
queryWrapper.lambda().eq(MetricDO::getIsPublish, metricFilter.getIsPublish());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(metricFilter.getKey())) {
|
if (StringUtils.isNotBlank(metricFilter.getKey())) {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -474,31 +475,53 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
|
|||||||
if (StringUtils.isNotEmpty(dimensionDO.getDimValueMaps())) {
|
if (StringUtils.isNotEmpty(dimensionDO.getDimValueMaps())) {
|
||||||
dimValueMapList = JsonUtil.toList(dimensionDO.getDimValueMaps(), DimValueMap.class);
|
dimValueMapList = JsonUtil.toList(dimensionDO.getDimValueMaps(), DimValueMap.class);
|
||||||
}
|
}
|
||||||
DimValueMap dimValueMaps = req.getDimValueMaps();
|
|
||||||
if (StringUtils.isEmpty(dimValueMaps.getTechName())) {
|
// 预先处理请求列表,设置默认的 techName
|
||||||
dimValueMaps.setTechName(dimValueMaps.getValue());
|
for (DimValueMap dimValueMap : req.getDimValueMaps()) {
|
||||||
}
|
if (StringUtils.isEmpty(dimValueMap.getTechName())) {
|
||||||
Map<String, DimValueMap> valeAndMapInfo = dimValueMapList.stream()
|
dimValueMap.setTechName(dimValueMap.getValue());
|
||||||
.collect(Collectors.toMap(DimValueMap::getValue, v -> v, (v1, v2) -> v2));
|
|
||||||
String value = dimValueMaps.getValue();
|
|
||||||
if (CollectionUtils.isEmpty(dimValueMaps.getAlias())) {
|
|
||||||
// 删除
|
|
||||||
dimValueMapList =
|
|
||||||
dimValueMapList.stream().filter(map -> !map.getValue().equalsIgnoreCase(value))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
} else {
|
|
||||||
// 新增
|
|
||||||
if (!valeAndMapInfo.keySet().contains(value)) {
|
|
||||||
dimValueMapList.add(dimValueMaps);
|
|
||||||
} else {
|
|
||||||
// 更新
|
|
||||||
dimValueMapList.stream().forEach(map -> {
|
|
||||||
if (map.getValue().equalsIgnoreCase(value)) {
|
|
||||||
map.setAlias(dimValueMaps.getAlias());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建现有数据的 Map,用于快速查找 (value -> DimValueMap)
|
||||||
|
Map<String, DimValueMap> existingMap = dimValueMapList.stream()
|
||||||
|
.collect(Collectors.toMap(DimValueMap::getValue, v -> v, (v1, v2) -> v2));
|
||||||
|
|
||||||
|
// 收集需要删除的 values(alias 为空的)
|
||||||
|
Set<String> valuesToDelete = req.getDimValueMaps().stream()
|
||||||
|
.filter(dimValueMap -> CollectionUtils.isEmpty(dimValueMap.getAlias()))
|
||||||
|
.map(DimValueMap::getValue).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 一次性删除所有需要删除的数据
|
||||||
|
if (!valuesToDelete.isEmpty()) {
|
||||||
|
dimValueMapList =
|
||||||
|
dimValueMapList.stream().filter(map -> !valuesToDelete.contains(map.getValue()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
// 同时从 existingMap 中移除
|
||||||
|
existingMap.keySet().removeAll(valuesToDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理新增和更新
|
||||||
|
for (DimValueMap dimValueMap : req.getDimValueMaps()) {
|
||||||
|
// 跳过需要删除的
|
||||||
|
if (CollectionUtils.isEmpty(dimValueMap.getAlias())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = dimValueMap.getValue();
|
||||||
|
if (!existingMap.containsKey(value)) {
|
||||||
|
// 新增
|
||||||
|
dimValueMapList.add(dimValueMap);
|
||||||
|
existingMap.put(value, dimValueMap);
|
||||||
|
} else {
|
||||||
|
// 更新 - 直接更新已存在的对象
|
||||||
|
DimValueMap existing = existingMap.get(value);
|
||||||
|
existing.setAlias(dimValueMap.getAlias());
|
||||||
|
existing.setTechName(dimValueMap.getTechName());
|
||||||
|
existing.setBizName(dimValueMap.getBizName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dimensionDO.setDimValueMaps(JsonUtil.toString(dimValueMapList));
|
dimensionDO.setDimValueMaps(JsonUtil.toString(dimValueMapList));
|
||||||
updateById(dimensionDO);
|
updateById(dimensionDO);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -374,7 +374,15 @@ public class MetricServiceImpl extends ServiceImpl<MetricDOMapper, MetricDO>
|
|||||||
MetricFilter metricFilter = new MetricFilter();
|
MetricFilter metricFilter = new MetricFilter();
|
||||||
metricFilter.setUserName(user.getName());
|
metricFilter.setUserName(user.getName());
|
||||||
BeanUtils.copyProperties(pageMetricReq, metricFilter);
|
BeanUtils.copyProperties(pageMetricReq, metricFilter);
|
||||||
if (!CollectionUtils.isEmpty(pageMetricReq.getDomainIds())) {
|
|
||||||
|
// If dataSetId is provided, get models directly from the dataset
|
||||||
|
if (pageMetricReq.getDataSetId() != null) {
|
||||||
|
DataSetResp dataSetResp = dataSetService.getDataSet(pageMetricReq.getDataSetId());
|
||||||
|
if (dataSetResp != null) {
|
||||||
|
pageMetricReq.getModelIds().addAll(dataSetResp.getAllModels());
|
||||||
|
}
|
||||||
|
} else if (!CollectionUtils.isEmpty(pageMetricReq.getDomainIds())) {
|
||||||
|
// Only check domainIds when dataSetId is not provided
|
||||||
List<ModelResp> modelResps =
|
List<ModelResp> modelResps =
|
||||||
modelService.getAllModelByDomainIds(pageMetricReq.getDomainIds());
|
modelService.getAllModelByDomainIds(pageMetricReq.getDomainIds());
|
||||||
List<Long> modelIds =
|
List<Long> modelIds =
|
||||||
|
|||||||
@@ -47,22 +47,9 @@ public class ModelRelaServiceImpl extends ServiceImpl<ModelRelaDOMapper, ModelRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void check(ModelRela modelRela) {
|
private void check(ModelRela modelRela) {
|
||||||
ModelResp fromModel = modelService.getModel(modelRela.getFromModelId());
|
|
||||||
ModelResp toModel = modelService.getModel(modelRela.getToModelId());
|
|
||||||
if (CollectionUtils.isEmpty(modelRela.getJoinConditions())) {
|
if (CollectionUtils.isEmpty(modelRela.getJoinConditions())) {
|
||||||
throw new RuntimeException("关联关系不可为空");
|
throw new RuntimeException("关联关系不可为空");
|
||||||
}
|
}
|
||||||
for (JoinCondition joinCondition : modelRela.getJoinConditions()) {
|
|
||||||
IdentifyType identifyTypeLeft = fromModel.getIdentifyType(joinCondition.getLeftField());
|
|
||||||
IdentifyType identifyTypeRight = toModel.getIdentifyType(joinCondition.getRightField());
|
|
||||||
if (IdentifyType.foreign.equals(identifyTypeLeft)
|
|
||||||
|| IdentifyType.foreign.equals(identifyTypeRight)) {
|
|
||||||
if (!IdentifyType.primary.equals(identifyTypeLeft)
|
|
||||||
&& !IdentifyType.primary.equals(identifyTypeRight)) {
|
|
||||||
throw new RuntimeException("外键必须跟主键关联");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import java.util.*;
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.tencent.supersonic.common.pojo.DimensionConstants.DIMENSION_TIME_FORMAT;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ModelServiceImpl implements ModelService {
|
public class ModelServiceImpl implements ModelService {
|
||||||
@@ -530,17 +532,23 @@ public class ModelServiceImpl implements ModelService {
|
|||||||
Optional<Dimension> dimOptional = modelDetail.getDimensions().stream().filter(
|
Optional<Dimension> dimOptional = modelDetail.getDimensions().stream().filter(
|
||||||
dimension -> dimension.getBizName().equals(dimensionReq.getBizName()))
|
dimension -> dimension.getBizName().equals(dimensionReq.getBizName()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
String dateFormat = null;
|
||||||
|
if (dimensionReq.getExt().containsKey(DIMENSION_TIME_FORMAT)) {
|
||||||
|
dateFormat = (String) dimensionReq.getExt().get(DIMENSION_TIME_FORMAT);
|
||||||
|
}
|
||||||
if (dimOptional.isPresent()) {
|
if (dimOptional.isPresent()) {
|
||||||
Dimension dimension = dimOptional.get();
|
Dimension dimension = dimOptional.get();
|
||||||
dimension.setExpr(dimensionReq.getExpr());
|
dimension.setExpr(dimensionReq.getExpr());
|
||||||
dimension.setName(dimensionReq.getName());
|
dimension.setName(dimensionReq.getName());
|
||||||
dimension.setType(DimensionType.valueOf(dimensionReq.getType()));
|
dimension.setType(DimensionType.valueOf(dimensionReq.getType()));
|
||||||
dimension.setDescription(dimensionReq.getDescription());
|
dimension.setDescription(dimensionReq.getDescription());
|
||||||
|
dimension.setDateFormat(dateFormat);
|
||||||
} else {
|
} else {
|
||||||
Dimension dimension = Dimension.builder().name(dimensionReq.getName())
|
Dimension dimension = Dimension.builder().name(dimensionReq.getName())
|
||||||
.bizName(dimensionReq.getBizName()).expr(dimensionReq.getExpr())
|
.bizName(dimensionReq.getBizName()).expr(dimensionReq.getExpr())
|
||||||
.type(DimensionType.valueOf(dimensionReq.getType()))
|
.type(DimensionType.valueOf(dimensionReq.getType()))
|
||||||
.description(dimensionReq.getDescription()).build();
|
.dateFormat(dateFormat).description(dimensionReq.getDescription())
|
||||||
|
.build();
|
||||||
modelDetail.getDimensions().add(dimension);
|
modelDetail.getDimensions().add(dimension);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -413,11 +413,11 @@ public class SchemaServiceImpl implements SchemaService {
|
|||||||
public List<ItemResp> getDomainDataSetTree() {
|
public List<ItemResp> getDomainDataSetTree() {
|
||||||
List<DomainResp> domainResps = domainService.getDomainList();
|
List<DomainResp> domainResps = domainService.getDomainList();
|
||||||
List<ItemResp> itemResps = domainResps.stream().map(domain -> new ItemResp(domain.getId(),
|
List<ItemResp> itemResps = domainResps.stream().map(domain -> new ItemResp(domain.getId(),
|
||||||
domain.getParentId(), domain.getName(), TypeEnums.DOMAIN))
|
domain.getParentId(), domain.getName(), TypeEnums.DOMAIN)).toList();
|
||||||
.collect(Collectors.toList());
|
|
||||||
Map<Long, ItemResp> itemRespMap =
|
Map<Long, ItemResp> itemRespMap =
|
||||||
itemResps.stream().collect(Collectors.toMap(ItemResp::getId, item -> item));
|
itemResps.stream().collect(Collectors.toMap(ItemResp::getId, item -> item));
|
||||||
List<DataSetResp> dataSetResps = dataSetService.getDataSetList(new MetaFilter());
|
List<DataSetResp> dataSetResps = dataSetService
|
||||||
|
.getDataSetList(MetaFilter.builder().status(StatusEnum.ONLINE.getCode()).build());
|
||||||
for (DataSetResp dataSetResp : dataSetResps) {
|
for (DataSetResp dataSetResp : dataSetResps) {
|
||||||
ItemResp itemResp = itemRespMap.get(dataSetResp.getDomainId());
|
ItemResp itemResp = itemRespMap.get(dataSetResp.getDomainId());
|
||||||
if (itemResp != null) {
|
if (itemResp != null) {
|
||||||
|
|||||||
@@ -296,6 +296,8 @@ public class DictUtils {
|
|||||||
modelIds.add(dictItemResp.getModelId());
|
modelIds.add(dictItemResp.getModelId());
|
||||||
QuerySqlReq querySqlReq = new QuerySqlReq();
|
QuerySqlReq querySqlReq = new QuerySqlReq();
|
||||||
querySqlReq.setSql(sql);
|
querySqlReq.setSql(sql);
|
||||||
|
// bypass semantic translation
|
||||||
|
querySqlReq.getSqlInfo().setQuerySQL(sql);
|
||||||
querySqlReq.setNeedAuth(false);
|
querySqlReq.setNeedAuth(false);
|
||||||
querySqlReq.setModelIds(modelIds);
|
querySqlReq.setModelIds(modelIds);
|
||||||
|
|
||||||
@@ -445,14 +447,29 @@ public class DictUtils {
|
|||||||
if (DateConf.DateMode.ALL.equals(config.getDateConf().getDateMode())) {
|
if (DateConf.DateMode.ALL.equals(config.getDateConf().getDateMode())) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 静态日期
|
// 静态日期
|
||||||
if (DateConf.DateMode.BETWEEN.equals(config.getDateConf().getDateMode())) {
|
if (DateConf.DateMode.BETWEEN.equals(config.getDateConf().getDateMode())) {
|
||||||
|
String dateFormat = partitionTimeDimension.getDateFormat();
|
||||||
|
if (StringUtils.isEmpty(dateFormat)) {
|
||||||
|
dateFormat = "yyyy-MM-dd"; // 默认格式
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化起止日期
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
|
||||||
|
String startDate =
|
||||||
|
LocalDate.parse(config.getDateConf().getStartDate()).format(formatter);
|
||||||
|
String endDate = LocalDate.parse(config.getDateConf().getEndDate()).format(formatter);
|
||||||
|
|
||||||
return String.format("( %s >= '%s' and %s <= '%s' )",
|
return String.format("( %s >= '%s' and %s <= '%s' )",
|
||||||
config.getDateConf().getDateField(), config.getDateConf().getStartDate(),
|
partitionTimeDimension.getBizName(), startDate,
|
||||||
config.getDateConf().getDateField(), config.getDateConf().getEndDate());
|
partitionTimeDimension.getBizName(), endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动态日期
|
// 动态日期
|
||||||
if (DateConf.DateMode.RECENT.equals(config.getDateConf().getDateMode())) {
|
if (DateConf.DateMode.RECENT.equals(config.getDateConf().getDateMode())) {
|
||||||
|
dictItemResp.getConfig().getDateConf()
|
||||||
|
.setDateField(partitionTimeDimension.getBizName());
|
||||||
return generateDictDateFilterRecent(dictItemResp);
|
return generateDictDateFilterRecent(dictItemResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -355,9 +355,11 @@ const DimensionValueSettingModal: React.FC<CreateFormProps> = ({
|
|||||||
onRecordSave={(record) => {
|
onRecordSave={(record) => {
|
||||||
modifyDimensionValue({
|
modifyDimensionValue({
|
||||||
id: dimensionItem.id,
|
id: dimensionItem.id,
|
||||||
dimValueMaps: {
|
dimValueMaps: [
|
||||||
...record,
|
{
|
||||||
},
|
...record,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
hideCtrlBtn={['deleteBtn']}
|
hideCtrlBtn={['deleteBtn']}
|
||||||
|
|||||||
Reference in New Issue
Block a user