apache/skywalking · error · IllegalExpressionException

Unsupported aggregateLabels function.

Error message

Unsupported aggregateLabels function.

What it means

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.

Source

Thrown at oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/AggregateLabelsOp.java:55

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;

public class AggregateLabelsOp {

    public static ExpressionResult doAggregateLabelsOp(ExpressionResult result,
                                                       int funcType,
                                                       List<String> labelNames) throws IllegalExpressionException {
        switch (funcType) {
            case MQEParser.AVG:
                return aggregateLabeledValueResult(result, labelNames, AvgAggregateLabelsFunc::new);
            case MQEParser.SUM:
                return aggregateLabeledValueResult(result, labelNames, SumAggregateLabelsFunc::new);
            case MQEParser.MAX:
                return aggregateLabeledValueResult(result, labelNames, MaxAggregateLabelsFunc::new);
            case MQEParser.MIN:
                return aggregateLabeledValueResult(result, labelNames, MinAggregateLabelsFunc::new);
            default:
                throw new IllegalExpressionException("Unsupported aggregateLabels function.");
        }
    }

    private static ExpressionResult aggregateLabeledValueResult(ExpressionResult expResult,
                                                                List<String> labelNames,
                                                                AggregateLabelsFuncFactory factory) {
        List<MQEValues> results = expResult.getResults();
        if (CollectionUtils.isEmpty(results)) {
            return expResult;
        }

        LinkedHashMap<List<KeyValue>, List<MQEValues>> groupedResult = results.stream().collect(groupingBy(mqeValues -> getLabels(labelNames, mqeValues),
                                                                                                          LinkedHashMap::new,
                                                                                                          toList()));
        if (groupedResult.size() == 1 && groupedResult.keySet().iterator().next().isEmpty()) {
            expResult.setLabeledResult(false);
        }
        expResult.getResults().clear();

View on GitHub (pinned to 102af09b4a)

Solutions

  1. Replace the function with one of AVG, SUM, MAX, MIN
  2. If you need a count, restructure the query (count is not supported across labels; consider a different metric or relabel/k8s labels at ingest)
  3. Check the MQE doc for your OAP version to confirm supported aggregateLabels functions
  4. Upgrade OAP if a newer release added the function you need

Example fix

# before
aggregate_labels(service_percentile.p99(dt5m), COUNT)
# after
aggregate_labels(service_percentile.p99(dt5m), AVG)
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<String> SUPPORTED = Set.of("AVG", "SUM", "MAX", "MIN");
void assertAggregateLabelsFunc(String func) {
    if (!SUPPORTED.contains(func.toUpperCase())) throw new IllegalArgumentException("Unsupported aggregateLabels function: " + func);
}

Type guard

boolean isSupportedAggregateLabelsFunc(String f) {
    return f != null && java.util.Set.of("AVG","SUM","MAX","MIN").contains(f.toUpperCase(Locale.ROOT));
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14). Data as JSON: /api/errors/6645fddfb6d38f20. Report an issue: GitHub.