mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(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:
@@ -1,7 +1,10 @@
|
|||||||
package com.tencent.supersonic.chat.corrector;
|
package com.tencent.supersonic.chat.corrector;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SemanticCorrectInfo;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SelectCorrector extends BaseSemanticCorrector {
|
public class SelectCorrector extends BaseSemanticCorrector {
|
||||||
@@ -10,6 +13,14 @@ public class SelectCorrector extends BaseSemanticCorrector {
|
|||||||
public void correct(SemanticCorrectInfo semanticCorrectInfo) {
|
public void correct(SemanticCorrectInfo semanticCorrectInfo) {
|
||||||
super.correct(semanticCorrectInfo);
|
super.correct(semanticCorrectInfo);
|
||||||
String sql = semanticCorrectInfo.getSql();
|
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);
|
addFieldsToSelect(semanticCorrectInfo, sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ public class LLMDslParser implements SemanticParser {
|
|||||||
dslCorrection.correct(correctInfo);
|
dslCorrection.correct(correctInfo);
|
||||||
log.info("sqlCorrection:{} sql:{}", dslCorrection.getClass().getSimpleName(), correctInfo.getSql());
|
log.info("sqlCorrection:{} sql:{}", dslCorrection.getClass().getSimpleName(), correctInfo.getSql());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("sqlCorrection:{} correct error,correctInfo:{}", dslCorrection, correctInfo, e);
|
log.error(String.format("correct error,correctInfo:%s", correctInfo), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return correctInfo;
|
return correctInfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user