(improvement)(chat) If the number of aggregated fields is equal to the number of queried fields, do not add fields to select (#191)

This commit is contained in:
lexluo09
2023-10-11 11:08:45 +08:00
committed by GitHub
parent 278af3ce34
commit d6cefaa6d2
2 changed files with 12 additions and 1 deletions

View File

@@ -1,7 +1,10 @@
package com.tencent.supersonic.chat.corrector;
import com.tencent.supersonic.chat.api.pojo.SemanticCorrectInfo;
import com.tencent.supersonic.common.util.jsqlparser.SqlParserSelectHelper;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
@Slf4j
public class SelectCorrector extends BaseSemanticCorrector {
@@ -10,6 +13,14 @@ public class SelectCorrector extends BaseSemanticCorrector {
public void correct(SemanticCorrectInfo semanticCorrectInfo) {
super.correct(semanticCorrectInfo);
String sql = semanticCorrectInfo.getSql();
List<String> aggregateFields = SqlParserSelectHelper.getAggregateFields(sql);
List<String> selectFields = SqlParserSelectHelper.getSelectFields(sql);
// If the number of aggregated fields is equal to the number of queried fields, do not add fields to select.
if (!CollectionUtils.isEmpty(aggregateFields)
&& !CollectionUtils.isEmpty(selectFields)
&& aggregateFields.size() == selectFields.size()) {
return;
}
addFieldsToSelect(semanticCorrectInfo, sql);
}
}

View File

@@ -251,7 +251,7 @@ public class LLMDslParser implements SemanticParser {
dslCorrection.correct(correctInfo);
log.info("sqlCorrection:{} sql:{}", dslCorrection.getClass().getSimpleName(), correctInfo.getSql());
} catch (Exception e) {
log.error("sqlCorrection:{} correct error,correctInfo:{}", dslCorrection, correctInfo, e);
log.error(String.format("correct error,correctInfo:%s", correctInfo), e);
}
});
return correctInfo;