{"record":{"id":"6645fddfb6d38f20","repo":"apache/skywalking","slug":"unsupported-aggregatelabels-function","errorCode":null,"errorMessage":"Unsupported aggregateLabels function.","messagePattern":"Unsupported aggregateLabels function\\.","errorType":"exception","errorClass":"IllegalExpressionException","httpStatus":null,"severity":"error","filePath":"oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java","lineNumber":55,"sourceCode":"import static java.util.stream.Collectors.groupingBy;\nimport static java.util.stream.Collectors.toList;\n\npublic class AggregateLabelsOp {\n\n    public static ExpressionResult doAggregateLabelsOp(ExpressionResult result,\n                                                       int funcType,\n                                                       List<String> labelNames) throws IllegalExpressionException {\n        switch (funcType) {\n            case MQEParser.AVG:\n                return aggregateLabeledValueResult(result, labelNames, AvgAggregateLabelsFunc::new);\n            case MQEParser.SUM:\n                return aggregateLabeledValueResult(result, labelNames, SumAggregateLabelsFunc::new);\n            case MQEParser.MAX:\n                return aggregateLabeledValueResult(result, labelNames, MaxAggregateLabelsFunc::new);\n            case MQEParser.MIN:\n                return aggregateLabeledValueResult(result, labelNames, MinAggregateLabelsFunc::new);\n            default:\n                throw new IllegalExpressionException(\"Unsupported aggregateLabels function.\");\n        }\n    }\n\n    private static ExpressionResult aggregateLabeledValueResult(ExpressionResult expResult,\n                                                                List<String> labelNames,\n                                                                AggregateLabelsFuncFactory factory) {\n        List<MQEValues> results = expResult.getResults();\n        if (CollectionUtils.isEmpty(results)) {\n            return expResult;\n        }\n\n        LinkedHashMap<List<KeyValue>, List<MQEValues>> groupedResult = results.stream().collect(groupingBy(mqeValues -> getLabels(labelNames, mqeValues),\n                                                                                                          LinkedHashMap::new,\n                                                                                                          toList()));\n        if (groupedResult.size() == 1 && groupedResult.keySet().iterator().next().isEmpty()) {\n            expResult.setLabeledResult(false);\n        }\n        expResult.getResults().clear();","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java#L37-L73","documentation":"IllegalExpressionException from AggregateLabelsOp when the aggregateLabels(...) function receives a funcType token other than AVG, SUM, MAX or MIN. The grammar may lex the function name, but the runtime dispatch switch only implements those four aggregations, so any other token reaching dispatch is rejected as unsupported.","triggerScenarios":"Writing aggregate_labels(metric, <FUNC>) with a FUNC the runtime does not implement (e.g. COUNT, MEDIAN, P99 or a typo). Whether it fails at parse (unknown function) or here (known token, unimplemented) depends on the grammar version, but the outcome is the same rejection.","commonSituations":"PromQL-trained users expecting by(cluster) style aggregation with arbitrary functions; requesting COUNT of labeled values which MQE deliberately omits; UI autocompleting a function the deployed OAP version doesn't support yet.","solutions":["Replace the function with one of AVG, SUM, MAX, MIN","If you need a count, restructure the query (count is not supported across labels; consider a different metric or relabel/k8s labels at ingest)","Check the MQE doc for your OAP version to confirm supported aggregateLabels functions","Upgrade OAP if a newer release added the function you need"],"exampleFix":"# before\naggregate_labels(service_percentile.p99(dt5m), COUNT)\n# after\naggregate_labels(service_percentile.p99(dt5m), AVG)","handlingStrategy":"validation","validationCode":"private static final Set<String> SUPPORTED = Set.of(\"AVG\", \"SUM\", \"MAX\", \"MIN\");\nvoid assertAggregateLabelsFunc(String func) {\n    if (!SUPPORTED.contains(func.toUpperCase())) throw new IllegalArgumentException(\"Unsupported aggregateLabels function: \" + func);\n}","typeGuard":"boolean isSupportedAggregateLabelsFunc(String f) {\n    return f != null && java.util.Set.of(\"AVG\",\"SUM\",\"MAX\",\"MIN\").contains(f.toUpperCase(Locale.ROOT));\n}","tryCatchPattern":null,"preventionTips":["Restrict aggregateLabels functions to AVG/SUM/MAX/MIN","Check the MQE doc for the deployed OAP version","Don't assume PromQL aggregation semantics in MQE"],"tags":["mqe","aggregation","query","unsupported-operation"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}