mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
(improvement)(headless) Optimize jsqlparser code and add support for complex queries like WITH in the corrector (#1730)
This commit is contained in:
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.chat.corrector;
|
||||
|
||||
import com.tencent.supersonic.common.jsqlparser.AggregateEnum;
|
||||
import com.tencent.supersonic.common.jsqlparser.FieldExpression;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlAsHelper;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlRemoveHelper;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlReplaceHelper;
|
||||
import com.tencent.supersonic.common.jsqlparser.SqlSelectHelper;
|
||||
@@ -38,8 +39,6 @@ public class SchemaCorrector extends BaseSemanticCorrector {
|
||||
|
||||
correctAggFunction(semanticParseInfo);
|
||||
|
||||
replaceAlias(semanticParseInfo);
|
||||
|
||||
updateFieldNameByLinkingValue(semanticParseInfo);
|
||||
|
||||
updateFieldValueByLinkingValue(semanticParseInfo);
|
||||
@@ -62,17 +61,16 @@ public class SchemaCorrector extends BaseSemanticCorrector {
|
||||
sqlInfo.setCorrectedS2SQL(sql);
|
||||
}
|
||||
|
||||
private void replaceAlias(SemanticParseInfo semanticParseInfo) {
|
||||
SqlInfo sqlInfo = semanticParseInfo.getSqlInfo();
|
||||
String replaceAlias = SqlReplaceHelper.replaceAlias(sqlInfo.getCorrectedS2SQL());
|
||||
sqlInfo.setCorrectedS2SQL(replaceAlias);
|
||||
}
|
||||
|
||||
private void correctFieldName(
|
||||
ChatQueryContext chatQueryContext, SemanticParseInfo semanticParseInfo) {
|
||||
Map<String, String> fieldNameMap =
|
||||
getFieldNameMap(chatQueryContext, semanticParseInfo.getDataSetId());
|
||||
// add as fieldName
|
||||
SqlInfo sqlInfo = semanticParseInfo.getSqlInfo();
|
||||
List<String> asFields = SqlAsHelper.getAsFields(sqlInfo.getCorrectedS2SQL());
|
||||
for (String asField : asFields) {
|
||||
fieldNameMap.put(asField, asField);
|
||||
}
|
||||
String sql = SqlReplaceHelper.replaceFields(sqlInfo.getCorrectedS2SQL(), fieldNameMap);
|
||||
sqlInfo.setCorrectedS2SQL(sql);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ public class TagQueryServiceImpl implements TagQueryService {
|
||||
@Value("${s2.item.value.date.format:yyyy-MM-dd}")
|
||||
private String itemValueDateFormat;
|
||||
|
||||
//因有些数据库(如Postgresql)不支持列名大小写,所以列名统一使用小写,以兼容更多数据库
|
||||
//private final String tagValueAlias = "internalTagCount";
|
||||
// 因有些数据库(如Postgresql)不支持列名大小写,所以列名统一使用小写,以兼容更多数据库
|
||||
// private final String tagValueAlias = "internalTagCount";
|
||||
private final String tagValueAlias = "internal_tag_count";
|
||||
private final String maxDateAlias = "internal_max_date";
|
||||
private final TagMetaService tagMetaService;
|
||||
|
||||
@@ -116,6 +116,10 @@ public class QueryUtils {
|
||||
column.setDataFormatType(metricRespMap.get(nameEn).getDataFormatType());
|
||||
column.setDataFormat(metricRespMap.get(nameEn).getDataFormat());
|
||||
}
|
||||
// set name by NameEn
|
||||
if (StringUtils.isBlank(column.getName()) && StringUtils.isNotBlank(column.getNameEn())) {
|
||||
column.setName(column.getNameEn());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNumberType(String type) {
|
||||
|
||||
Reference in New Issue
Block a user