mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(improvement)(headless) QueryStructReq covert to s2Sql adding a switch to determine whether it is bizName (#668)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -149,16 +149,20 @@ public class QueryStructReq extends SemanticQueryReq {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public QuerySqlReq convert(QueryStructReq queryStructReq) {
|
||||||
|
return convert(queryStructReq, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert queryStructReq to QueryS2QLReq
|
* convert queryStructReq to QueryS2QLReq
|
||||||
*
|
*
|
||||||
* @param queryStructReq
|
* @param queryStructReq
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public QuerySqlReq convert(QueryStructReq queryStructReq) {
|
public QuerySqlReq convert(QueryStructReq queryStructReq, boolean isBizName) {
|
||||||
String sql = null;
|
String sql = null;
|
||||||
try {
|
try {
|
||||||
sql = buildSql(queryStructReq);
|
sql = buildSql(queryStructReq, isBizName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("buildSql error", e);
|
log.error("buildSql error", e);
|
||||||
}
|
}
|
||||||
@@ -170,7 +174,7 @@ public class QueryStructReq extends SemanticQueryReq {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildSql(QueryStructReq queryStructReq) throws JSQLParserException {
|
private String buildSql(QueryStructReq queryStructReq, boolean isBizName) throws JSQLParserException {
|
||||||
Select select = new Select();
|
Select select = new Select();
|
||||||
//1.Set the select items (columns)
|
//1.Set the select items (columns)
|
||||||
PlainSelect plainSelect = new PlainSelect();
|
PlainSelect plainSelect = new PlainSelect();
|
||||||
@@ -249,7 +253,7 @@ public class QueryStructReq extends SemanticQueryReq {
|
|||||||
//6.Set where
|
//6.Set where
|
||||||
List<Filter> dimensionFilters = queryStructReq.getDimensionFilters();
|
List<Filter> dimensionFilters = queryStructReq.getDimensionFilters();
|
||||||
SqlFilterUtils sqlFilterUtils = ContextUtils.getBean(SqlFilterUtils.class);
|
SqlFilterUtils sqlFilterUtils = ContextUtils.getBean(SqlFilterUtils.class);
|
||||||
String whereClause = sqlFilterUtils.getWhereClause(dimensionFilters);
|
String whereClause = sqlFilterUtils.getWhereClause(dimensionFilters, isBizName);
|
||||||
|
|
||||||
String sql = select.toString();
|
String sql = select.toString();
|
||||||
if (StringUtils.isNotBlank(whereClause)) {
|
if (StringUtils.isNotBlank(whereClause)) {
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ import com.tencent.supersonic.headless.api.response.SqlParserResp;
|
|||||||
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
||||||
import com.tencent.supersonic.headless.server.service.DownloadService;
|
import com.tencent.supersonic.headless.server.service.DownloadService;
|
||||||
import com.tencent.supersonic.headless.server.service.QueryService;
|
import com.tencent.supersonic.headless.server.service.QueryService;
|
||||||
import java.util.List;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -34,6 +30,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/semantic/query")
|
@RequestMapping("/api/semantic/query")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -58,7 +59,7 @@ public class QueryController {
|
|||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
QuerySqlReq querySqlReq = queryStructReq.convert(queryStructReq);
|
QuerySqlReq querySqlReq = queryStructReq.convert(queryStructReq, true);
|
||||||
return queryService.queryBySql(querySqlReq, user);
|
return queryService.queryBySql(querySqlReq, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|||||||
String fileName = String.format("%s_%s.xlsx", "supersonic", DateUtils.format(new Date(), DateUtils.FORMAT));
|
String fileName = String.format("%s_%s.xlsx", "supersonic", DateUtils.format(new Date(), DateUtils.FORMAT));
|
||||||
File file = FileUtils.createTmpFile(fileName);
|
File file = FileUtils.createTmpFile(fileName);
|
||||||
try {
|
try {
|
||||||
QuerySqlReq querySqlReq = downloadStructReq.convert(downloadStructReq);
|
QuerySqlReq querySqlReq = downloadStructReq.convert(downloadStructReq, true);
|
||||||
SemanticQueryResp queryResult = (SemanticQueryResp) queryService.queryBySql(querySqlReq, user);
|
SemanticQueryResp queryResult = (SemanticQueryResp) queryService.queryBySql(querySqlReq, user);
|
||||||
DataDownload dataDownload = buildDataDownload(queryResult, downloadStructReq);
|
DataDownload dataDownload = buildDataDownload(queryResult, downloadStructReq);
|
||||||
EasyExcel.write(file).sheet("Sheet1").head(dataDownload.getHeaders()).doWrite(dataDownload.getData());
|
EasyExcel.write(file).sheet("Sheet1").head(dataDownload.getHeaders()).doWrite(dataDownload.getData());
|
||||||
|
|||||||
Reference in New Issue
Block a user