mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(Fix)(headless)Fix expression replacement issue. (#2024)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
public enum SchemaElementType {
|
||||
DATASET, METRIC, DIMENSION, VALUE, ID, DATE, TAG, TERM
|
||||
DATASET, MODEL, METRIC, DIMENSION, VALUE, ID, DATE, TAG, TERM
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
public class SqlExecuteReq {
|
||||
public static final String LIMIT_WRAPPER = " SELECT * FROM ( %s ) a LIMIT %d ";
|
||||
|
||||
@NotNull(message = "modelId can not be null")
|
||||
@NotNull(message = "databaseId can not be null")
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "sql can not be blank")
|
||||
|
||||
@@ -58,12 +58,12 @@ public abstract class BaseMatchStrategy<T extends MapResult> implements MatchStr
|
||||
boolean isDeleted = existResults.removeIf(existResult -> {
|
||||
boolean delete = existResult.lessSimilar(oneRoundResult);
|
||||
if (delete) {
|
||||
log.info("deleted existResult:{}", existResult);
|
||||
log.debug("deleted existResult:{}", existResult);
|
||||
}
|
||||
return delete;
|
||||
});
|
||||
if (isDeleted) {
|
||||
log.info("deleted, add oneRoundResult:{}", oneRoundResult);
|
||||
log.debug("deleted, add oneRoundResult:{}", oneRoundResult);
|
||||
existResults.add(oneRoundResult);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -127,7 +127,7 @@ public class KeywordMapper extends BaseMapper {
|
||||
.similarity(EditDistanceUtils.getSimilarity(match.getDetectWord(),
|
||||
schemaElement.getName()))
|
||||
.build();
|
||||
log.info("add to schema, elementMatch {}", schemaElementMatch);
|
||||
log.debug("add to schema, elementMatch {}", schemaElementMatch);
|
||||
addToSchemaMap(chatQueryContext.getMapInfo(), schemaElement.getDataSetId(),
|
||||
schemaElementMatch);
|
||||
}
|
||||
|
||||
@@ -55,12 +55,12 @@ public class DefaultSemanticTranslator implements SemanticTranslator {
|
||||
|
||||
private void mergeOntologyQuery(QueryStatement queryStatement) throws Exception {
|
||||
OntologyQuery ontologyQuery = queryStatement.getOntologyQuery();
|
||||
log.info("parse with ontology: [{}]", ontologyQuery);
|
||||
|
||||
if (Objects.isNull(ontologyQuery) || StringUtils.isBlank(ontologyQuery.getSql())) {
|
||||
throw new Exception(String.format("parse ontology table [%s] error [%s]",
|
||||
queryStatement.getSqlQuery().getTable(), queryStatement.getErrMsg()));
|
||||
throw new Exception(String.format("parse ontology sql [%s] error [%s]",
|
||||
StringUtils.normalizeSpace(queryStatement.getSqlQuery().getSql()),
|
||||
queryStatement.getErrMsg()));
|
||||
}
|
||||
log.info("parse with ontologyQuery fields: [{}]", ontologyQuery.getFields());
|
||||
|
||||
SqlQuery sqlQuery = queryStatement.getSqlQuery();
|
||||
String ontologyOuterSql = sqlQuery.getSql();
|
||||
|
||||
@@ -139,7 +139,7 @@ public class SqlUtils {
|
||||
throws SQLException {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
for (QueryColumn queryColumn : queryColumns) {
|
||||
String colName = queryColumn.getNameEn();
|
||||
String colName = queryColumn.getBizName();
|
||||
Object value = rs.getObject(colName);
|
||||
map.put(colName, getValue(value));
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ public class DimValueAspect {
|
||||
}
|
||||
|
||||
for (QueryColumn queryColumn : columns) {
|
||||
if (dimAndTechNameAndBizNamePair.containsKey(queryColumn.getNameEn())) {
|
||||
if (dimAndTechNameAndBizNamePair.containsKey(queryColumn.getBizName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class S2SemanticLayerService implements SemanticLayerService {
|
||||
|
||||
private List<QueryColumn> createQueryColumns(DimensionValueReq dimensionValueReq) {
|
||||
QueryColumn queryColumn = new QueryColumn();
|
||||
queryColumn.setNameEn(dimensionValueReq.getBizName());
|
||||
queryColumn.setBizName(dimensionValueReq.getBizName());
|
||||
queryColumn.setShowType(SemanticType.CATEGORY.name());
|
||||
queryColumn.setAuthorized(true);
|
||||
queryColumn.setType("CHAR");
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DatabaseController {
|
||||
public SemanticQueryResp executeSql(@RequestBody SqlExecuteReq sqlExecuteReq,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
User user = UserHolder.findUser(request, response);
|
||||
return databaseService.executeSql(sqlExecuteReq, sqlExecuteReq.getId(), user);
|
||||
return databaseService.executeSql(sqlExecuteReq, user);
|
||||
}
|
||||
|
||||
@RequestMapping("/getDbNames")
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface DatabaseService {
|
||||
|
||||
List<DatabaseResp> getDatabaseByType(DataType dataType);
|
||||
|
||||
SemanticQueryResp executeSql(SqlExecuteReq sqlExecuteReq, Long id, User user);
|
||||
SemanticQueryResp executeSql(SqlExecuteReq sqlExecuteReq, User user);
|
||||
|
||||
DatabaseResp getDatabase(Long id, User user);
|
||||
|
||||
|
||||
@@ -138,8 +138,8 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
||||
}
|
||||
|
||||
@Override
|
||||
public SemanticQueryResp executeSql(SqlExecuteReq sqlExecuteReq, Long id, User user) {
|
||||
DatabaseResp databaseResp = getDatabase(id);
|
||||
public SemanticQueryResp executeSql(SqlExecuteReq sqlExecuteReq, User user) {
|
||||
DatabaseResp databaseResp = getDatabase(sqlExecuteReq.getId());
|
||||
if (databaseResp == null) {
|
||||
return new SemanticQueryResp();
|
||||
}
|
||||
@@ -257,7 +257,7 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
||||
List<DBColumn> dbColumns = Lists.newArrayList();
|
||||
for (QueryColumn queryColumn : semanticQueryResp.getColumns()) {
|
||||
DBColumn dbColumn = new DBColumn();
|
||||
dbColumn.setColumnName(queryColumn.getNameEn());
|
||||
dbColumn.setColumnName(queryColumn.getBizName());
|
||||
dbColumn.setDataType(queryColumn.getType());
|
||||
dbColumns.add(dbColumn);
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public class DownloadServiceImpl implements DownloadService {
|
||||
for (Map<String, Object> row : semanticQueryResp.getResultList()) {
|
||||
List<String> rowData = new ArrayList<>();
|
||||
for (QueryColumn column : semanticQueryResp.getColumns()) {
|
||||
rowData.add(String.valueOf(row.get(column.getNameEn())));
|
||||
rowData.add(String.valueOf(row.get(column.getBizName())));
|
||||
}
|
||||
data.add(rowData);
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public class DownloadServiceImpl implements DownloadService {
|
||||
QueryColumn metric = metricColumns.get(0);
|
||||
List<String> groups = queryStructReq.getGroups();
|
||||
List<Map<String, Object>> dataTransformed =
|
||||
DataTransformUtils.transform(queryResult.getResultList(), metric.getNameEn(),
|
||||
DataTransformUtils.transform(queryResult.getResultList(), metric.getBizName(),
|
||||
groups, queryStructReq.getDateInfo());
|
||||
List<List<String>> headers =
|
||||
buildHeader(dimensionColumns, queryStructReq.getDateInfo().getDateList());
|
||||
@@ -264,7 +264,7 @@ public class DownloadServiceImpl implements DownloadService {
|
||||
|
||||
private Map<String, String> getDimensionNameMap(List<QueryColumn> queryColumns) {
|
||||
return queryColumns.stream()
|
||||
.collect(Collectors.toMap(QueryColumn::getName, QueryColumn::getNameEn));
|
||||
.collect(Collectors.toMap(QueryColumn::getName, QueryColumn::getBizName));
|
||||
}
|
||||
|
||||
private List<DimensionResp> getMetricRelaDimensions(MetricResp metricResp,
|
||||
|
||||
@@ -309,7 +309,7 @@ public class FlightServiceImpl extends BasicFlightSqlProducer implements FlightS
|
||||
int columnNum = resp.getColumns().size();
|
||||
rowSetMetaData.setColumnCount(columnNum);
|
||||
for (int i = 1; i <= columnNum; i++) {
|
||||
String columnName = resp.getColumns().get(i - 1).getNameEn();
|
||||
String columnName = resp.getColumns().get(i - 1).getBizName();
|
||||
rowSetMetaData.setColumnName(i, columnName);
|
||||
Optional<Map<String, Object>> valOpt = resp.getResultList().stream()
|
||||
.filter(r -> r.containsKey(columnName) && Objects.nonNull(r.get(columnName)))
|
||||
@@ -329,7 +329,7 @@ public class FlightServiceImpl extends BasicFlightSqlProducer implements FlightS
|
||||
for (Map<String, Object> row : resp.getResultList()) {
|
||||
rowset.moveToInsertRow();
|
||||
for (int i = 1; i <= columnNum; i++) {
|
||||
String columnName = resp.getColumns().get(i - 1).getNameEn();
|
||||
String columnName = resp.getColumns().get(i - 1).getBizName();
|
||||
if (row.containsKey(columnName)) {
|
||||
rowset.updateObject(i, row.get(columnName));
|
||||
} else {
|
||||
|
||||
@@ -72,7 +72,7 @@ public class QueryUtils {
|
||||
private void processColumn(QueryColumn column, Map<String, String> namePair,
|
||||
Map<String, String> nameTypePair, Map<String, MetricResp> metricRespMap,
|
||||
Map<String, DimensionResp> dimensionRespMap) {
|
||||
String nameEn = getName(column.getNameEn());
|
||||
String nameEn = getName(column.getBizName());
|
||||
if (nameEn.contains(JOIN_UNDERLINE)) {
|
||||
nameEn = nameEn.split(JOIN_UNDERLINE)[1];
|
||||
}
|
||||
@@ -110,8 +110,8 @@ public class QueryUtils {
|
||||
column.setModelId(dimensionRespMap.get(nameEn).getModelId());
|
||||
}
|
||||
// set name by NameEn
|
||||
if (StringUtils.isBlank(column.getName()) && StringUtils.isNotBlank(column.getNameEn())) {
|
||||
column.setName(column.getNameEn());
|
||||
if (StringUtils.isBlank(column.getName()) && StringUtils.isNotBlank(column.getBizName())) {
|
||||
column.setName(column.getBizName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user