mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-04-19 21:14:25 +08:00
Compare commits
38 Commits
v0.9.10
...
202957a4c0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
202957a4c0 | ||
|
|
313718fa6a | ||
|
|
35b835172b | ||
|
|
1c85bcecc5 | ||
|
|
c3483ae340 | ||
|
|
a5051c7225 | ||
|
|
12f6cfa42d | ||
|
|
4c94f2b816 | ||
|
|
c81aa5859d | ||
|
|
21e213fb19 | ||
|
|
f67bf3eeac | ||
|
|
9d13038599 | ||
|
|
0c8c2d4804 | ||
|
|
f05a4b523c | ||
|
|
b7369abcca | ||
|
|
b40cb13740 | ||
|
|
6f8cf9853b | ||
|
|
75906037ac | ||
|
|
b58e041e8d | ||
|
|
93d585c0d5 | ||
|
|
0dbf56d357 | ||
|
|
a3293e6788 | ||
|
|
a99f5985f5 | ||
|
|
91243005bc | ||
|
|
a76b5a4300 | ||
|
|
c1f9df963c | ||
|
|
954aa4eea5 | ||
|
|
33bd0de604 | ||
|
|
881d891d70 | ||
|
|
d9db455dab | ||
|
|
e0dc3fbf1a | ||
|
|
efddf4cacf | ||
|
|
732222ab98 | ||
|
|
5b994c4f8f | ||
|
|
5d2ebdf680 | ||
|
|
f1bc18ef65 | ||
|
|
8f361f9932 | ||
|
|
f532088e38 |
2
.github/workflows/centos-ci.yml
vendored
2
.github/workflows/centos-ci.yml
vendored
@@ -47,7 +47,7 @@ jobs:
|
||||
mvn -version
|
||||
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
|
||||
2
.github/workflows/mac-ci.yml
vendored
2
.github/workflows/mac-ci.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
distribution: 'adopt'
|
||||
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/Library/Caches/Maven # macOS Maven cache path
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
|
||||
2
.github/workflows/ubuntu-ci.yml
vendored
2
.github/workflows/ubuntu-ci.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
distribution: 'adopt'
|
||||
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
|
||||
2
.github/workflows/windows-ci.yml
vendored
2
.github/workflows/windows-ci.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
distribution: 'adopt' # You might need to change this if 'adopt' doesn't support JDK 21
|
||||
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~\.m2 # Windows uses a backslash for paths
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -14,7 +14,7 @@ code and logo.
|
||||
b. a commercial license must be obtained from the author if you want to develop and distribute a derivative work based
|
||||
on SuperSonic.
|
||||
|
||||
Please contact zhangjun2915@163.com by email to inquire about licensing matters.
|
||||
Please contact supersonicbi@qq.com by email to inquire about licensing matters.
|
||||
|
||||
|
||||
2. As a contributor, you should agree that:
|
||||
|
||||
@@ -75,7 +75,7 @@ SuperSonic comes with sample semantic models as well as chat conversations that
|
||||
|
||||
## Build and Development
|
||||
|
||||
Please refer to project [Docs](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA/).
|
||||
Please refer to project [Docs](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E9%83%A8%E7%BD%B2/).
|
||||
|
||||
## WeChat Contact
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ SuperSonic自带样例的语义模型和问答对话,只需以下三步即可
|
||||
|
||||
## 如何构建和部署
|
||||
|
||||
请参考项目[文档](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA/)。
|
||||
请参考项目[文档](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E9%83%A8%E7%BD%B2/)。
|
||||
|
||||
## 微信联系方式
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ SuperSonicには、サンプルのセマンティックモデルとチャット
|
||||
|
||||
## ビルドと開発
|
||||
|
||||
プロジェクト[ドキュメント](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA/)を参照してください。
|
||||
プロジェクト[ドキュメント](https://supersonicbi.github.io/docs/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2/%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E9%83%A8%E7%BD%B2/)を参照してください。
|
||||
|
||||
## WeChat連絡先
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ if "%command%"=="restart" (
|
||||
set "logDir=%baseDir%\logs"
|
||||
set "classpath=%baseDir%;%webDir%;%libDir%\*;%confDir%"
|
||||
set "property=-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Dspring.profiles.active=%profile%"
|
||||
set "java-command=%property% -Xms1024m -Xmx1024m -cp %CLASSPATH% %MAIN_CLASS%"
|
||||
set "java-command=%property% -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%"
|
||||
if not exist %logDir% mkdir %logDir%
|
||||
start /B java %java-command% >nul 2>&1
|
||||
timeout /t 10 >nul
|
||||
|
||||
@@ -60,7 +60,8 @@ function runJavaService {
|
||||
JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}')
|
||||
fi
|
||||
export PATH=$JAVA_HOME/bin:$PATH
|
||||
command="-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Dapp_name=${local_app_name} -Xms1024m -Xmx1024m $main_class"
|
||||
command="-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08
|
||||
-Dapp_name=${local_app_name} -Xms1024m -Xmx2048m $main_class"
|
||||
|
||||
mkdir -p $javaRunDir/logs
|
||||
java -Dspring.profiles.active="$profile" $command >/dev/null 2>$javaRunDir/logs/error.log &
|
||||
|
||||
5
assembly/bin/supersonic-docker-compose.sh
Normal file
5
assembly/bin/supersonic-docker-compose.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
export SUPERSONIC_VERSION=latest
|
||||
|
||||
docker-compose -f docker-compose.yml -p supersonic up
|
||||
23
assembly/bin/supersonic-docker-run.sh
Normal file
23
assembly/bin/supersonic-docker-run.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
export SUPERSONIC_VERSION=latest
|
||||
|
||||
#### Set below DB configs to connect to your own database
|
||||
# Supported DB_TYPE: h2, mysql, postgres
|
||||
export S2_DB_TYPE=h2
|
||||
export S2_DB_HOST=
|
||||
export S2_DB_PORT=
|
||||
export S2_DB_USER=
|
||||
export S2_DB_PASSWORD=
|
||||
export S2_DB_DATABASE=
|
||||
|
||||
docker run --rm -it -d \
|
||||
--name supersonic_standalone \
|
||||
-p 9080:9080 \
|
||||
-e S2_DB_TYPE=${S2_DB_TYPE} \
|
||||
-e S2_DB_HOST=${S2_DB_HOST} \
|
||||
-e S2_DB_PORT=${S2_DB_PORT} \
|
||||
-e S2_DB_USER=${S2_DB_USER} \
|
||||
-e S2_DB_PASSWORD=${S2_DB_PASSWORD} \
|
||||
-e S2_DB_DATABASE=${S2_DB_DATABASE} \
|
||||
supersonicbi/supersonic:${SUPERSONIC_VERSION}
|
||||
@@ -1,10 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#### Set below DB configs to connect to your own database
|
||||
# Comment out below exports to config your DB connection
|
||||
# Supported DB_TYPE: h2, mysql, postgres
|
||||
export S2_DB_TYPE=h2
|
||||
export S2_DB_HOST=
|
||||
export S2_DB_PORT=
|
||||
export S2_DB_USER=
|
||||
export S2_DB_PASSWORD=
|
||||
export S2_DB_DATABASE=
|
||||
#export S2_DB_TYPE=h2
|
||||
#export S2_DB_HOST=
|
||||
#export S2_DB_PORT=
|
||||
#export S2_DB_USER=
|
||||
#export S2_DB_PASSWORD=
|
||||
#export S2_DB_DATABASE=
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.tencent.supersonic.auth.authentication.interceptor;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
|
||||
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
|
||||
import com.tencent.supersonic.auth.api.authentication.service.UserService;
|
||||
import com.tencent.supersonic.auth.authentication.utils.TokenService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -16,7 +16,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
|
||||
|
||||
protected AuthenticationConfig authenticationConfig;
|
||||
|
||||
protected UserServiceImpl userServiceImpl;
|
||||
protected UserService userService;
|
||||
|
||||
protected TokenService tokenService;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.tencent.supersonic.auth.authentication.interceptor;
|
||||
import com.tencent.supersonic.auth.api.authentication.annotation.AuthenticationIgnore;
|
||||
import com.tencent.supersonic.auth.api.authentication.config.AuthenticationConfig;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.UserWithPassword;
|
||||
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
|
||||
import com.tencent.supersonic.auth.api.authentication.service.UserService;
|
||||
import com.tencent.supersonic.auth.authentication.utils.TokenService;
|
||||
import com.tencent.supersonic.common.pojo.exception.AccessException;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
@@ -16,12 +16,7 @@ import org.springframework.web.method.HandlerMethod;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_IS_ADMIN;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_DISPLAY_NAME;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_EMAIL;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_ID;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_NAME;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.TOKEN_USER_PASSWORD;
|
||||
import static com.tencent.supersonic.auth.api.authentication.constant.UserConstants.*;
|
||||
|
||||
@Slf4j
|
||||
public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor {
|
||||
@@ -30,7 +25,7 @@ public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler) throws AccessException {
|
||||
authenticationConfig = ContextUtils.getBean(AuthenticationConfig.class);
|
||||
userServiceImpl = ContextUtils.getBean(UserServiceImpl.class);
|
||||
userService = ContextUtils.getBean(UserService.class);
|
||||
tokenService = ContextUtils.getBean(TokenService.class);
|
||||
if (!authenticationConfig.isEnabled()) {
|
||||
return true;
|
||||
|
||||
@@ -5,5 +5,7 @@ import com.tencent.supersonic.chat.server.pojo.ExecuteContext;
|
||||
|
||||
public interface ChatQueryExecutor {
|
||||
|
||||
boolean accept(ExecuteContext executeContext);
|
||||
|
||||
QueryResult execute(ExecuteContext executeContext);
|
||||
}
|
||||
|
||||
@@ -37,11 +37,12 @@ public class PlainTextExecutor implements ChatQueryExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryResult execute(ExecuteContext executeContext) {
|
||||
if (!"PLAIN_TEXT".equals(executeContext.getParseInfo().getQueryMode())) {
|
||||
return null;
|
||||
}
|
||||
public boolean accept(ExecuteContext executeContext) {
|
||||
return "PLAIN_TEXT".equals(executeContext.getParseInfo().getQueryMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryResult execute(ExecuteContext executeContext) {
|
||||
AgentService agentService = ContextUtils.getBean(AgentService.class);
|
||||
Agent chatAgent = agentService.getAgent(executeContext.getAgent().getId());
|
||||
ChatApp chatApp = chatAgent.getChatAppConfig().get(APP_KEY);
|
||||
|
||||
@@ -8,6 +8,11 @@ import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
|
||||
public class PluginExecutor implements ChatQueryExecutor {
|
||||
|
||||
@Override
|
||||
public boolean accept(ExecuteContext executeContext) {
|
||||
return PluginQueryManager.isPluginQuery(executeContext.getParseInfo().getQueryMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryResult execute(ExecuteContext executeContext) {
|
||||
SemanticParseInfo parseInfo = executeContext.getParseInfo();
|
||||
|
||||
@@ -25,6 +25,11 @@ import java.util.Objects;
|
||||
|
||||
public class SqlExecutor implements ChatQueryExecutor {
|
||||
|
||||
@Override
|
||||
public boolean accept(ExecuteContext executeContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public QueryResult execute(ExecuteContext executeContext) {
|
||||
@@ -80,9 +85,9 @@ public class SqlExecutor implements ChatQueryExecutor {
|
||||
queryResult.setQueryId(executeContext.getRequest().getQueryId());
|
||||
queryResult.setChatContext(parseInfo);
|
||||
queryResult.setQueryMode(parseInfo.getQueryMode());
|
||||
queryResult.setQueryTimeCost(System.currentTimeMillis() - startTime);
|
||||
SemanticQueryResp queryResp =
|
||||
semanticLayer.queryByReq(sqlReq, executeContext.getRequest().getUser());
|
||||
queryResult.setQueryTimeCost(System.currentTimeMillis() - startTime);
|
||||
if (queryResp != null) {
|
||||
queryResult.setQueryAuthorization(queryResp.getQueryAuthorization());
|
||||
queryResult.setQuerySql(queryResp.getSql());
|
||||
|
||||
@@ -4,5 +4,7 @@ import com.tencent.supersonic.chat.server.pojo.ParseContext;
|
||||
|
||||
public interface ChatQueryParser {
|
||||
|
||||
boolean accept(ParseContext parseContext);
|
||||
|
||||
void parse(ParseContext parseContext);
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ public class NL2PluginParser implements ChatQueryParser {
|
||||
private final List<PluginRecognizer> pluginRecognizers =
|
||||
ComponentFactory.getPluginRecognizers();
|
||||
|
||||
public boolean accept(ParseContext parseContext) {
|
||||
return parseContext.getAgent().containsPluginTool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(ParseContext parseContext) {
|
||||
if (!parseContext.getAgent().containsPluginTool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pluginRecognizers.forEach(pluginRecognizer -> {
|
||||
pluginRecognizer.recognize(parseContext);
|
||||
log.info("{} recallResult:{}", pluginRecognizer.getClass().getSimpleName(),
|
||||
|
||||
@@ -73,12 +73,12 @@ public class NL2SQLParser implements ChatQueryParser {
|
||||
.build());
|
||||
}
|
||||
|
||||
public boolean accept(ParseContext parseContext) {
|
||||
return parseContext.enableNL2SQL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(ParseContext parseContext) {
|
||||
if (!parseContext.enableNL2SQL()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// first go with rule-based parsers unless the user has already selected one parse.
|
||||
if (Objects.isNull(parseContext.getRequest().getSelectedParse())) {
|
||||
QueryNLReq queryNLReq = QueryReqConverter.buildQueryNLReq(parseContext);
|
||||
|
||||
@@ -6,12 +6,12 @@ import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||
|
||||
public class PlainTextParser implements ChatQueryParser {
|
||||
|
||||
public boolean accept(ParseContext parseContext) {
|
||||
return !parseContext.getAgent().containsAnyTool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(ParseContext parseContext) {
|
||||
if (parseContext.getAgent().containsAnyTool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SemanticParseInfo parseInfo = new SemanticParseInfo();
|
||||
parseInfo.setQueryMode("PLAIN_TEXT");
|
||||
parseInfo.setId(1);
|
||||
|
||||
@@ -66,8 +66,10 @@ public class ChatConfigController {
|
||||
}
|
||||
|
||||
@GetMapping("/getDomainDataSetTree")
|
||||
public List<ItemResp> getDomainDataSetTree() {
|
||||
return semanticLayerService.getDomainDataSetTree();
|
||||
public List<ItemResp> getDomainDataSetTree(HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return semanticLayerService.getDomainDataSetTree(user);
|
||||
}
|
||||
|
||||
@GetMapping("/getDataSetSchema/{id}")
|
||||
|
||||
@@ -161,9 +161,11 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO> implem
|
||||
JsonUtil.toMap(agentDO.getChatModelConfig(), String.class, ChatApp.class));
|
||||
agent.setVisualConfig(JsonUtil.toObject(agentDO.getVisualConfig(), VisualConfig.class));
|
||||
agent.getChatAppConfig().values().forEach(c -> {
|
||||
ChatModel chatModel = chatModelService.getChatModel(c.getChatModelId());
|
||||
if (Objects.nonNull(chatModel)) {
|
||||
c.setChatModelConfig(chatModelService.getChatModel(c.getChatModelId()).getConfig());
|
||||
if (c.isEnable()) {// 优化,减少访问数据库的次数
|
||||
ChatModel chatModel = chatModelService.getChatModel(c.getChatModelId());
|
||||
if (Objects.nonNull(chatModel)) {
|
||||
c.setChatModelConfig(chatModel.getConfig());
|
||||
}
|
||||
}
|
||||
});
|
||||
agent.setAdmins(JsonUtil.toList(agentDO.getAdmin(), String.class));
|
||||
|
||||
@@ -95,7 +95,11 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
||||
}
|
||||
|
||||
ParseContext parseContext = buildParseContext(chatParseReq, new ChatParseResp(queryId));
|
||||
chatQueryParsers.forEach(p -> p.parse(parseContext));
|
||||
for (ChatQueryParser parser : chatQueryParsers) {
|
||||
if (parser.accept(parseContext)) {
|
||||
parser.parse(parseContext);
|
||||
}
|
||||
}
|
||||
|
||||
for (ParseResultProcessor processor : parseResultProcessors) {
|
||||
if (processor.accept(parseContext)) {
|
||||
@@ -116,9 +120,11 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
||||
QueryResult queryResult = new QueryResult();
|
||||
ExecuteContext executeContext = buildExecuteContext(chatExecuteReq);
|
||||
for (ChatQueryExecutor chatQueryExecutor : chatQueryExecutors) {
|
||||
queryResult = chatQueryExecutor.execute(executeContext);
|
||||
if (queryResult != null) {
|
||||
break;
|
||||
if (chatQueryExecutor.accept(executeContext)) {
|
||||
queryResult = chatQueryExecutor.execute(executeContext);
|
||||
if (queryResult != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,19 +18,23 @@ import com.tencent.supersonic.common.config.EmbeddingConfig;
|
||||
import com.tencent.supersonic.common.pojo.Text2SQLExemplar;
|
||||
import com.tencent.supersonic.common.pojo.User;
|
||||
import com.tencent.supersonic.common.service.ExemplarService;
|
||||
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.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MemoryServiceImpl implements MemoryService {
|
||||
@Slf4j
|
||||
public class MemoryServiceImpl implements MemoryService, CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private ChatMemoryRepository chatMemoryRepository;
|
||||
@@ -187,4 +191,25 @@ public class MemoryServiceImpl implements MemoryService {
|
||||
return memory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) { // 优化,启动时检查,向量数据,将记忆放到向量数据库
|
||||
loadSysExemplars();
|
||||
}
|
||||
|
||||
public void loadSysExemplars() {
|
||||
try {
|
||||
List<ChatMemory> memories = this
|
||||
.getMemories(ChatMemoryFilter.builder().status(MemoryStatus.ENABLED).build());
|
||||
for (ChatMemory memory : memories) {
|
||||
exemplarService.storeExemplar(
|
||||
embeddingConfig.getMemoryCollectionName(memory.getAgentId()),
|
||||
Text2SQLExemplar.builder().question(memory.getQuestion())
|
||||
.sideInfo(memory.getSideInfo()).dbSchema(memory.getDbSchema())
|
||||
.sql(memory.getS2sql()).build());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to load system exemplars", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,16 @@ public class SqlDialectFactory {
|
||||
.withLiteralQuoteString("'").withIdentifierQuoteString("\"")
|
||||
.withLiteralEscapedQuoteString("''").withUnquotedCasing(Casing.UNCHANGED)
|
||||
.withQuotedCasing(Casing.UNCHANGED).withCaseSensitive(true);
|
||||
public static final Context PRESTO_CONTEXT =
|
||||
SqlDialect.EMPTY_CONTEXT.withDatabaseProduct(DatabaseProduct.PRESTO)
|
||||
.withLiteralQuoteString("'").withIdentifierQuoteString("\"")
|
||||
.withLiteralEscapedQuoteString("''").withUnquotedCasing(Casing.UNCHANGED)
|
||||
.withQuotedCasing(Casing.UNCHANGED).withCaseSensitive(true);
|
||||
public static final Context KYUUBI_CONTEXT =
|
||||
SqlDialect.EMPTY_CONTEXT.withDatabaseProduct(DatabaseProduct.BIG_QUERY)
|
||||
.withLiteralQuoteString("'").withIdentifierQuoteString("`")
|
||||
.withLiteralEscapedQuoteString("''").withUnquotedCasing(Casing.UNCHANGED)
|
||||
.withQuotedCasing(Casing.UNCHANGED).withCaseSensitive(false);
|
||||
private static Map<EngineType, SemanticSqlDialect> sqlDialectMap;
|
||||
|
||||
static {
|
||||
@@ -35,6 +45,10 @@ public class SqlDialectFactory {
|
||||
sqlDialectMap.put(EngineType.H2, new SemanticSqlDialect(DEFAULT_CONTEXT));
|
||||
sqlDialectMap.put(EngineType.POSTGRESQL, new SemanticSqlDialect(POSTGRESQL_CONTEXT));
|
||||
sqlDialectMap.put(EngineType.HANADB, new SemanticSqlDialect(HANADB_CONTEXT));
|
||||
sqlDialectMap.put(EngineType.STARROCKS, new SemanticSqlDialect(DEFAULT_CONTEXT));
|
||||
sqlDialectMap.put(EngineType.KYUUBI, new SemanticSqlDialect(KYUUBI_CONTEXT));
|
||||
sqlDialectMap.put(EngineType.PRESTO, new SemanticSqlDialect(PRESTO_CONTEXT));
|
||||
sqlDialectMap.put(EngineType.TRINO, new SemanticSqlDialect(PRESTO_CONTEXT));
|
||||
}
|
||||
|
||||
public static SemanticSqlDialect getSqlDialect(EngineType engineType) {
|
||||
|
||||
@@ -2,19 +2,11 @@ package com.tencent.supersonic.common.calcite;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.calcite.sql.SqlIdentifier;
|
||||
import org.apache.calcite.sql.SqlLiteral;
|
||||
import org.apache.calcite.sql.SqlNode;
|
||||
import org.apache.calcite.sql.SqlNodeList;
|
||||
import org.apache.calcite.sql.SqlOrderBy;
|
||||
import org.apache.calcite.sql.SqlSelect;
|
||||
import org.apache.calcite.sql.SqlWith;
|
||||
import org.apache.calcite.sql.SqlWithItem;
|
||||
import org.apache.calcite.sql.SqlWriterConfig;
|
||||
import org.apache.calcite.sql.parser.SqlParseException;
|
||||
import org.apache.calcite.sql.parser.SqlParser;
|
||||
import org.apache.calcite.sql.parser.SqlParserPos;
|
||||
import org.apache.calcite.sql.pretty.SqlPrettyWriter;
|
||||
import net.sf.jsqlparser.expression.Alias;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
|
||||
import net.sf.jsqlparser.statement.select.Select;
|
||||
import net.sf.jsqlparser.statement.select.WithItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -22,85 +14,37 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class SqlMergeWithUtils {
|
||||
public static String mergeWith(EngineType engineType, String sql, List<String> parentSqlList,
|
||||
List<String> parentWithNameList) throws SqlParseException {
|
||||
SqlParser.Config parserConfig = Configuration.getParserConfig(engineType);
|
||||
List<String> parentWithNameList) throws Exception {
|
||||
|
||||
// Parse the main SQL statement
|
||||
SqlParser parser = SqlParser.create(sql, parserConfig);
|
||||
SqlNode sqlNode1 = parser.parseQuery();
|
||||
Select selectStatement = (Select) CCJSqlParserUtil.parse(sql);
|
||||
List<WithItem> withItemList = new ArrayList<>();
|
||||
|
||||
// List to hold all WITH items
|
||||
List<SqlNode> withItemList = new ArrayList<>();
|
||||
|
||||
// Iterate over each parentSql and parentWithName pair
|
||||
for (int i = 0; i < parentSqlList.size(); i++) {
|
||||
String parentSql = parentSqlList.get(i);
|
||||
String parentWithName = parentWithNameList.get(i);
|
||||
|
||||
// Parse the parent SQL statement
|
||||
parser = SqlParser.create(parentSql, parserConfig);
|
||||
SqlNode sqlNode2 = parser.parseQuery();
|
||||
Select parentSelect = (Select) CCJSqlParserUtil.parse(parentSql);
|
||||
ParenthesedSelect select = new ParenthesedSelect();
|
||||
select.setSelect(parentSelect);
|
||||
|
||||
// Create a new WITH item for parentWithName without quotes
|
||||
SqlWithItem withItem = new SqlWithItem(SqlParserPos.ZERO,
|
||||
new SqlIdentifier(parentWithName, SqlParserPos.ZERO), null, sqlNode2,
|
||||
SqlLiteral.createBoolean(false, SqlParserPos.ZERO));
|
||||
WithItem withItem = new WithItem();
|
||||
withItem.setAlias(new Alias(parentWithName));
|
||||
withItem.setSelect(select);
|
||||
|
||||
// Add the new WITH item to the list
|
||||
withItemList.add(withItem);
|
||||
}
|
||||
|
||||
// Check if the main SQL node contains an ORDER BY or LIMIT clause
|
||||
SqlNode limitNode = null;
|
||||
SqlNodeList orderByList = null;
|
||||
if (sqlNode1 instanceof SqlOrderBy) {
|
||||
SqlOrderBy sqlOrderBy = (SqlOrderBy) sqlNode1;
|
||||
limitNode = sqlOrderBy.fetch;
|
||||
orderByList = sqlOrderBy.orderList;
|
||||
sqlNode1 = sqlOrderBy.query;
|
||||
} else if (sqlNode1 instanceof SqlSelect) {
|
||||
SqlSelect sqlSelect = (SqlSelect) sqlNode1;
|
||||
limitNode = sqlSelect.getFetch();
|
||||
sqlSelect.setFetch(null);
|
||||
sqlNode1 = sqlSelect;
|
||||
// Extract existing WITH items from mainSelectBody if it has any
|
||||
if (selectStatement.getWithItemsList() != null) {
|
||||
withItemList.addAll(selectStatement.getWithItemsList());
|
||||
}
|
||||
|
||||
// Extract existing WITH items from sqlNode1 if it is a SqlWith
|
||||
if (sqlNode1 instanceof SqlWith) {
|
||||
SqlWith sqlWith = (SqlWith) sqlNode1;
|
||||
withItemList.addAll(sqlWith.withList.getList());
|
||||
sqlNode1 = sqlWith.body;
|
||||
}
|
||||
// Set the new WITH items list to the main select body
|
||||
selectStatement.setWithItemsList(withItemList);
|
||||
|
||||
// Create a new SqlWith node
|
||||
SqlWith finalSqlNode = new SqlWith(SqlParserPos.ZERO,
|
||||
new SqlNodeList(withItemList, SqlParserPos.ZERO), sqlNode1);
|
||||
|
||||
// If there was an ORDER BY or LIMIT clause, wrap the finalSqlNode in a SqlOrderBy
|
||||
SqlNode resultNode = finalSqlNode;
|
||||
if (orderByList != null || limitNode != null) {
|
||||
resultNode = new SqlOrderBy(SqlParserPos.ZERO, finalSqlNode,
|
||||
orderByList != null ? orderByList : SqlNodeList.EMPTY, null, limitNode);
|
||||
}
|
||||
|
||||
// Custom SqlPrettyWriter configuration to avoid quoting identifiers
|
||||
SqlWriterConfig config = Configuration.getSqlWriterConfig(engineType);
|
||||
// Pretty print the final SQL
|
||||
SqlPrettyWriter writer = new SqlPrettyWriter(config);
|
||||
return writer.format(resultNode);
|
||||
}
|
||||
|
||||
public static boolean hasWith(EngineType engineType, String sql) throws SqlParseException {
|
||||
SqlParser.Config parserConfig = Configuration.getParserConfig(engineType);
|
||||
SqlParser parser = SqlParser.create(sql, parserConfig);
|
||||
SqlNode sqlNode = parser.parseQuery();
|
||||
SqlNode sqlSelect = sqlNode;
|
||||
if (sqlNode instanceof SqlOrderBy) {
|
||||
SqlOrderBy sqlOrderBy = (SqlOrderBy) sqlNode;
|
||||
sqlSelect = sqlOrderBy.query;
|
||||
} else if (sqlNode instanceof SqlSelect) {
|
||||
sqlSelect = (SqlSelect) sqlNode;
|
||||
}
|
||||
return sqlSelect instanceof SqlWith;
|
||||
return selectStatement.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.tencent.supersonic.common.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.common.pojo.ChatModelConfig;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ChatModel {
|
||||
@@ -25,5 +27,11 @@ public class ChatModel {
|
||||
|
||||
private String admin;
|
||||
|
||||
private String viewer;
|
||||
private List<String> viewers = Lists.newArrayList();
|
||||
|
||||
private Integer isOpen = 0;
|
||||
|
||||
public boolean isPublic() {
|
||||
return isOpen != null && isOpen == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ public class FiledFilterReplaceVisitor extends ExpressionVisitorAdapter {
|
||||
}
|
||||
|
||||
ExpressionList<?> leftFunctionParams = leftFunction.getParameters();
|
||||
if (CollectionUtils.isEmpty(leftFunctionParams)) {
|
||||
if (CollectionUtils.isEmpty(leftFunctionParams)
|
||||
|| !(leftFunctionParams.get(0) instanceof Column)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,10 @@ public class SqlReplaceHelper {
|
||||
public static String replaceFields(String sql, Map<String, String> fieldNameMap,
|
||||
boolean exactReplace) {
|
||||
Select selectStatement = SqlSelectHelper.getSelect(sql);
|
||||
// alias field should not be replaced
|
||||
Set<String> aliases = SqlSelectHelper.getAliasFields(sql);
|
||||
aliases.forEach(alias -> fieldNameMap.put(alias, alias));
|
||||
|
||||
Set<Select> plainSelectList = SqlSelectHelper.getAllSelect(selectStatement);
|
||||
for (Select plainSelect : plainSelectList) {
|
||||
if (plainSelect instanceof PlainSelect) {
|
||||
|
||||
@@ -989,6 +989,15 @@ public class SqlSelectHelper {
|
||||
for (SelectItem selectItem : selectItems) {
|
||||
selectItem.accept(visitor);
|
||||
}
|
||||
if (plainSelect.getHaving() != null) {
|
||||
plainSelect.getHaving().accept(visitor);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(plainSelect.getOrderByElements())) {
|
||||
for (OrderByElement orderByElement : plainSelect.getOrderByElements()) {
|
||||
orderByElement.getExpression().accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
return !visitor.getFunctionNames().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,4 +30,6 @@ public class ChatModelDO {
|
||||
private String admin;
|
||||
|
||||
private String viewer;
|
||||
|
||||
private Integer isOpen;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.common.pojo;
|
||||
import com.google.common.base.Objects;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.ASC_UPPER;
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.tencent.supersonic.common.pojo.User;
|
||||
import java.util.List;
|
||||
|
||||
public interface ChatModelService {
|
||||
List<ChatModel> getChatModels();
|
||||
List<ChatModel> getChatModels(User user);
|
||||
|
||||
ChatModel getChatModel(Integer id);
|
||||
|
||||
|
||||
@@ -23,8 +23,15 @@ import java.util.stream.Collectors;
|
||||
public class ChatModelServiceImpl extends ServiceImpl<ChatModelMapper, ChatModelDO>
|
||||
implements ChatModelService {
|
||||
@Override
|
||||
public List<ChatModel> getChatModels() {
|
||||
return list().stream().map(this::convert).collect(Collectors.toList());
|
||||
public List<ChatModel> getChatModels(User user) {
|
||||
return list().stream().map(this::convert).filter(chatModel -> {
|
||||
if (chatModel.isPublic() || user.isSuperAdmin()
|
||||
|| chatModel.getCreatedBy().equals(user.getName())
|
||||
|| chatModel.getViewers().contains(user.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,10 +48,14 @@ public class ChatModelServiceImpl extends ServiceImpl<ChatModelMapper, ChatModel
|
||||
chatModelDO.setCreatedBy(user.getName());
|
||||
chatModelDO.setCreatedAt(new Date());
|
||||
chatModelDO.setUpdatedBy(user.getName());
|
||||
chatModelDO.setUpdatedAt(new Date());
|
||||
chatModelDO.setUpdatedAt(chatModelDO.getCreatedAt());
|
||||
chatModelDO.setIsOpen(chatModel.getIsOpen());
|
||||
if (StringUtils.isBlank(chatModel.getAdmin())) {
|
||||
chatModelDO.setAdmin(user.getName());
|
||||
}
|
||||
if (!chatModel.getViewers().isEmpty()) {
|
||||
chatModelDO.setViewer(JsonUtil.toString(chatModel.getViewers()));
|
||||
}
|
||||
save(chatModelDO);
|
||||
chatModel.setId(chatModelDO.getId());
|
||||
return chatModel;
|
||||
@@ -55,9 +66,13 @@ public class ChatModelServiceImpl extends ServiceImpl<ChatModelMapper, ChatModel
|
||||
ChatModelDO chatModelDO = convert(chatModel);
|
||||
chatModelDO.setUpdatedBy(user.getName());
|
||||
chatModelDO.setUpdatedAt(new Date());
|
||||
chatModelDO.setIsOpen(chatModel.getIsOpen());
|
||||
if (StringUtils.isBlank(chatModel.getAdmin())) {
|
||||
chatModel.setAdmin(user.getName());
|
||||
}
|
||||
if (!chatModel.getViewers().isEmpty()) {
|
||||
chatModelDO.setViewer(JsonUtil.toString(chatModel.getViewers()));
|
||||
}
|
||||
updateById(chatModelDO);
|
||||
return chatModel;
|
||||
}
|
||||
@@ -74,6 +89,7 @@ public class ChatModelServiceImpl extends ServiceImpl<ChatModelMapper, ChatModel
|
||||
ChatModel chatModel = new ChatModel();
|
||||
BeanUtils.copyProperties(chatModelDO, chatModel);
|
||||
chatModel.setConfig(JsonUtil.toObject(chatModelDO.getConfig(), ChatModelConfig.class));
|
||||
chatModel.setViewers(JsonUtil.toList(chatModelDO.getViewer(), String.class));
|
||||
return chatModel;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.tencent.supersonic.common.calcite;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.calcite.sql.parser.SqlParseException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -12,7 +11,7 @@ import java.util.Collections;
|
||||
class SqlWithMergerTest {
|
||||
|
||||
@Test
|
||||
void test1() throws SqlParseException {
|
||||
void test1() throws Exception {
|
||||
String sql1 = "WITH DepartmentVisits AS (\n" + " SELECT department, SUM(pv) AS 总访问次数\n"
|
||||
+ " FROM t_1\n"
|
||||
+ " WHERE sys_imp_date >= '2024-09-01' AND sys_imp_date <= '2024-09-29'\n"
|
||||
@@ -38,7 +37,7 @@ class SqlWithMergerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void test2() throws SqlParseException {
|
||||
void test2() throws Exception {
|
||||
|
||||
String sql1 =
|
||||
"WITH DepartmentVisits AS (SELECT department, SUM(pv) AS 总访问次数 FROM t_1 WHERE sys_imp_date >= '2024-08-28' "
|
||||
@@ -65,7 +64,7 @@ class SqlWithMergerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void test3() throws SqlParseException {
|
||||
void test3() throws Exception {
|
||||
|
||||
String sql1 = "SELECT COUNT(*) FROM DepartmentVisits WHERE 总访问次数 > 100 LIMIT 1000";
|
||||
|
||||
@@ -89,7 +88,7 @@ class SqlWithMergerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void test4() throws SqlParseException {
|
||||
void test4() throws Exception {
|
||||
String sql1 = "SELECT COUNT(*) FROM DepartmentVisits WHERE 总访问次数 > 100";
|
||||
|
||||
String sql2 =
|
||||
@@ -112,7 +111,7 @@ class SqlWithMergerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void test5() throws SqlParseException {
|
||||
void test5() throws Exception {
|
||||
|
||||
String sql1 = "SELECT COUNT(*) FROM Department join Visits WHERE 总访问次数 > 100";
|
||||
|
||||
@@ -132,13 +131,13 @@ class SqlWithMergerTest {
|
||||
"WITH t_1 AS (SELECT `t3`.`sys_imp_date`, `t2`.`department`, `t3`.`s2_pv_uv_statis_pv` AS `pv` "
|
||||
+ "FROM (SELECT `user_name`, `department` FROM `s2_user_department`) AS `t2` LEFT JOIN "
|
||||
+ "(SELECT 1 AS `s2_pv_uv_statis_pv`, `imp_date` AS `sys_imp_date`, `user_name` FROM `s2_pv_uv_statis`) "
|
||||
+ "AS `t3` ON `t2`.`user_name` = `t3`.`user_name`) SELECT COUNT(*) FROM Department INNER JOIN Visits "
|
||||
+ "AS `t3` ON `t2`.`user_name` = `t3`.`user_name`) SELECT COUNT(*) FROM Department JOIN Visits "
|
||||
+ "WHERE 总访问次数 > 100");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void test6() throws SqlParseException {
|
||||
void test6() throws Exception {
|
||||
|
||||
String sql1 =
|
||||
"SELECT COUNT(*) FROM Department join Visits WHERE 总访问次数 > 100 ORDER BY 总访问次数 LIMIT 10";
|
||||
@@ -159,7 +158,36 @@ class SqlWithMergerTest {
|
||||
"WITH t_1 AS (SELECT `t3`.`sys_imp_date`, `t2`.`department`, `t3`.`s2_pv_uv_statis_pv` AS `pv` FROM "
|
||||
+ "(SELECT `user_name`, `department` FROM `s2_user_department`) AS `t2` LEFT JOIN (SELECT 1 AS `s2_pv_uv_statis_pv`,"
|
||||
+ " `imp_date` AS `sys_imp_date`, `user_name` FROM `s2_pv_uv_statis`) AS `t3` ON `t2`.`user_name` = `t3`.`user_name`) "
|
||||
+ "SELECT COUNT(*) FROM Department INNER JOIN Visits WHERE 总访问次数 > 100 ORDER BY 总访问次数 LIMIT 10");
|
||||
+ "SELECT COUNT(*) FROM Department JOIN Visits WHERE 总访问次数 > 100 ORDER BY 总访问次数 LIMIT 10");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test7() throws Exception {
|
||||
|
||||
String sql1 =
|
||||
"SELECT COUNT(*) FROM Department join Visits WHERE 总访问次数 > 100 AND imp_date >= CURRENT_DATE - "
|
||||
+ "INTERVAL '1 year' AND sys_imp_date < CURRENT_DATE ORDER"
|
||||
+ " BY 总访问次数 LIMIT 10";
|
||||
|
||||
String sql2 =
|
||||
"SELECT `t3`.`sys_imp_date`, `t2`.`department`, `t3`.`s2_pv_uv_statis_pv` AS `pv`\n"
|
||||
+ "FROM\n" + "(SELECT `user_name`, `department`\n" + "FROM\n"
|
||||
+ "`s2_user_department`) AS `t2`\n"
|
||||
+ "LEFT JOIN (SELECT 1 AS `s2_pv_uv_statis_pv`, `imp_date` AS `sys_imp_date`, `user_name`\n"
|
||||
+ "FROM\n"
|
||||
+ "`s2_pv_uv_statis`) AS `t3` ON `t2`.`user_name` = `t3`.`user_name`";
|
||||
|
||||
String mergeSql = SqlMergeWithUtils.mergeWith(EngineType.MYSQL, sql1,
|
||||
Collections.singletonList(sql2), Collections.singletonList("t_1"));
|
||||
|
||||
|
||||
Assert.assertEquals(format(mergeSql),
|
||||
"WITH t_1 AS (SELECT `t3`.`sys_imp_date`, `t2`.`department`, `t3`.`s2_pv_uv_statis_pv` AS `pv` FROM "
|
||||
+ "(SELECT `user_name`, `department` FROM `s2_user_department`) AS `t2` LEFT JOIN (SELECT 1 AS `s2_pv_uv_statis_pv`,"
|
||||
+ " `imp_date` AS `sys_imp_date`, `user_name` FROM `s2_pv_uv_statis`) AS `t3` ON `t2`.`user_name` = `t3`.`user_name`) "
|
||||
+ "SELECT COUNT(*) FROM Department JOIN Visits WHERE 总访问次数 > 100 AND imp_date >= "
|
||||
+ "CURRENT_DATE - INTERVAL '1 year' AND sys_imp_date < CURRENT_DATE ORDER BY 总访问次数 "
|
||||
+ "LIMIT 10");
|
||||
}
|
||||
|
||||
private static String format(String mergeSql) {
|
||||
|
||||
@@ -27,4 +27,4 @@ WORKDIR /usr/src/app/supersonic-standalone-${SUPERSONIC_VERSION}
|
||||
EXPOSE 9080
|
||||
# Command to run the supersonic daemon
|
||||
RUN chmod +x bin/supersonic-daemon.sh
|
||||
CMD ["bash", "-c", "bin/supersonic-daemon.sh restart standalone docker && tail -f /dev/null"]
|
||||
CMD ["bash", "-c", "bin/supersonic-daemon.sh restart standalone ${S2_DB_TYPE} && tail -f /dev/null"]
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
# Function to execute the build script
|
||||
execute_build_script() {
|
||||
echo "Executing build script: assembly/bin/supersonic-build.sh"
|
||||
assembly/bin/supersonic-build.sh
|
||||
echo "Executing build script: sh assembly/bin/supersonic-build.sh"
|
||||
sh assembly/bin/supersonic-build.sh
|
||||
}
|
||||
|
||||
# Function to build the Docker image
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SUPERSONIC_VERSION=latest docker-compose -f docker-compose.yml -p supersonic up
|
||||
@@ -12,7 +12,7 @@ services:
|
||||
ports:
|
||||
- "15432:5432"
|
||||
# volumes:
|
||||
# - postgres_data:/var/lib/postgresql
|
||||
# - postgres_data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- supersonic_network
|
||||
dns:
|
||||
@@ -30,12 +30,19 @@ services:
|
||||
privileged: true
|
||||
container_name: supersonic_standalone
|
||||
environment:
|
||||
DB_HOST: supersonic_postgres
|
||||
DB_NAME: postgres
|
||||
DB_USERNAME: supersonic_user
|
||||
DB_PASSWORD: supersonic_password
|
||||
S2_DB_TYPE: postgres
|
||||
S2_DB_HOST: supersonic_postgres
|
||||
S2_DB_PORT: 5432
|
||||
S2_DB_DATABASE: postgres
|
||||
S2_DB_USER: supersonic_user
|
||||
S2_DB_PASSWORD: supersonic_password
|
||||
ports:
|
||||
- "9080:9080"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "2.0"
|
||||
memory: 2048M
|
||||
depends_on:
|
||||
supersonic_postgres:
|
||||
condition: service_healthy
|
||||
@@ -62,4 +69,4 @@ services:
|
||||
# supersonic_data:
|
||||
|
||||
networks:
|
||||
supersonic_network:
|
||||
supersonic_network:
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.tencent.supersonic.headless.api.pojo;
|
||||
import com.tencent.supersonic.common.pojo.Constants;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.DimensionType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Dimension {
|
||||
|
||||
@@ -23,12 +23,16 @@ public class Measure {
|
||||
|
||||
private String alias;
|
||||
|
||||
public Measure(String name, String bizName, String expr, String agg, Integer isCreateMetric) {
|
||||
private String unit;
|
||||
|
||||
public Measure(String name, String bizName, String expr, String agg, String unit,
|
||||
Integer isCreateMetric) {
|
||||
this.name = name;
|
||||
this.agg = agg;
|
||||
this.isCreateMetric = isCreateMetric;
|
||||
this.bizName = bizName;
|
||||
this.expr = expr;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public Measure(String name, String bizName, String agg, Integer isCreateMetric) {
|
||||
|
||||
@@ -24,6 +24,8 @@ public class ModelDetail {
|
||||
|
||||
private String tableQuery;
|
||||
|
||||
private String filterSql;
|
||||
|
||||
private List<Identify> identifiers = Lists.newArrayList();
|
||||
|
||||
private List<Dimension> dimensions = Lists.newArrayList();
|
||||
@@ -49,27 +51,4 @@ public class ModelDetail {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Field> getFields() {
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
return fields;
|
||||
}
|
||||
List<Field> fieldList = Lists.newArrayList();
|
||||
// Compatible with older versions
|
||||
if (!CollectionUtils.isEmpty(identifiers)) {
|
||||
fieldList.addAll(identifiers.stream()
|
||||
.map(identify -> Field.builder().fieldName(identify.getFieldName()).build())
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dimensions)) {
|
||||
fieldList.addAll(dimensions.stream()
|
||||
.map(dim -> Field.builder().fieldName(dim.getFieldName()).build())
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(measures)) {
|
||||
fieldList.addAll(measures.stream()
|
||||
.map(measure -> Field.builder().fieldName(measure.getFieldName()).build())
|
||||
.collect(Collectors.toSet()));
|
||||
}
|
||||
return fieldList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ public class ModelSchema {
|
||||
|
||||
private String description;
|
||||
|
||||
private List<ColumnSchema> columnSchemas;
|
||||
private List<SemanticColumn> semanticColumns;
|
||||
|
||||
@JsonIgnore
|
||||
public ColumnSchema getColumnByName(String columnName) {
|
||||
for (ColumnSchema fieldSchema : columnSchemas) {
|
||||
public SemanticColumn getColumnByName(String columnName) {
|
||||
for (SemanticColumn fieldSchema : semanticColumns) {
|
||||
if (fieldSchema.getColumnName().equalsIgnoreCase(columnName)) {
|
||||
return fieldSchema;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.tencent.supersonic.headless.api.pojo.enums.FieldType;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ColumnSchema {
|
||||
public class SemanticColumn {
|
||||
|
||||
private String columnName;
|
||||
|
||||
@@ -19,4 +19,8 @@ public class ColumnSchema {
|
||||
|
||||
private String name;
|
||||
|
||||
private String expr;
|
||||
|
||||
private String unit;
|
||||
|
||||
}
|
||||
@@ -32,9 +32,12 @@ public class DatabaseReq extends RecordInfo {
|
||||
private String description;
|
||||
|
||||
private String schema;
|
||||
|
||||
private String url;
|
||||
|
||||
private List<String> admins = Lists.newArrayList();
|
||||
|
||||
private List<String> viewers = Lists.newArrayList();
|
||||
|
||||
private Integer isOpen = 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ public class ModelBuildReq {
|
||||
|
||||
private String sql;
|
||||
|
||||
private String filterSql;
|
||||
|
||||
private String catalog;
|
||||
|
||||
private String db;
|
||||
|
||||
@@ -170,6 +170,9 @@ public class QueryStructReq extends SemanticQueryReq {
|
||||
// 5. Set the limit clause
|
||||
plainSelect.setLimit(buildLimit(queryStructReq));
|
||||
|
||||
// 6. Set having clause
|
||||
plainSelect.setHaving(buildHavingClause(queryStructReq));
|
||||
|
||||
select.setSelect(plainSelect);
|
||||
|
||||
// 6. Set where clause
|
||||
@@ -239,7 +242,8 @@ public class QueryStructReq extends SemanticQueryReq {
|
||||
|
||||
private GroupByElement buildGroupByElement(QueryStructReq queryStructReq) {
|
||||
List<String> groups = queryStructReq.getGroups();
|
||||
if (!CollectionUtils.isEmpty(groups) && !queryStructReq.getAggregators().isEmpty()) {
|
||||
if ((!CollectionUtils.isEmpty(groups) && !queryStructReq.getAggregators().isEmpty())
|
||||
|| !queryStructReq.getMetricFilters().isEmpty()) {
|
||||
GroupByElement groupByElement = new GroupByElement();
|
||||
for (String group : groups) {
|
||||
groupByElement.addGroupByExpression(new Column(group));
|
||||
@@ -289,4 +293,23 @@ public class QueryStructReq extends SemanticQueryReq {
|
||||
}
|
||||
return Constants.TABLE_PREFIX + StringUtils.join(modelIds, "_");
|
||||
}
|
||||
|
||||
public Expression buildHavingClause(QueryStructReq queryStructReq) {
|
||||
if (queryStructReq.getMetricFilters().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Filter> filters = queryStructReq.getMetricFilters();
|
||||
SqlFilterUtils sqlFilterUtils = ContextUtils.getBean(SqlFilterUtils.class);
|
||||
String havingClause = sqlFilterUtils.getWhereClause(filters, false);
|
||||
if (StringUtils.isNotBlank(havingClause)) {
|
||||
try {
|
||||
return CCJSqlParserUtil.parseCondExpression(havingClause);
|
||||
} catch (JSQLParserException e) {
|
||||
log.error("Failed to parse having clause", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ public class DatabaseResp extends RecordInfo {
|
||||
|
||||
private List<String> viewers = Lists.newArrayList();
|
||||
|
||||
private Integer isOpen = 0;
|
||||
|
||||
private String type;
|
||||
|
||||
private String url;
|
||||
@@ -48,6 +50,10 @@ public class DatabaseResp extends RecordInfo {
|
||||
|
||||
private boolean hasEditPermission = false;
|
||||
|
||||
public boolean isPublic() {
|
||||
return isOpen != null && isOpen == 1;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
Pattern p = Pattern.compile("jdbc:(?<db>\\w+):.*((//)|@)(?<host>.+):(?<port>\\d+).*");
|
||||
Matcher m = p.matcher(url);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tencent.supersonic.headless.chat.corrector;
|
||||
|
||||
import com.tencent.supersonic.common.jsqlparser.FieldExpression;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlAddHelper;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlSelectHelper;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlValidHelper;
|
||||
@@ -8,10 +9,7 @@ import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/** Perform SQL corrections on the "Select" section in S2SQL. */
|
||||
@Slf4j
|
||||
@@ -46,10 +44,28 @@ public class SelectCorrector extends BaseSemanticCorrector {
|
||||
return correctS2SQL;
|
||||
}
|
||||
needAddFields.removeAll(selectFields);
|
||||
String addFieldsToSelectSql =
|
||||
SqlAddHelper.addFieldsToSelect(correctS2SQL, new ArrayList<>(needAddFields));
|
||||
semanticParseInfo.getSqlInfo().setCorrectedS2SQL(addFieldsToSelectSql);
|
||||
return addFieldsToSelectSql;
|
||||
|
||||
if (!SqlSelectHelper.hasSubSelect(correctS2SQL)) { // 优化内容 , 如果sql 条件包含了这个字段,而且是全等,则不再查询该字段
|
||||
List<FieldExpression> tmp4 = SqlSelectHelper.getWhereExpressions(correctS2SQL);
|
||||
Iterator<String> it = needAddFields.iterator();
|
||||
while (it.hasNext()) {
|
||||
String field = it.next();
|
||||
long size = tmp4.stream()
|
||||
.filter(e -> e.getFieldName().equals(field) && "=".equals(e.getOperator()))
|
||||
.count();
|
||||
if (size == 1) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needAddFields.size() > 0) {
|
||||
String addFieldsToSelectSql =
|
||||
SqlAddHelper.addFieldsToSelect(correctS2SQL, new ArrayList<>(needAddFields));
|
||||
semanticParseInfo.getSqlInfo().setCorrectedS2SQL(addFieldsToSelectSql);
|
||||
return addFieldsToSelectSql;
|
||||
} else {
|
||||
return correctS2SQL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,4 +22,9 @@ public abstract class MapResult implements Serializable {
|
||||
return this.getMapKey().equals(otherResult.getMapKey())
|
||||
&& this.similarity < otherResult.similarity;
|
||||
}
|
||||
|
||||
public Boolean lessOrEqualSimilar(MapResult otherResult) {
|
||||
return this.getMapKey().equals(otherResult.getMapKey())
|
||||
&& this.similarity <= otherResult.similarity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ public class MetaEmbeddingService {
|
||||
return dataSetIds.stream().map(dataSetId -> {
|
||||
Retrieval newRetrieval = new Retrieval();
|
||||
BeanUtils.copyProperties(retrieval, newRetrieval);
|
||||
HashMap<String, Object> newMetadata = new HashMap<>(retrieval.getMetadata());
|
||||
newRetrieval.setMetadata(newMetadata);
|
||||
newRetrieval.getMetadata().putIfAbsent("dataSetId",
|
||||
dataSetId + Constants.UNDERLINE);
|
||||
return newRetrieval;
|
||||
|
||||
@@ -56,7 +56,8 @@ public abstract class BaseMatchStrategy<T extends MapResult> implements MatchStr
|
||||
for (T oneRoundResult : oneRoundResults) {
|
||||
if (existResults.contains(oneRoundResult)) {
|
||||
boolean isDeleted = existResults.removeIf(existResult -> {
|
||||
boolean delete = existResult.lessSimilar(oneRoundResult);
|
||||
// boolean delete = existResult.lessSimilar(oneRoundResult);
|
||||
boolean delete = existResult.lessOrEqualSimilar(oneRoundResult);
|
||||
if (delete) {
|
||||
log.debug("deleted existResult:{}", existResult);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ public class KeywordMapper extends BaseMapper {
|
||||
continue;
|
||||
}
|
||||
Long elementID = NatureHelper.getElementID(nature);
|
||||
if (elementID == null) {
|
||||
continue;
|
||||
}
|
||||
SchemaElement element = getSchemaElement(dataSetId, elementType, elementID,
|
||||
chatQueryContext.getSemanticSchema());
|
||||
if (Objects.isNull(element)) {
|
||||
|
||||
@@ -41,6 +41,28 @@ class AggCorrectorTest {
|
||||
semanticParseInfo.getSqlInfo().getCorrectedS2SQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSchemaCorrector() {
|
||||
SchemaCorrector corrector = new SchemaCorrector();
|
||||
Long dataSetId = 1L;
|
||||
ChatQueryContext chatQueryContext = buildQueryContext(dataSetId);
|
||||
SemanticParseInfo semanticParseInfo = new SemanticParseInfo();
|
||||
SchemaElement dataSet = new SchemaElement();
|
||||
dataSet.setDataSetId(dataSetId);
|
||||
semanticParseInfo.setDataSet(dataSet);
|
||||
SqlInfo sqlInfo = new SqlInfo();
|
||||
String sql =
|
||||
"WITH 总停留时长 AS (SELECT 用户, SUM(停留时长) AS _总停留时长_ FROM 超音数数据集 WHERE 用户 IN ('alice', 'lucy') AND 数据日期 >= '2025-03-01' AND 数据日期 <= '2025-03-12' GROUP BY 用户) SELECT 用户, _总停留时长_ FROM 总停留时长";
|
||||
sqlInfo.setParsedS2SQL(sql);
|
||||
sqlInfo.setCorrectedS2SQL(sql);
|
||||
semanticParseInfo.setSqlInfo(sqlInfo);
|
||||
corrector.correct(chatQueryContext, semanticParseInfo);
|
||||
Assert.assertEquals(
|
||||
"WITH 总停留时长 AS (SELECT 用户名, SUM(停留时长) AS _总停留时长_ FROM 超音数数据集 WHERE 用户名 IN ('alice', 'lucy') AND 数据日期 "
|
||||
+ ">= '2025-03-01' AND 数据日期 <= '2025-03-12' GROUP BY 用户名) SELECT 用户名, _总停留时长_ FROM 总停留时长",
|
||||
semanticParseInfo.getSqlInfo().getCorrectedS2SQL());
|
||||
}
|
||||
|
||||
private ChatQueryContext buildQueryContext(Long dataSetId) {
|
||||
ChatQueryContext chatQueryContext = new ChatQueryContext();
|
||||
List<DataSetSchema> dataSetSchemaList = new ArrayList<>();
|
||||
@@ -51,18 +73,18 @@ class AggCorrectorTest {
|
||||
schemaElement.setDataSetId(dataSetId);
|
||||
dataSetSchema.setDataSet(schemaElement);
|
||||
Set<SchemaElement> dimensions = new HashSet<>();
|
||||
SchemaElement element1 = new SchemaElement();
|
||||
element1.setDataSetId(1L);
|
||||
element1.setName("部门");
|
||||
dimensions.add(element1);
|
||||
|
||||
dimensions.add(SchemaElement.builder().dataSetId(1L).name("部门").build());
|
||||
|
||||
dimensions.add(SchemaElement.builder().dataSetId(1L).name("用户名").build());
|
||||
|
||||
dataSetSchema.setDimensions(dimensions);
|
||||
|
||||
Set<SchemaElement> metrics = new HashSet<>();
|
||||
SchemaElement metric1 = new SchemaElement();
|
||||
metric1.setDataSetId(1L);
|
||||
metric1.setName("访问次数");
|
||||
metrics.add(metric1);
|
||||
|
||||
metrics.add(SchemaElement.builder().dataSetId(1L).name("访问次数").build());
|
||||
|
||||
metrics.add(SchemaElement.builder().dataSetId(1L).name("停留时长").build());
|
||||
|
||||
dataSetSchema.setMetrics(metrics);
|
||||
dataSetSchemaList.add(dataSetSchema);
|
||||
|
||||
@@ -83,6 +83,7 @@ public class PrestoAdaptor extends BaseDbAdaptor {
|
||||
|
||||
@Override
|
||||
public String rewriteSql(String sql) {
|
||||
sql = sql.replaceAll("`", "\"");
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tencent.supersonic.headless.core.translator;
|
||||
|
||||
import com.tencent.supersonic.common.calcite.SqlMergeWithUtils;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlSelectHelper;
|
||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.QueryState;
|
||||
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
||||
@@ -73,7 +74,7 @@ public class DefaultSemanticTranslator implements SemanticTranslator {
|
||||
String finalSql = null;
|
||||
if (sqlQuery.isSupportWith()) {
|
||||
EngineType engineType = queryStatement.getOntology().getDatabaseType();
|
||||
if (!SqlMergeWithUtils.hasWith(engineType, ontologyOuterSql)) {
|
||||
if (!SqlSelectHelper.hasWith(ontologyOuterSql)) {
|
||||
finalSql = "with " + tables.stream()
|
||||
.map(t -> String.format("%s as (%s)", t.getLeft(), t.getRight()))
|
||||
.collect(Collectors.joining(",")) + "\n" + ontologyOuterSql;
|
||||
|
||||
@@ -40,11 +40,23 @@ public class DataModelNode extends SemanticNode {
|
||||
.equalsIgnoreCase(EngineType.POSTGRESQL.getName())) {
|
||||
String fullTableName = String.join(".public.",
|
||||
dataModel.getModelDetail().getTableQuery().split("\\."));
|
||||
sqlTable = "select * from " + fullTableName;
|
||||
sqlTable = "SELECT * FROM " + fullTableName;
|
||||
} else {
|
||||
sqlTable = "select * from " + dataModel.getModelDetail().getTableQuery();
|
||||
sqlTable = "SELECT * FROM " + dataModel.getModelDetail().getTableQuery();
|
||||
}
|
||||
}
|
||||
|
||||
// String filterSql = dataModel.getFilterSql();
|
||||
String filterSql = dataModel.getModelDetail().getFilterSql();
|
||||
if (filterSql != null && !filterSql.isEmpty()) {
|
||||
boolean sqlContainWhere = sqlTable.toUpperCase().matches("(?s).*\\bWHERE\\b.*");
|
||||
if (sqlContainWhere) {
|
||||
sqlTable = String.format("%s AND %s", sqlTable, filterSql);
|
||||
} else {
|
||||
sqlTable = String.format("%s WHERE %s", sqlTable, filterSql);
|
||||
}
|
||||
}
|
||||
|
||||
if (sqlTable.isEmpty()) {
|
||||
throw new Exception("DataModelNode build error [tableSqlNode not found]");
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ public abstract class SemanticNode {
|
||||
scope.getValidator().getCatalogReader().getRootSchema(), engineType);
|
||||
if (Configuration.getSqlAdvisor(sqlValidatorWithHints, engineType).getReservedAndKeyWords()
|
||||
.contains(expression.toUpperCase())) {
|
||||
if (engineType == EngineType.HANADB) {
|
||||
if (engineType == EngineType.HANADB || engineType == EngineType.PRESTO
|
||||
|| engineType == EngineType.TRINO) {
|
||||
expression = String.format("\"%s\"", expression);
|
||||
} else {
|
||||
expression = String.format("`%s`", expression);
|
||||
@@ -166,9 +167,9 @@ public abstract class SemanticNode {
|
||||
if (sqlNode instanceof SqlBasicCall) {
|
||||
SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
|
||||
if (sqlBasicCall.getOperator().getKind().equals(SqlKind.AS)) {
|
||||
if (sqlBasicCall.getOperandList().get(0) instanceof SqlSelect) {
|
||||
SqlSelect table = (SqlSelect) sqlBasicCall.getOperandList().get(0);
|
||||
return table;
|
||||
SqlNode innerQuery = sqlBasicCall.getOperandList().get(0);
|
||||
if (innerQuery instanceof SqlCall) {
|
||||
return innerQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,13 @@ public class SqlBuilder {
|
||||
SqlNode parserNode = tableView.build();
|
||||
DatabaseResp database = queryStatement.getOntology().getDatabase();
|
||||
EngineType engineType = EngineType.fromString(database.getType());
|
||||
parserNode = optimizeParseNode(parserNode, engineType);
|
||||
try {
|
||||
parserNode = optimizeParseNode(parserNode, engineType);
|
||||
} catch (Exception e) {
|
||||
// failure in optimization phase doesn't affect the query result,
|
||||
// just ignore it
|
||||
log.error("optimizeParseNode error", e);
|
||||
}
|
||||
return SemanticNode.getSql(parserNode, engineType);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public interface SemanticLayerService {
|
||||
|
||||
DataSetSchema getDataSetSchema(Long id);
|
||||
|
||||
List<ItemResp> getDomainDataSetTree();
|
||||
List<ItemResp> getDomainDataSetTree(User user);
|
||||
|
||||
List<DimensionResp> getDimensions(MetaFilter metaFilter);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.common.collect.Sets;
|
||||
import com.tencent.supersonic.common.pojo.Constants;
|
||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||
import com.tencent.supersonic.common.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.common.pojo.enums.TaskStatusEnum;
|
||||
import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.Dimension;
|
||||
@@ -29,10 +30,7 @@ import com.tencent.supersonic.headless.core.utils.ComponentFactory;
|
||||
import com.tencent.supersonic.headless.server.annotation.S2DataPermission;
|
||||
import com.tencent.supersonic.headless.server.facade.service.SemanticLayerService;
|
||||
import com.tencent.supersonic.headless.server.manager.SemanticSchemaManager;
|
||||
import com.tencent.supersonic.headless.server.service.DataSetService;
|
||||
import com.tencent.supersonic.headless.server.service.DimensionService;
|
||||
import com.tencent.supersonic.headless.server.service.MetricService;
|
||||
import com.tencent.supersonic.headless.server.service.SchemaService;
|
||||
import com.tencent.supersonic.headless.server.service.*;
|
||||
import com.tencent.supersonic.headless.server.utils.MetricDrillDownChecker;
|
||||
import com.tencent.supersonic.headless.server.utils.QueryUtils;
|
||||
import com.tencent.supersonic.headless.server.utils.StatUtils;
|
||||
@@ -59,6 +57,7 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
||||
private final MetricDrillDownChecker metricDrillDownChecker;
|
||||
private final KnowledgeBaseService knowledgeBaseService;
|
||||
private final MetricService metricService;
|
||||
private final DomainService domainService;
|
||||
private final DimensionService dimensionService;
|
||||
private final TranslatorConfig translatorConfig;
|
||||
private final QueryCache queryCache = ComponentFactory.getQueryCache();
|
||||
@@ -69,7 +68,8 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
||||
SchemaService schemaService, SemanticTranslator semanticTranslator,
|
||||
MetricDrillDownChecker metricDrillDownChecker,
|
||||
KnowledgeBaseService knowledgeBaseService, MetricService metricService,
|
||||
DimensionService dimensionService, TranslatorConfig translatorConfig) {
|
||||
DimensionService dimensionService, DomainService domainService,
|
||||
TranslatorConfig translatorConfig) {
|
||||
this.statUtils = statUtils;
|
||||
this.queryUtils = queryUtils;
|
||||
this.semanticSchemaManager = semanticSchemaManager;
|
||||
@@ -80,6 +80,7 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
||||
this.knowledgeBaseService = knowledgeBaseService;
|
||||
this.metricService = metricService;
|
||||
this.dimensionService = dimensionService;
|
||||
this.domainService = domainService;
|
||||
this.translatorConfig = translatorConfig;
|
||||
}
|
||||
|
||||
@@ -262,8 +263,11 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemResp> getDomainDataSetTree() {
|
||||
return schemaService.getDomainDataSetTree();
|
||||
public List<ItemResp> getDomainDataSetTree(User user) {
|
||||
List<Long> domainsWithAuth = domainService.getDomainAuthSet(user, AuthType.VIEWER).stream()
|
||||
.map(DomainResp::getId).toList();
|
||||
return schemaService.getDomainDataSetTree().stream()
|
||||
.filter(item -> domainsWithAuth.contains(item.getId())).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,6 +36,7 @@ public class ModelYamlManager {
|
||||
} else {
|
||||
dataModelYamlTpl.setTableQuery(modelDetail.getTableQuery());
|
||||
}
|
||||
dataModelYamlTpl.setFilterSql(modelDetail.getFilterSql());
|
||||
dataModelYamlTpl.setFields(modelResp.getModelDetail().getFields());
|
||||
dataModelYamlTpl.setId(modelResp.getId());
|
||||
return dataModelYamlTpl;
|
||||
|
||||
@@ -97,9 +97,11 @@ public class SemanticSchemaManager {
|
||||
modelDetail.setDbType(d.getType());
|
||||
modelDetail.setSqlQuery(d.getSqlQuery());
|
||||
modelDetail.setTableQuery(d.getTableQuery());
|
||||
modelDetail.setFilterSql(d.getFilterSql());
|
||||
modelDetail.getIdentifiers().addAll(getIdentify(d.getIdentifiers()));
|
||||
modelDetail.getMeasures().addAll(getMeasureParams(d.getMeasures()));
|
||||
modelDetail.getDimensions().addAll(getDimensions(d.getDimensions()));
|
||||
modelDetail.getFields().addAll(d.getFields());
|
||||
|
||||
return dataModel;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ public class LLMSemanticModeller implements SemanticModeller {
|
||||
if (!chatApp.isPresent() || !chatApp.get().isEnable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<DbSchema> otherDbSchema = getOtherDbSchema(dbSchema, dbSchemas);
|
||||
ModelSchemaExtractor extractor =
|
||||
AiServices.create(ModelSchemaExtractor.class, getChatModel(modelBuildReq));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.tencent.supersonic.headless.server.modeller;
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.ColumnSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.DbSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.ModelSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ModelBuildReq;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -16,19 +16,20 @@ public class RuleSemanticModeller implements SemanticModeller {
|
||||
@Override
|
||||
public void build(DbSchema dbSchema, List<DbSchema> dbSchemas, ModelSchema modelSchema,
|
||||
ModelBuildReq modelBuildReq) {
|
||||
List<ColumnSchema> columnSchemas =
|
||||
List<SemanticColumn> semanticColumns =
|
||||
dbSchema.getDbColumns().stream().map(this::convert).collect(Collectors.toList());
|
||||
modelSchema.setColumnSchemas(columnSchemas);
|
||||
modelSchema.setSemanticColumns(semanticColumns);
|
||||
}
|
||||
|
||||
private ColumnSchema convert(DBColumn dbColumn) {
|
||||
ColumnSchema columnSchema = new ColumnSchema();
|
||||
columnSchema.setName(dbColumn.getColumnName());
|
||||
columnSchema.setColumnName(dbColumn.getColumnName());
|
||||
columnSchema.setComment(dbColumn.getComment());
|
||||
columnSchema.setDataType(dbColumn.getDataType());
|
||||
columnSchema.setFiledType(dbColumn.getFieldType());
|
||||
return columnSchema;
|
||||
private SemanticColumn convert(DBColumn dbColumn) {
|
||||
SemanticColumn semanticColumn = new SemanticColumn();
|
||||
semanticColumn.setName(dbColumn.getColumnName());
|
||||
semanticColumn.setColumnName(dbColumn.getColumnName());
|
||||
semanticColumn.setExpr(dbColumn.getColumnName());
|
||||
semanticColumn.setComment(dbColumn.getComment());
|
||||
semanticColumn.setDataType(dbColumn.getDataType());
|
||||
semanticColumn.setFiledType(dbColumn.getFieldType());
|
||||
return semanticColumn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import com.tencent.supersonic.headless.api.pojo.request.ModelBuildReq;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A semantic modeler builds semantic-layer schemas from database-layer schemas.
|
||||
*/
|
||||
public interface SemanticModeller {
|
||||
|
||||
void build(DbSchema dbSchema, List<DbSchema> otherDbSchema, ModelSchema modelSchema,
|
||||
|
||||
@@ -44,6 +44,8 @@ public class DatabaseDO {
|
||||
/** */
|
||||
private String viewer;
|
||||
|
||||
private Integer isOpen = 0;
|
||||
|
||||
/** 配置信息 */
|
||||
private String config;
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public class DataModelYamlTpl {
|
||||
|
||||
private String tableQuery;
|
||||
|
||||
private String filterSql;
|
||||
|
||||
private List<IdentifyYamlTpl> identifiers;
|
||||
|
||||
private List<DimensionYamlTpl> dimensions;
|
||||
|
||||
@@ -52,8 +52,10 @@ public class ChatModelController {
|
||||
}
|
||||
|
||||
@RequestMapping("/getModelList")
|
||||
public List<ChatModel> getModelList() {
|
||||
return chatModelService.getChatModels();
|
||||
public List<ChatModel> getModelList(HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
User user = UserHolder.findUser(httpServletRequest, httpServletResponse);
|
||||
return chatModelService.getChatModels(user);
|
||||
}
|
||||
|
||||
@RequestMapping("/getModelAppList")
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.server.rest;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.common.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetaFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.DataSetReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DataSetResp;
|
||||
@@ -51,6 +52,7 @@ public class DataSetController {
|
||||
public List<DataSetResp> getDataSetList(@RequestParam("domainId") Long domainId) {
|
||||
MetaFilter metaFilter = new MetaFilter();
|
||||
metaFilter.setDomainId(domainId);
|
||||
metaFilter.setStatus(StatusEnum.ONLINE.getCode());
|
||||
return dataSetService.getDataSetList(metaFilter);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,11 @@ package com.tencent.supersonic.headless.server.service;
|
||||
import com.tencent.supersonic.common.pojo.ItemDateResp;
|
||||
import com.tencent.supersonic.common.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.headless.api.pojo.Dimension;
|
||||
import com.tencent.supersonic.headless.api.pojo.ItemDateFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetaFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.ModelSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.FieldRemovedReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ModelBuildReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ModelReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.*;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.UnAvailableItemResp;
|
||||
@@ -54,4 +52,6 @@ public interface ModelService {
|
||||
DatabaseResp getDatabaseByModelId(Long modelId);
|
||||
|
||||
void batchUpdateStatus(MetaBatchReq metaBatchReq, User user);
|
||||
|
||||
Dimension updateDimension(DimensionReq dimensionReq, User user);
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ public class DataSetServiceImpl extends ServiceImpl<DataSetDOMapper, DataSetDO>
|
||||
public DataSetResp save(DataSetReq dataSetReq, User user) {
|
||||
dataSetReq.createdBy(user.getName());
|
||||
DataSetDO dataSetDO = convert(dataSetReq);
|
||||
dataSetDO.setStatus(StatusEnum.ONLINE.getCode());
|
||||
dataSetDO.setStatus(dataSetReq.getStatus() != null ? dataSetReq.getStatus()
|
||||
: StatusEnum.ONLINE.getCode());
|
||||
DataSetResp dataSetResp = convert(dataSetDO);
|
||||
// conflictCheck(dataSetResp);
|
||||
save(dataSetDO);
|
||||
dataSetResp.setId(dataSetDO.getId());
|
||||
return dataSetResp;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||
import com.tencent.supersonic.common.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
||||
import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
||||
@@ -79,8 +80,9 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
||||
|
||||
@Override
|
||||
public List<DatabaseResp> getDatabaseList(User user) {
|
||||
List<DatabaseResp> databaseResps =
|
||||
list().stream().map(DatabaseConverter::convert).collect(Collectors.toList());
|
||||
List<DatabaseResp> databaseResps = list().stream().map(DatabaseConverter::convert)
|
||||
.filter(database -> filterByAuth(database, user, AuthType.VIEWER))
|
||||
.collect(Collectors.toList());
|
||||
fillPermission(databaseResps, user);
|
||||
return databaseResps;
|
||||
}
|
||||
@@ -94,12 +96,50 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
||||
databaseResp.setHasEditPermission(true);
|
||||
databaseResp.setHasUsePermission(true);
|
||||
}
|
||||
if (databaseResp.getViewers().contains(user.getName())) {
|
||||
if (databaseResp.getViewers().contains(user.getName()) || databaseResp.isPublic()) {
|
||||
databaseResp.setHasUsePermission(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean filterByAuth(DatabaseResp database, User user, AuthType authType) {
|
||||
if (database.isPublic() || user.isSuperAdmin()
|
||||
|| user.getName().equals(database.getCreatedBy())) {
|
||||
return true;
|
||||
}
|
||||
authType = authType == null ? AuthType.VIEWER : authType;
|
||||
switch (authType) {
|
||||
case ADMIN:
|
||||
return checkAdminPermission(user, database);
|
||||
case VIEWER:
|
||||
default:
|
||||
return checkViewPermission(user, database);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAdminPermission(User user, DatabaseResp database) {
|
||||
List<String> admins = database.getAdmins();
|
||||
if (user.isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
if (admins.contains(user.getName()) || database.getCreatedBy().equals(user.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkViewPermission(User user, DatabaseResp database) {
|
||||
if (checkAdminPermission(user, database)) {
|
||||
return true;
|
||||
}
|
||||
List<String> viewers = database.getViewers();
|
||||
|
||||
if (viewers.contains(user.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDatabase(Long databaseId) {
|
||||
ModelFilter modelFilter = new ModelFilter();
|
||||
|
||||
@@ -84,6 +84,10 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
|
||||
DimensionDO dimensionDO = DimensionConverter.convert2DimensionDO(dimensionReq);
|
||||
dimensionRepository.createDimension(dimensionDO);
|
||||
sendEventBatch(Lists.newArrayList(dimensionDO), EventType.ADD);
|
||||
|
||||
// should update modelDetail
|
||||
modelService.updateDimension(dimensionReq, user);
|
||||
|
||||
return DimensionConverter.convert2DimensionResp(dimensionDO);
|
||||
}
|
||||
|
||||
@@ -136,6 +140,9 @@ public class DimensionServiceImpl extends ServiceImpl<DimensionDOMapper, Dimensi
|
||||
String oldName = dimensionDO.getName();
|
||||
DimensionConverter.convert(dimensionDO, dimensionReq);
|
||||
dimensionRepository.updateDimension(dimensionDO);
|
||||
// should update modelDetail as well
|
||||
modelService.updateDimension(dimensionReq, user);
|
||||
|
||||
if (!oldName.equals(dimensionDO.getName())) {
|
||||
sendEvent(getDataItem(dimensionDO), EventType.UPDATE);
|
||||
}
|
||||
|
||||
@@ -2,52 +2,24 @@ package com.tencent.supersonic.headless.server.service.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.auth.api.authentication.service.UserService;
|
||||
import com.tencent.supersonic.common.pojo.DataEvent;
|
||||
import com.tencent.supersonic.common.pojo.DataItem;
|
||||
import com.tencent.supersonic.common.pojo.ItemDateResp;
|
||||
import com.tencent.supersonic.common.pojo.ModelRela;
|
||||
import com.tencent.supersonic.common.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.*;
|
||||
import com.tencent.supersonic.common.pojo.enums.AuthType;
|
||||
import com.tencent.supersonic.common.pojo.enums.EventType;
|
||||
import com.tencent.supersonic.common.pojo.enums.StatusEnum;
|
||||
import com.tencent.supersonic.common.pojo.enums.TypeEnums;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.DbSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.Dimension;
|
||||
import com.tencent.supersonic.headless.api.pojo.Identify;
|
||||
import com.tencent.supersonic.headless.api.pojo.ItemDateFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.Measure;
|
||||
import com.tencent.supersonic.headless.api.pojo.MetaFilter;
|
||||
import com.tencent.supersonic.headless.api.pojo.ModelSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.DateInfoReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.DimensionReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.FieldRemovedReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.MetricReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ModelBuildReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ModelReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DataSetResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DimensionResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.DomainResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.MetricResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.UnAvailableItemResp;
|
||||
import com.tencent.supersonic.headless.api.pojo.*;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.DimensionType;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.*;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.*;
|
||||
import com.tencent.supersonic.headless.server.modeller.SemanticModeller;
|
||||
import com.tencent.supersonic.headless.server.persistence.dataobject.DateInfoDO;
|
||||
import com.tencent.supersonic.headless.server.persistence.dataobject.ModelDO;
|
||||
import com.tencent.supersonic.headless.server.persistence.repository.DateInfoRepository;
|
||||
import com.tencent.supersonic.headless.server.persistence.repository.ModelRepository;
|
||||
import com.tencent.supersonic.headless.server.pojo.ModelFilter;
|
||||
import com.tencent.supersonic.headless.server.service.DataSetService;
|
||||
import com.tencent.supersonic.headless.server.service.DatabaseService;
|
||||
import com.tencent.supersonic.headless.server.service.DimensionService;
|
||||
import com.tencent.supersonic.headless.server.service.DomainService;
|
||||
import com.tencent.supersonic.headless.server.service.MetricService;
|
||||
import com.tencent.supersonic.headless.server.service.ModelRelaService;
|
||||
import com.tencent.supersonic.headless.server.service.ModelService;
|
||||
import com.tencent.supersonic.headless.server.service.*;
|
||||
import com.tencent.supersonic.headless.server.utils.CoreComponentFactory;
|
||||
import com.tencent.supersonic.headless.server.utils.ModelConverter;
|
||||
import com.tencent.supersonic.headless.server.utils.NameCheckUtils;
|
||||
@@ -62,12 +34,7 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -277,8 +244,8 @@ public class ModelServiceImpl implements ModelService {
|
||||
dimensionService.createDimensionBatch(dimensionReqs, user);
|
||||
}
|
||||
|
||||
private void batchCreateMetric(ModelDO datasourceDO, User user) throws Exception {
|
||||
List<MetricReq> metricReqs = ModelConverter.convertMetricList(datasourceDO);
|
||||
private void batchCreateMetric(ModelDO modelDO, User user) throws Exception {
|
||||
List<MetricReq> metricReqs = ModelConverter.convertMetricList(modelDO);
|
||||
metricService.createMetricBatch(metricReqs, user);
|
||||
}
|
||||
|
||||
@@ -553,6 +520,35 @@ public class ModelServiceImpl implements ModelService {
|
||||
modelRepository.batchUpdate(modelDOS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension updateDimension(DimensionReq dimensionReq, User user) {
|
||||
ModelDO modelDO = getModelDO(dimensionReq.getModelId());
|
||||
ModelDetail modelDetail = JsonUtil.toObject(modelDO.getModelDetail(), ModelDetail.class);
|
||||
Optional<Dimension> dimOptional = modelDetail.getDimensions().stream()
|
||||
.filter(dimension -> dimension.getBizName().equals(dimensionReq.getBizName()))
|
||||
.findFirst();
|
||||
Dimension result;
|
||||
if (dimOptional.isPresent()) {
|
||||
Dimension dimension = dimOptional.get();
|
||||
dimension.setExpr(dimensionReq.getExpr());
|
||||
dimension.setName(dimensionReq.getName());
|
||||
dimension.setType(DimensionType.valueOf(dimensionReq.getType()));
|
||||
dimension.setDescription(dimensionReq.getDescription());
|
||||
result = dimension;
|
||||
} else {
|
||||
Dimension dimension = Dimension.builder().name(dimensionReq.getName())
|
||||
.bizName(dimensionReq.getBizName()).expr(dimensionReq.getExpr())
|
||||
.type(DimensionType.valueOf(dimensionReq.getType()))
|
||||
.description(dimensionReq.getDescription()).build();
|
||||
modelDetail.getDimensions().add(dimension);
|
||||
result = dimension;
|
||||
}
|
||||
|
||||
modelDO.setModelDetail(JsonUtil.toString(modelDetail));
|
||||
modelRepository.updateModel(modelDO);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected ModelDO getModelDO(Long id) {
|
||||
return modelRepository.getModelById(id);
|
||||
}
|
||||
|
||||
@@ -425,8 +425,12 @@ public class DictUtils {
|
||||
.format(DateTimeFormatter.ofPattern(format));
|
||||
String end = LocalDate.now().minusDays(itemValueDateEnd)
|
||||
.format(DateTimeFormatter.ofPattern(format));
|
||||
return String.format("( %s >= '%s' and %s <= '%s' )", dateConf.getDateField(), start,
|
||||
dateConf.getDateField(), end);
|
||||
if (Objects.nonNull(dateConf)) {
|
||||
return String.format("( %s >= '%s' and %s <= '%s' )", dateConf.getDateField(), start,
|
||||
dateConf.getDateField(), end);
|
||||
} else {
|
||||
return String.format("( %s >= '%s' and %s <= '%s' )", "dt", start, "dt", end);
|
||||
}
|
||||
}
|
||||
|
||||
private String generateDictDateFilter(DictItemResp dictItemResp) {
|
||||
@@ -440,7 +444,7 @@ public class DictUtils {
|
||||
}
|
||||
// 未进行设置
|
||||
if (Objects.isNull(config) || Objects.isNull(config.getDateConf())) {
|
||||
return defaultDateFilter(config.getDateConf());
|
||||
return defaultDateFilter(null);
|
||||
}
|
||||
// 全表扫描
|
||||
if (DateConf.DateMode.ALL.equals(config.getDateConf().getDateMode())) {
|
||||
|
||||
@@ -157,23 +157,29 @@ public class ModelConverter {
|
||||
modelDetail.setQueryType(ModelDefineType.TABLE_QUERY.getName());
|
||||
modelDetail.setTableQuery(String.format("%s.%s", modelBuildReq.getDb(), tableName));
|
||||
}
|
||||
for (ColumnSchema columnSchema : modelSchema.getColumnSchemas()) {
|
||||
FieldType fieldType = columnSchema.getFiledType();
|
||||
List<Field> fields = new ArrayList<>();
|
||||
for (SemanticColumn semanticColumn : modelSchema.getSemanticColumns()) {
|
||||
FieldType fieldType = semanticColumn.getFiledType();
|
||||
fields.add(new Field(semanticColumn.getName(), semanticColumn.getDataType()));
|
||||
|
||||
if (getIdentifyType(fieldType) != null) {
|
||||
Identify identify = new Identify(columnSchema.getName(),
|
||||
getIdentifyType(fieldType).name(), columnSchema.getColumnName(), 1);
|
||||
Identify identify = new Identify(semanticColumn.getName(),
|
||||
getIdentifyType(fieldType).name(), semanticColumn.getColumnName(), 1);
|
||||
modelDetail.getIdentifiers().add(identify);
|
||||
} else if (FieldType.measure.equals(fieldType)) {
|
||||
Measure measure = new Measure(columnSchema.getName(), columnSchema.getColumnName(),
|
||||
columnSchema.getColumnName(), columnSchema.getAgg().getOperator(), 1);
|
||||
Measure measure = new Measure(semanticColumn.getName(),
|
||||
semanticColumn.getColumnName(), semanticColumn.getExpr(),
|
||||
semanticColumn.getAgg().getOperator(), semanticColumn.getUnit(), 1);
|
||||
modelDetail.getMeasures().add(measure);
|
||||
} else {
|
||||
Dimension dim = new Dimension(columnSchema.getName(), columnSchema.getColumnName(),
|
||||
columnSchema.getColumnName(),
|
||||
DimensionType.valueOf(columnSchema.getFiledType().name()), 1);
|
||||
Dimension dim = new Dimension(semanticColumn.getName(),
|
||||
semanticColumn.getColumnName(), semanticColumn.getExpr(),
|
||||
DimensionType.valueOf(semanticColumn.getFiledType().name()), 1);
|
||||
modelDetail.getDimensions().add(dim);
|
||||
}
|
||||
}
|
||||
modelDetail.setFields(fields);
|
||||
modelDetail.setFilterSql(modelBuildReq.getFilterSql());
|
||||
modelReq.setModelDetail(modelDetail);
|
||||
return modelReq;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,19 @@ public class SqlVariableParseUtilsTest {
|
||||
Assertions.assertEquals(expectedSql, actualSql);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParseSql_if() {
|
||||
String sql =
|
||||
"select * from t_$interval$ where id = $id$ $if(name)$and name = $name$$endif$";
|
||||
List<SqlVariable> variables = Lists.newArrayList(mockNumSqlVariable(),
|
||||
mockExprSqlVariable(), mockStrSqlVariable());
|
||||
List<Param> params =
|
||||
Lists.newArrayList(mockIdParam(), mockNameParam(), mockIntervalParam());
|
||||
String actualSql = SqlVariableParseUtils.parse(sql, variables, params);
|
||||
String expectedSql = "select * from t_wk where id = 2 and name = 'alice'";
|
||||
Assertions.assertEquals(expectedSql, actualSql);
|
||||
}
|
||||
|
||||
private SqlVariable mockNumSqlVariable() {
|
||||
return mockSqlVariable("id", VariableValueType.NUMBER, 1);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public abstract class S2BaseDemo implements CommandLineRunner {
|
||||
}
|
||||
|
||||
protected ChatModel addChatModelIfNotExist() {
|
||||
List<ChatModel> chatModels = chatModelService.getChatModels();
|
||||
List<ChatModel> chatModels = chatModelService.getChatModels(defaultUser);
|
||||
if (!chatModels.isEmpty()) {
|
||||
return chatModels.get(0);
|
||||
} else {
|
||||
|
||||
@@ -333,7 +333,6 @@ public class S2VisitsDemo extends S2BaseDemo {
|
||||
metricReq.setSensitiveLevel(SensitiveLevelEnum.HIGH.getCode());
|
||||
metricReq.setDescription("每个用户平均访问的次数");
|
||||
metricReq.setClassifications(Collections.singletonList("核心指标"));
|
||||
metricReq.setAlias("平均访问次数");
|
||||
MetricDefineByMetricParams metricTypeParams = new MetricDefineByMetricParams();
|
||||
metricTypeParams.setExpr("pv/uv");
|
||||
List<MetricParam> metrics = new ArrayList<>();
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: org.postgresql.Driver
|
||||
url: jdbc:postgresql://${DB_HOST}:${DB_PORT:5432}/${DB_NAME}?stringtype=unspecified
|
||||
username: ${DB_USERNAME}
|
||||
password: ${DB_PASSWORD}
|
||||
sql:
|
||||
init:
|
||||
continue-on-error: true
|
||||
mode: always
|
||||
username: ${DB_USERNAME}
|
||||
password: ${DB_PASSWORD}
|
||||
schema-locations: classpath:db/schema-postgres.sql,classpath:db/schema-postgres-demo.sql
|
||||
data-locations: classpath:db/data-postgres.sql,classpath:db/data-postgres-demo.sql
|
||||
|
||||
s2:
|
||||
embedding:
|
||||
store:
|
||||
provider: PGVECTOR
|
||||
base:
|
||||
url: ${DB_HOST}
|
||||
port: ${DB_PORT:5432}
|
||||
databaseName: ${DB_NAME}
|
||||
user: ${DB_USERNAME}
|
||||
password: ${DB_PASSWORD}
|
||||
dimension: 512
|
||||
@@ -410,4 +410,11 @@ ALTER TABLE s2_query_stat_info RENAME COLUMN `sql` TO `query_sql`;
|
||||
--20250224
|
||||
ALTER TABLE s2_agent add column `admin_org` varchar(3000) DEFAULT NULL COMMENT '管理员组织';
|
||||
ALTER TABLE s2_agent add column `view_org` varchar(3000) DEFAULT NULL COMMENT '可用组织';
|
||||
ALTER TABLE s2_agent add column `is_open` tinyint DEFAULT NULL COMMENT '是否公开';
|
||||
ALTER TABLE s2_agent add column `is_open` tinyint DEFAULT NULL COMMENT '是否公开';
|
||||
|
||||
--20250309
|
||||
ALTER TABLE s2_model_rela alter column join_condition type text;
|
||||
|
||||
--20250310
|
||||
ALTER TABLE s2_chat_model add column is_open tinyint DEFAULT NULL COMMENT '是否公开';
|
||||
ALTER TABLE s2_database add column is_open tinyint DEFAULT NULL COMMENT '是否公开';
|
||||
@@ -116,6 +116,7 @@ CREATE TABLE IF NOT EXISTS `s2_chat_model`
|
||||
`updated_by` varchar(100) NOT NULL,
|
||||
`admin` varchar(500) NOT NULL,
|
||||
`viewer` varchar(500) DEFAULT NULL,
|
||||
`is_open` TINYINT DEFAULT NULL , -- whether public
|
||||
PRIMARY KEY (`id`)
|
||||
); COMMENT ON TABLE s2_chat_model IS 'chat model table';
|
||||
|
||||
@@ -197,6 +198,7 @@ CREATE TABLE IF NOT EXISTS `s2_database` (
|
||||
`updated_by` varchar(100) NOT NULL,
|
||||
`admin` varchar(500) NOT NULL,
|
||||
`viewer` varchar(500) DEFAULT NULL,
|
||||
`is_open` TINYINT DEFAULT NULL , -- whether public
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
COMMENT ON TABLE s2_database IS 'database instance table';
|
||||
@@ -268,7 +270,7 @@ CREATE TABLE IF NOT EXISTS s2_model_rela
|
||||
from_model_id BIGINT,
|
||||
to_model_id BIGINT,
|
||||
join_type VARCHAR(255),
|
||||
join_condition VARCHAR(255),
|
||||
join_condition TEXT,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
@@ -379,7 +381,7 @@ CREATE TABLE IF NOT EXISTS s2_agent
|
||||
enable_feedback int null,
|
||||
`admin` varchar(3000) DEFAULT NULL , -- administrator
|
||||
`admin_org` varchar(3000) DEFAULT NULL , -- administrators organization
|
||||
`is_open` TINYINT DEFAULT NULL , -- whether the public
|
||||
`is_open` TINYINT DEFAULT NULL , -- whether public
|
||||
`viewer` varchar(3000) DEFAULT NULL , -- available users
|
||||
`view_org` varchar(3000) DEFAULT NULL , -- available organization
|
||||
PRIMARY KEY (`id`)
|
||||
|
||||
@@ -161,6 +161,7 @@ CREATE TABLE IF NOT EXISTS `s2_chat_model` (
|
||||
`updated_by` varchar(100) NOT NULL COMMENT '更新人',
|
||||
`admin` varchar(500) DEFAULT NULL,
|
||||
`viewer` varchar(500) DEFAULT NULL,
|
||||
`is_open` tinyint DEFAULT NULL COMMENT '是否公开',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='对话大模型实例表';
|
||||
|
||||
@@ -177,6 +178,7 @@ CREATE TABLE IF NOT EXISTS `s2_database` (
|
||||
`updated_by` varchar(100) NOT NULL COMMENT '更新人',
|
||||
`admin` varchar(500) DEFAULT NULL,
|
||||
`viewer` varchar(500) DEFAULT NULL,
|
||||
`is_open` tinyint DEFAULT NULL COMMENT '是否公开',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='数据库实例表';
|
||||
|
||||
@@ -404,7 +406,7 @@ CREATE TABLE IF NOT EXISTS s2_model_rela
|
||||
from_model_id bigint,
|
||||
to_model_id bigint,
|
||||
join_type VARCHAR(255),
|
||||
join_condition VARCHAR(255)
|
||||
join_condition text
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `s2_collect` (
|
||||
|
||||
@@ -147,7 +147,8 @@ CREATE TABLE IF NOT EXISTS s2_chat_model (
|
||||
updated_at timestamp NOT NULL,
|
||||
updated_by varchar(100) NOT NULL,
|
||||
admin varchar(500) DEFAULT NULL,
|
||||
viewer varchar(500) DEFAULT NULL
|
||||
viewer varchar(500) DEFAULT NULL,
|
||||
is_open smallint DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS s2_database (
|
||||
@@ -162,7 +163,8 @@ CREATE TABLE IF NOT EXISTS s2_database (
|
||||
updated_at timestamp NOT NULL,
|
||||
updated_by varchar(100) NOT NULL,
|
||||
admin varchar(500) DEFAULT NULL,
|
||||
viewer varchar(500) DEFAULT NULL
|
||||
viewer varchar(500) DEFAULT NULL,
|
||||
is_open smallint DEFAULT NULL
|
||||
);
|
||||
|
||||
|
||||
@@ -465,7 +467,7 @@ CREATE TABLE IF NOT EXISTS s2_model_rela (
|
||||
from_model_id bigint,
|
||||
to_model_id bigint,
|
||||
join_type VARCHAR(255),
|
||||
join_condition VARCHAR(255)
|
||||
join_condition text
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS s2_collect (
|
||||
|
||||
@@ -155,16 +155,6 @@ public class Text2SQLEval extends BaseTest {
|
||||
assert result.getTextResult().contains("3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_detail_query() throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
QueryResult result = submitNewChat("特斯拉旗下有哪些品牌", agent.getId());
|
||||
durations.add(System.currentTimeMillis() - start);
|
||||
assert result.getQueryColumns().size() >= 1;
|
||||
assert result.getTextResult().contains("Model Y");
|
||||
assert result.getTextResult().contains("Model 3");
|
||||
}
|
||||
|
||||
public Agent getLLMAgent() {
|
||||
Agent agent = new Agent();
|
||||
agent.setName("Agent for Test");
|
||||
|
||||
@@ -39,14 +39,14 @@ public class SemanticModellerTest extends BaseTest {
|
||||
Map<String, ModelSchema> modelSchemaMap = modelService.buildModelSchema(modelSchemaReq);
|
||||
|
||||
ModelSchema userModelSchema = modelSchemaMap.get("s2_user_department");
|
||||
Assertions.assertEquals(2, userModelSchema.getColumnSchemas().size());
|
||||
Assertions.assertEquals(2, userModelSchema.getSemanticColumns().size());
|
||||
Assertions.assertEquals(FieldType.primary_key,
|
||||
userModelSchema.getColumnByName("user_name").getFiledType());
|
||||
Assertions.assertEquals(FieldType.categorical,
|
||||
userModelSchema.getColumnByName("department").getFiledType());
|
||||
|
||||
ModelSchema stayTimeModelSchema = modelSchemaMap.get("s2_stay_time_statis");
|
||||
Assertions.assertEquals(4, stayTimeModelSchema.getColumnSchemas().size());
|
||||
Assertions.assertEquals(4, stayTimeModelSchema.getSemanticColumns().size());
|
||||
Assertions.assertEquals(FieldType.foreign_key,
|
||||
stayTimeModelSchema.getColumnByName("user_name").getFiledType());
|
||||
Assertions.assertEquals(FieldType.partition_time,
|
||||
@@ -72,7 +72,7 @@ public class SemanticModellerTest extends BaseTest {
|
||||
Map<String, ModelSchema> modelSchemaMap = modelService.buildModelSchema(modelSchemaReq);
|
||||
|
||||
ModelSchema pvModelSchema = modelSchemaMap.values().iterator().next();
|
||||
Assertions.assertEquals(5, pvModelSchema.getColumnSchemas().size());
|
||||
Assertions.assertEquals(5, pvModelSchema.getSemanticColumns().size());
|
||||
Assertions.assertEquals(FieldType.partition_time,
|
||||
pvModelSchema.getColumnByName("imp_date").getFiledType());
|
||||
Assertions.assertEquals(FieldType.categorical,
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -26,7 +26,7 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<revision>0.9.10</revision>
|
||||
<revision>1.0.0-SNAPSHOT</revision>
|
||||
<java.source.version>21</java.source.version>
|
||||
<java.target.version>21</java.target.version>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Form, Button, Modal, Input } from 'antd';
|
||||
import { Form, Button, Modal, Input, message } from 'antd';
|
||||
|
||||
import type { RegisterFormDetail } from './types';
|
||||
|
||||
@@ -37,8 +37,9 @@ const RegisterForm: React.FC<RegisterFormProps> = (props) => {
|
||||
try {
|
||||
await handleUpdate(formValus);
|
||||
setSaveLoading(false);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
setSaveLoading(false);
|
||||
message.error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -41,8 +41,9 @@ const LoginPage: React.FC = () => {
|
||||
}
|
||||
history.push('/');
|
||||
return;
|
||||
} else {
|
||||
message.error(msg);
|
||||
}
|
||||
message.success(msg);
|
||||
};
|
||||
|
||||
// 处理登录按钮响应
|
||||
@@ -55,12 +56,14 @@ const LoginPage: React.FC = () => {
|
||||
// 处理注册弹窗确定按钮
|
||||
const handleRegister = async (values: RegisterFormDetail) => {
|
||||
const enCodeValues = { ...values, password: encryptPassword(values.password, encryptKey) };
|
||||
const { code } = await userRegister(enCodeValues);
|
||||
const { code, msg } = await userRegister(enCodeValues);
|
||||
if (code === 200) {
|
||||
message.success('注册成功');
|
||||
setCreateModalVisible(false);
|
||||
// 注册完自动帮用户登录
|
||||
await loginDone(enCodeValues);
|
||||
} else {
|
||||
message.error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import { isFunction } from 'lodash';
|
||||
import FullScreen from '@/components/FullScreen';
|
||||
import SqlEditor from '@/components/SqlEditor';
|
||||
import type { TaskResultItem, TaskResultColumn } from '../data';
|
||||
import { executeSql, listColumnsBySql } from '@/pages/SemanticModel/service';
|
||||
import { executeSql } from '@/pages/SemanticModel/service';
|
||||
|
||||
import SqlParams from './SqlParams';
|
||||
import styles from '../style.less';
|
||||
@@ -248,19 +248,12 @@ const SqlDetail: React.FC<IProps> = ({
|
||||
id: currentDatabaseItem.key,
|
||||
sqlVariables: sqlParams,
|
||||
});
|
||||
|
||||
const { code: getColumnCode, data: getColumnData } = await listColumnsBySql({
|
||||
sql: value,
|
||||
databaseId: currentDatabaseItem.key,
|
||||
});
|
||||
|
||||
setResultTableLoading(false);
|
||||
if (code === 200 && getColumnCode === 200) {
|
||||
const columnData = getColumnData.map((item) => {
|
||||
if (code === 200) {
|
||||
const columnData = (data.columns || []).map((item: any) => {
|
||||
return {
|
||||
...item,
|
||||
nameEn: item.columnName,
|
||||
type: item.dataType,
|
||||
columnName: item.nameEn,
|
||||
};
|
||||
});
|
||||
fetchTaskResult(data, columnData);
|
||||
|
||||
@@ -107,20 +107,8 @@ const MetricDetail: React.FC<Props> = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Helmet
|
||||
title={`${metircData?.id ? `[指标]${metircData?.name}-${BASE_TITLE}` : '新建指标'}`}
|
||||
/>
|
||||
<div className={styles.metricDetailWrapper}>
|
||||
<div className={styles.metricDetail}>
|
||||
<div className={styles.siderContainer}>
|
||||
<MetricInfoSider
|
||||
relationDimensionOptions={relationDimensionOptions}
|
||||
metircData={metircData}
|
||||
onDimensionRelationBtnClick={() => {
|
||||
setMetricRelationModalOpenState(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.tabContainer}>
|
||||
<Tabs
|
||||
defaultActiveKey="metricCaliberInput"
|
||||
@@ -146,6 +134,15 @@ const MetricDetail: React.FC<Props> = () => {
|
||||
className={styles.metricDetailTab}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.siderContainer}>
|
||||
<MetricInfoSider
|
||||
relationDimensionOptions={relationDimensionOptions}
|
||||
metircData={metircData}
|
||||
onDimensionRelationBtnClick={() => {
|
||||
setMetricRelationModalOpenState(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DimensionAndMetricRelationModal
|
||||
metricItem={metircData}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
.metricWrapper {
|
||||
width: 100%;
|
||||
margin-left: auto;
|
||||
@@ -12,7 +11,6 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
|
||||
.metricFilterWrapper {
|
||||
margin: 20px;
|
||||
padding: 20px;
|
||||
@@ -183,7 +181,68 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.metricEditWrapper {
|
||||
.metricDetailTab {
|
||||
:global {
|
||||
.ant-tabs-nav {
|
||||
margin: 10px 20px 0 20px;
|
||||
padding: 0 20px;
|
||||
background-color: rgb(255, 255, 255);
|
||||
border-radius: 8px;
|
||||
transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
||||
}
|
||||
.ant-tabs-tab {
|
||||
padding: 12px 0;
|
||||
color: #344767;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
.metricDetail {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
background-color: transparent;
|
||||
height: 100%;
|
||||
.tabContainer {
|
||||
padding: 24px;
|
||||
min-height: calc(100vh - 78px);
|
||||
width: calc(100vw - 350px);
|
||||
background-color: #fafafb;
|
||||
}
|
||||
.metricInfoContent {
|
||||
padding: 25px;
|
||||
.title {
|
||||
position: relative;
|
||||
margin-bottom: 12px;
|
||||
color: #0e73ff;
|
||||
font-weight: bold;
|
||||
font-size: 16px;
|
||||
&::before {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: -10px;
|
||||
display: block;
|
||||
width: 3px;
|
||||
height: 14px;
|
||||
font-size: 0;
|
||||
background: #0e73ff;
|
||||
border: 1px solid #0e73ff;
|
||||
border-radius: 2px;
|
||||
content: '';
|
||||
}
|
||||
}
|
||||
}
|
||||
.siderContainer {
|
||||
width: 350px;
|
||||
min-height: calc(100vh - 78px);
|
||||
border-radius: 6px;
|
||||
padding: 24px 0 24px 24px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.metricDetailWrapper {
|
||||
height: calc(100vh - 56px);
|
||||
@@ -215,8 +274,7 @@
|
||||
.tabContainer {
|
||||
height: 100%;
|
||||
min-height: calc(100vh - 78px);
|
||||
// width: calc(100vw - 450px);
|
||||
width: 100%;
|
||||
width: calc(100vw - 450px);
|
||||
background-color: #fafafb;
|
||||
}
|
||||
.metricInfoContent {
|
||||
@@ -245,8 +303,9 @@
|
||||
.siderContainer {
|
||||
width: 450px;
|
||||
min-height: calc(100vh - 78px);
|
||||
margin: 10px 20px 20px 0;
|
||||
background-color: rgb(255, 255, 255);
|
||||
border-radius: 6px;
|
||||
padding: 10px 0 24px 24px;
|
||||
box-shadow: rgba(0, 0, 0, 0.08) 6px 0px 16px 0px, rgba(0, 0, 0, 0.12) 3px 0px 6px -4px,
|
||||
rgba(0, 0, 0, 0.05) 9px 0px 28px 8px;
|
||||
}
|
||||
@@ -265,5 +324,260 @@
|
||||
transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
||||
}
|
||||
|
||||
.metricInfoSider {
|
||||
padding: 20px;
|
||||
color: #344767;
|
||||
background-color: #fff;
|
||||
height: 100%;
|
||||
border: 1px solid #e6ebf1;
|
||||
border-radius: 6px;
|
||||
.createTitle {
|
||||
margin-bottom: 10px;
|
||||
color: #344767;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
font-family: var(--tencent-font-family);
|
||||
}
|
||||
.gotoMetricListIcon {
|
||||
color: #3182ce;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: #5493ff;
|
||||
}
|
||||
}
|
||||
.title {
|
||||
margin-bottom: 20px;
|
||||
.name {
|
||||
font-weight: 600;
|
||||
font-size: 18px;
|
||||
}
|
||||
.bizName {
|
||||
margin: 5px 0 0 25px;
|
||||
color: #7b809a;
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
.desc {
|
||||
display: block;
|
||||
margin-top: 8px;
|
||||
color: #7b809a;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
line-height: 1.9;
|
||||
}
|
||||
.subTitle {
|
||||
margin: 0px;
|
||||
color: rgb(123, 128, 154);
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
line-height: 1.25;
|
||||
letter-spacing: 0.03333em;
|
||||
text-transform: uppercase;
|
||||
text-decoration: none;
|
||||
vertical-align: unset;
|
||||
opacity: 1;
|
||||
}
|
||||
.sectionContainer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: scroll;
|
||||
|
||||
overflow: hidden;
|
||||
background-image: none;
|
||||
border-radius: 6px;
|
||||
.section {
|
||||
padding: 16px;
|
||||
color: rgb(52, 71, 103);
|
||||
line-height: 1.25;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
opacity: 1;
|
||||
.sectionTitleBox {
|
||||
padding: 8px 0;
|
||||
color: rgb(52, 71, 103);
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
opacity: 1;
|
||||
.sectionTitle {
|
||||
margin: 0px;
|
||||
color: rgb(52, 71, 103);
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
line-height: 1.625;
|
||||
letter-spacing: 0.0075em;
|
||||
text-transform: capitalize;
|
||||
text-decoration: none;
|
||||
vertical-align: unset;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.item {
|
||||
display: flex;
|
||||
padding-top: 8px;
|
||||
padding-right: 16px;
|
||||
padding-bottom: 8px;
|
||||
color: rgb(52, 71, 103);
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
opacity: 1;
|
||||
.itemLable {
|
||||
min-width: fit-content;
|
||||
margin: 0px;
|
||||
margin-right: 10px;
|
||||
color: #344767;
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: 0.02857em;
|
||||
text-transform: capitalize;
|
||||
text-decoration: none;
|
||||
vertical-align: unset;
|
||||
opacity: 1;
|
||||
}
|
||||
.itemValue {
|
||||
margin: 0px;
|
||||
color: #7b809a;
|
||||
font-weight: 400;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: 0.02857em;
|
||||
text-transform: none;
|
||||
text-decoration: none;
|
||||
vertical-align: unset;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
.hr {
|
||||
flex-shrink: 0;
|
||||
margin: 0px;
|
||||
border-color: rgb(242, 244, 247);
|
||||
// border-width: 0px 0px thin;
|
||||
border-style: solid;
|
||||
}
|
||||
.ctrlBox {
|
||||
.ctrlList {
|
||||
position: relative;
|
||||
margin: 0px;
|
||||
padding: 8px 0px;
|
||||
list-style: none;
|
||||
background-color: rgb(249, 250, 251);
|
||||
li {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
box-sizing: border-box;
|
||||
min-width: 0px;
|
||||
margin: 4px;
|
||||
padding: 4px 16px;
|
||||
color: inherit;
|
||||
text-align: left;
|
||||
text-decoration: none;
|
||||
vertical-align: middle;
|
||||
background-color: transparent;
|
||||
border: 0px;
|
||||
border-radius: 0px;
|
||||
outline: 0px;
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
||||
appearance: none;
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
-webkit-box-flex: 1;
|
||||
-webkit-box-pack: start;
|
||||
-webkit-box-align: center;
|
||||
&:hover {
|
||||
color: #3182ce;
|
||||
text-decoration: none;
|
||||
background-color: rgba(16, 24, 40, 0.04);
|
||||
}
|
||||
}
|
||||
.ctrlItemIcon {
|
||||
flex-shrink: 0;
|
||||
min-width: unset;
|
||||
margin-right: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.styles.ctrlItemLable {
|
||||
display: block;
|
||||
margin: 0px;
|
||||
font-weight: 400;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.settingList {
|
||||
list-style: none;
|
||||
margin: 0px;
|
||||
position: relative;
|
||||
padding: 0px;
|
||||
li {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
background-color: transparent;
|
||||
outline: 0px;
|
||||
border: 0px;
|
||||
margin: 0px;
|
||||
border-radius: 0px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
vertical-align: middle;
|
||||
appearance: none;
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
text-decoration: none;
|
||||
min-width: 0px;
|
||||
box-sizing: border-box;
|
||||
text-align: left;
|
||||
padding: 8px 16px;
|
||||
transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
||||
&.active {
|
||||
background-color: rgba(22, 119, 255, 0.08);
|
||||
.icon {
|
||||
color: rgb(22, 119, 255);
|
||||
}
|
||||
.content {
|
||||
.text {
|
||||
color: rgb(22, 119, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
.icon {
|
||||
min-width: 32px;
|
||||
color: #344767;
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
}
|
||||
.content {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0px;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 4px;
|
||||
.text {
|
||||
margin: 0px;
|
||||
color: #344767;
|
||||
font-size: 16px;
|
||||
// line-height: 1.57;
|
||||
// font-family: var(--tencent-font-family);
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
background-color: rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ const DatasetCreateForm: React.FC<ModelCreateFormModalProps> = forwardRef(
|
||||
setSaveLoading(false);
|
||||
if (code === 200) {
|
||||
onSubmit?.(queryData);
|
||||
message.success('保存成功');
|
||||
} else {
|
||||
message.error(msg);
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ const ViewCreateFormModal: React.FC<ModelCreateFormModalProps> = ({
|
||||
setSaveLoading(false);
|
||||
if (code === 200) {
|
||||
onSubmit?.(queryData);
|
||||
message.success('保存成功');
|
||||
} else {
|
||||
message.error(msg);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ const ViewSearchFormModal: React.FC<ModelCreateFormModalProps> = ({
|
||||
setSaveLoading(false);
|
||||
if (code === 200) {
|
||||
onSubmit?.(queryData);
|
||||
message.success('保存成功');
|
||||
} else {
|
||||
message.error(msg);
|
||||
}
|
||||
|
||||
@@ -373,12 +373,6 @@ export async function executeSql(params: ExcuteSqlParams) {
|
||||
return request.post(`${process.env.API_BASE_URL}database/executeSql`, { data });
|
||||
}
|
||||
|
||||
export async function listColumnsBySql(data: { databaseId: number; sql: string }) {
|
||||
return request.post(`${process.env.API_BASE_URL}database/listColumnsBySql`, {
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export function getCatalogs(dbId: number): Promise<any> {
|
||||
return request(`${process.env.API_BASE_URL}database/getCatalogs`, {
|
||||
method: 'GET',
|
||||
@@ -409,7 +403,12 @@ export function getTables(databaseId: number, catalog: string, dbName: string):
|
||||
});
|
||||
}
|
||||
|
||||
export function getColumns(databaseId: number, catalog: string, dbName: string, tableName: string): Promise<any> {
|
||||
export function getColumns(
|
||||
databaseId: number,
|
||||
catalog: string,
|
||||
dbName: string,
|
||||
tableName: string,
|
||||
): Promise<any> {
|
||||
return request(`${process.env.API_BASE_URL}database/getColumnsByName`, {
|
||||
method: 'GET',
|
||||
params: {
|
||||
|
||||
Reference in New Issue
Block a user