[Fix][headless]Fix the evaluation logic of agg type.

This commit is contained in:
jerryjzhang
2024-12-02 23:39:53 +08:00
parent 0ce79cbfc0
commit 3e903b862e
4 changed files with 16 additions and 7 deletions

View File

@@ -15,7 +15,7 @@ public class ColumnSchema {
private FieldType filedType; private FieldType filedType;
private AggOperatorEnum agg = AggOperatorEnum.UNKNOWN; private AggOperatorEnum agg = AggOperatorEnum.SUM;
private String name; private String name;

View File

@@ -61,13 +61,18 @@ public class SqlQueryConverter implements QueryConverter {
List<MetricSchemaResp> metricSchemas = getMetrics(semanticSchemaResp, allFields); List<MetricSchemaResp> metricSchemas = getMetrics(semanticSchemaResp, allFields);
List<String> metrics = List<String> metrics =
metricSchemas.stream().map(SchemaItem::getBizName).collect(Collectors.toList()); metricSchemas.stream().map(SchemaItem::getBizName).collect(Collectors.toList());
AggOption aggOption = getAggOption(sqlQueryParam.getSql(), metricSchemas);
Set<String> dimensions = getDimensions(semanticSchemaResp, allFields); Set<String> dimensions = getDimensions(semanticSchemaResp, allFields);
OntologyQueryParam ontologyQueryParam = new OntologyQueryParam(); OntologyQueryParam ontologyQueryParam = new OntologyQueryParam();
ontologyQueryParam.getMetrics().addAll(metrics); ontologyQueryParam.getMetrics().addAll(metrics);
ontologyQueryParam.getDimensions().addAll(dimensions); ontologyQueryParam.getDimensions().addAll(dimensions);
ontologyQueryParam.setAggOption(aggOption); AggOption sqlQueryAggOption = getAggOption(sqlQueryParam.getSql(), metricSchemas);
ontologyQueryParam.setNativeQuery(!AggOption.isAgg(aggOption)); // if sql query itself has aggregation, ontology query just returns detail
if (sqlQueryAggOption.equals(AggOption.AGGREGATION)) {
ontologyQueryParam.setAggOption(AggOption.NATIVE);
} else if (sqlQueryAggOption.equals(AggOption.NATIVE) && !metrics.isEmpty()) {
ontologyQueryParam.setAggOption(AggOption.DEFAULT);
}
ontologyQueryParam.setNativeQuery(!AggOption.isAgg(ontologyQueryParam.getAggOption()));
queryStatement.setOntologyQueryParam(ontologyQueryParam); queryStatement.setOntologyQueryParam(ontologyQueryParam);
generateDerivedMetric(sqlGenerateUtils, queryStatement); generateDerivedMetric(sqlGenerateUtils, queryStatement);

View File

@@ -57,7 +57,11 @@ public class StructQueryConverter implements QueryConverter {
.map(Aggregator::getColumn).collect(Collectors.toList())); .map(Aggregator::getColumn).collect(Collectors.toList()));
String where = sqlGenerateUtils.generateWhere(structQueryParam, null); String where = sqlGenerateUtils.generateWhere(structQueryParam, null);
ontologyQueryParam.setWhere(where); ontologyQueryParam.setWhere(where);
ontologyQueryParam.setAggOption(AggOption.AGGREGATION); if (ontologyQueryParam.getMetrics().isEmpty()) {
ontologyQueryParam.setAggOption(AggOption.NATIVE);
} else {
ontologyQueryParam.setAggOption(AggOption.DEFAULT);
}
ontologyQueryParam.setNativeQuery(structQueryParam.getQueryType().isNativeAggQuery()); ontologyQueryParam.setNativeQuery(structQueryParam.getQueryType().isNativeAggQuery());
ontologyQueryParam.setOrder(structQueryParam.getOrders().stream() ontologyQueryParam.setOrder(structQueryParam.getOrders().stream()
.map(order -> new ColumnOrder(order.getColumn(), order.getDirection())) .map(order -> new ColumnOrder(order.getColumn(), order.getDirection()))

View File

@@ -15,6 +15,6 @@ public class OntologyQueryParam {
private String where; private String where;
private Long limit; private Long limit;
private List<ColumnOrder> order; private List<ColumnOrder> order;
private boolean nativeQuery = false; private boolean nativeQuery = true;
private AggOption aggOption = AggOption.DEFAULT; private AggOption aggOption = AggOption.NATIVE;
} }