mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(improvement)(headless) add SqlEvaluation interface (#1150)
This commit is contained in:
@@ -37,6 +37,7 @@ public class SemanticParseInfo {
|
||||
private List<SchemaElementMatch> elementMatches = new ArrayList<>();
|
||||
private Map<String, Object> properties = new HashMap<>();
|
||||
private SqlInfo sqlInfo = new SqlInfo();
|
||||
private SqlEvaluation sqlEvaluation = new SqlEvaluation();
|
||||
private QueryType queryType = QueryType.ID;
|
||||
private EntityInfo entityInfo;
|
||||
private String textInfo;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SqlEvaluation {
|
||||
|
||||
private Boolean isValidated;
|
||||
private String validateMsg;
|
||||
}
|
||||
@@ -97,4 +97,14 @@ public class SqlQueryApiController {
|
||||
return semanticQueryRespList;
|
||||
}
|
||||
|
||||
@PostMapping("/validate")
|
||||
public Object validate(@RequestBody QuerySqlReq querySqlReq,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) throws Exception {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
String sql = querySqlReq.getSql();
|
||||
querySqlReq.setSql(StringUtil.replaceBackticks(sql));
|
||||
return chatQueryService.validate(querySqlReq, user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.headless.server.service;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.headless.api.pojo.EntityInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SqlEvaluation;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.DimensionValueReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ExecuteQueryReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryDataReq;
|
||||
@@ -32,5 +33,7 @@ public interface ChatQueryService {
|
||||
Object queryDimensionValue(DimensionValueReq dimensionValueReq, User user) throws Exception;
|
||||
|
||||
void correct(QuerySqlReq querySqlReq, User user);
|
||||
|
||||
SqlEvaluation validate(QuerySqlReq querySqlReq, User user);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaMapInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.SqlEvaluation;
|
||||
import com.tencent.supersonic.headless.api.pojo.SqlInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.CostType;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.QueryMethod;
|
||||
@@ -592,6 +593,17 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
||||
}
|
||||
|
||||
public void correct(QuerySqlReq querySqlReq, User user) {
|
||||
SemanticParseInfo semanticParseInfo = correctSqlReq(querySqlReq, user);
|
||||
querySqlReq.setSql(semanticParseInfo.getSqlInfo().getCorrectS2SQL());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlEvaluation validate(QuerySqlReq querySqlReq, User user) {
|
||||
SemanticParseInfo semanticParseInfo = correctSqlReq(querySqlReq, user);
|
||||
return semanticParseInfo.getSqlEvaluation();
|
||||
}
|
||||
|
||||
private SemanticParseInfo correctSqlReq(QuerySqlReq querySqlReq, User user) {
|
||||
QueryContext queryCtx = new QueryContext();
|
||||
SemanticSchema semanticSchema = semanticService.getSemanticSchema();
|
||||
queryCtx.setSemanticSchema(semanticSchema);
|
||||
@@ -615,7 +627,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
||||
}
|
||||
});
|
||||
log.info("chatQueryServiceImpl correct:{}", sqlInfo.getCorrectS2SQL());
|
||||
querySqlReq.setSql(sqlInfo.getCorrectS2SQL());
|
||||
return semanticParseInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user