apache/skywalking · error · IllegalExpressionException
Unsupported sort order.
Error message
Unsupported sort order.
What it means
SortLabelValuesOp.doSortLabelValuesOp sorts labeled results by label values; the order token must be exactly MQEParser.ASC or MQEParser.DES. Any other integer reaching the else branch throws 'Unsupported sort order.'. This op backs the sortLabelsForLabeledValues(...) MQE construct; a well-formed parse yields ASC or DES, so other values indicate grammar/runtime mismatch or direct API misuse.
Source
Thrown at oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/SortLabelValuesOp.java:50
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
@Slf4j
public class SortLabelValuesOp {
public static ExpressionResult doSortLabelValuesOp(ExpressionResult expResult,
int order,
List<String> labelNames) throws IllegalExpressionException {
if (CollectionUtils.isNotEmpty(labelNames)) {
labelNames = labelNames.stream().distinct().collect(toList());
if (MQEParser.ASC == order) {
expResult.setResults(
sort(expResult.getResults(), labelNames, labelNames.get(0), Comparator.naturalOrder()));
} else if (MQEParser.DES == order) {
expResult.setResults(
sort(expResult.getResults(), labelNames, labelNames.get(0), Comparator.reverseOrder()));
} else {
throw new IllegalExpressionException("Unsupported sort order.");
}
}
return expResult;
}
private static List<MQEValues> sort(List<MQEValues> results,
List<String> sortLabels,
String currentSortLabel,
Comparator<String> comparator) {
if (!sortLabels.contains(currentSortLabel)) {
log.error("Current sort label {} not found in the sort labels {} ", currentSortLabel, sortLabels);
return results;
}
if (sortLabels.indexOf(
currentSortLabel) == sortLabels.size() - 1) { //only one label or the latest label no need to group
results.sort(Comparator.comparing(mqeValues -> mqeValues.getMetric()
.getLabels()
.stream()View on GitHub (pinned to 102af09b4a)
Solutions
- Use the documented MQE syntax: sortLabelsForLabeledValues(metric, ASC, labelNames) or DES
- If calling programmatically, pass MQEParser.ASC or MQEParser.DES exactly, sourced from the same generated parser version as mqe-rt
- For new sort-order tokens in a fork, add an else-if branch in doSortLabelValuesOp
- Ensure mqe-grammar and mqe-rt jars match versions
Example fix
// before SortLabelValuesOp.doSortLabelValuesOp(result, 0, labels); // 0 is neither ASC nor DES // after SortLabelValuesOp.doSortLabelValuesOp(result, MQEParser.ASC, labels);
Defensive patterns
Strategy: validation
Validate before calling
if (order != MQEParser.ASC && order != MQEParser.DES) {
throw new IllegalArgumentException("order must be MQEParser.ASC or MQEParser.DES");
} Type guard
boolean isValidSortOrder(int order) { return order == MQEParser.ASC || order == MQEParser.DES; } Try / catch
catch (IllegalExpressionException e) { /* bad sort order constant passed to sortLabelsForLabeledValues */ } Prevention
- Use the documented ASC/DES tokens in sortLabelsForLabeledValues
- Import token constants from the same generated parser version as the runtime
When it happens
Trigger: Calling sortLabelsForLabeledValues with an order argument that is neither the ASC nor DES token constant — e.g. passing a SQL-style 'asc'/'desc' string mapping, 0/1 ints, or a custom grammar token after a fork; or a visitor bug passing the wrong token type.
Common situations: Custom grammar forks adding a new sort direction; calling the mqe-rt operation classes directly from plugin code with hand-built opType constants; version skew between the generated parser and the runtime operations jar.
Related errors
- Unsupported function.
- Unsupported function.
- Unsupported function.
- Unsupported aggregateLabels function.
- Unsupported aggregation operation.
AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14).
Data as JSON: /api/errors/6af5705c6597142c.
Report an issue: GitHub.