mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 22:25:19 +00:00
[improvement][headless-chat]Prompt LLM to generate with SQL statement to handle secondary calculation scenario.#1718
This commit is contained in:
@@ -34,9 +34,8 @@ public class OnePassSCSqlGenStrategy extends SqlGenStrategy {
|
||||
+ "\n2.ALWAYS specify date filter using `>`,`<`,`>=`,`<=` operator."
|
||||
+ "\n3.DO NOT include date filter in the where clause if not explicitly expressed in the `Question`."
|
||||
+ "\n4.DO NOT calculate date range using functions."
|
||||
+ "\n5.DO NOT calculate date range using DATE_SUB."
|
||||
+ "\n6.DO NOT miss the AGGREGATE operator of metrics, always add it as needed."
|
||||
+ "\n7.ALWAYS USE `with` statement to handle secondary calculation scenario.\""
|
||||
+ "\n5.DO NOT miss the AGGREGATE operator of metrics, always add it as needed."
|
||||
+ "\n6.ALWAYS use `with` statement if nested aggregation is needed."
|
||||
+ "\n#Exemplars:\n{{exemplar}}"
|
||||
+ "\n#Question:\nQuestion:{{question}},Schema:{{schema}},SideInfo:{{information}}";
|
||||
|
||||
|
||||
@@ -274,17 +274,11 @@ public class SqlGenerateUtils {
|
||||
return modelBizName + UNDERLINE + executorConfig.getInternalMetricNameSuffix();
|
||||
}
|
||||
|
||||
public String generateDerivedMetric(
|
||||
final List<MetricSchemaResp> metricResps,
|
||||
final Set<String> allFields,
|
||||
final Map<String, Measure> allMeasures,
|
||||
final List<DimSchemaResp> dimensionResps,
|
||||
final String expression,
|
||||
final MetricDefineType metricDefineType,
|
||||
AggOption aggOption,
|
||||
Map<String, String> visitedMetric,
|
||||
Set<String> measures,
|
||||
Set<String> dimensions) {
|
||||
public String generateDerivedMetric(final List<MetricSchemaResp> metricResps,
|
||||
final Set<String> allFields, final Map<String, Measure> allMeasures,
|
||||
final List<DimSchemaResp> dimensionResps, final String expression,
|
||||
final MetricDefineType metricDefineType, AggOption aggOption,
|
||||
Map<String, String> visitedMetric, Set<String> measures, Set<String> dimensions) {
|
||||
Set<String> fields = SqlSelectHelper.getColumnFromExpr(expression);
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
Map<String, String> replace = new HashMap<>();
|
||||
@@ -298,19 +292,11 @@ public class SqlGenerateUtils {
|
||||
replace.put(field, visitedMetric.get(field));
|
||||
break;
|
||||
}
|
||||
replace.put(
|
||||
field,
|
||||
generateDerivedMetric(
|
||||
metricResps,
|
||||
allFields,
|
||||
allMeasures,
|
||||
dimensionResps,
|
||||
getExpr(metricItem.get()),
|
||||
metricItem.get().getMetricDefineType(),
|
||||
aggOption,
|
||||
visitedMetric,
|
||||
measures,
|
||||
dimensions));
|
||||
replace.put(field,
|
||||
generateDerivedMetric(metricResps, allFields, allMeasures,
|
||||
dimensionResps, getExpr(metricItem.get()),
|
||||
metricItem.get().getMetricDefineType(), aggOption,
|
||||
visitedMetric, measures, dimensions));
|
||||
visitedMetric.put(field, replace.get(field));
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user