{"record":{"id":"9dd23468195ef6af","repo":"apache/skywalking","slug":"single-labeled-to-single-labeled-left-labeled-res","errorCode":null,"errorMessage":"Single Labeled to Single Labeled, left labeled result is empty or has more than one value.","messagePattern":"Single Labeled to Single Labeled, left labeled result is empty or has more than one value\\.","errorType":"exception","errorClass":"IllegalExpressionException","httpStatus":null,"severity":"error","filePath":"oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java","lineNumber":133,"sourceCode":"        if (left.isEmptyValue() || right.isEmptyValue()) {\n            mqeValue.setEmptyValue(true);\n        } else {\n            double value = calculate.apply(left.getDoubleValue(), right.getDoubleValue(), opType);\n            mqeValue.setDoubleValue(value);\n        }\n        return result;\n    }\n\n    private static ExpressionResult single2SingleLabeled(ExpressionResult singleLeft,\n                                                           ExpressionResult singleRight,\n                                                           int opType, LROp calculate) throws IllegalExpressionException {\n        Map<Set<KeyValue>, List<MQEValue>> labelMapR = new HashMap<>();\n        singleRight.getResults().forEach(mqeValuesR -> {\n            labelMapR.put(new HashSet<>(mqeValuesR.getMetric().getLabels()), mqeValuesR.getValues());\n        });\n        for (MQEValues mqeValuesL : singleLeft.getResults()) {\n            if (mqeValuesL.getValues().size() != 1) {\n                throw new IllegalExpressionException(\"Single Labeled to Single Labeled, left labeled result is empty or has more than one value.\");\n            }\n            //reserve left metric info\n            MQEValue valueL = mqeValuesL.getValues().get(0);\n            List<MQEValue> mqeValuesR = labelMapR.get(new HashSet<>(mqeValuesL.getMetric().getLabels()));\n            if (mqeValuesR == null) {\n                valueL.setEmptyValue(true);\n            } else {\n                if (mqeValuesR.size() != 1) {\n                    throw new IllegalExpressionException(\"Single Labeled to Single Labeled, right labeled result has more than one value.\");\n                }\n                MQEValue valueR = mqeValuesR.get(0);\n                if (valueL.isEmptyValue() || valueR.isEmptyValue()) {\n                    valueL.setEmptyValue(true);\n                    continue;\n                }\n                double value = calculate.apply(valueL.getDoubleValue(), valueR.getDoubleValue(), opType);\n                valueL.setDoubleValue(value);\n            }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java#L115-L151","documentation":"Thrown by LROp.single2SingleLabeled, which handles SINGLE_VALUE op SINGLE_VALUE where BOTH sides are labeled results. The left side is iterated per label-group (MQEValues), and each group must hold exactly one MQEValue. If any labeled group on the left has a value count != 1, the labeled scalar is malformed and the exception fires.","triggerScenarios":"MQE expression like 'relabels(a, ...) + relabels(b, ...)' or two labeled metrics combined with a binary operator, where at least one left label-group contains 0 or 2+ values. Reached when both operands are SINGLE_VALUE and both isLabeledResult() is true (LROp.java:87-88).","commonSituations":"Using relabels/on labels on a scalar metric that returns multiple values per label combination; label cardinality mismatch after a relabels rule maps several source labels onto one target label group; a metric redefined in OAL/MAL so it now emits multiple values where one used to be guaranteed.","solutions":["Query the left operand alone and inspect each results[] element: every labeled group must have exactly one value","Fix the relabels rules or the metric definition so each label combination yields a single value","Aggregate before labeling: apply sum()/latest() first, then relabels, so each group is a scalar","If multiple values per label are legitimate, redesign the query — single2SingleLabeled semantics require one value per label group"],"exampleFix":"// before\nquery: relabels(a, tag:(key1,val1)) + relabels(b, tag:(key1,val1))\n// after (aggregate first so each label group is a scalar)\nquery: relabels(sum(a), tag:(key1,val1)) + relabels(sum(b), tag:(key1,val1))","handlingStrategy":"validation","validationCode":"boolean ok = left.isLabeledResult()\n    && left.getResults().stream().allMatch(g -> g.getValues().size() == 1);","typeGuard":"boolean isLabeledScalar(ExpressionResult r) {\n    return r.getType() == ExpressionResultType.SINGLE_VALUE\n        && r.isLabeledResult()\n        && r.getResults().stream().allMatch(g -> g.getValues().size() == 1);\n}","tryCatchPattern":"catch (IllegalExpressionException e) { log.warn(\"MQE labeled scalar invalid: {}\", e.getMessage()); }","preventionTips":["Aggregate before relabels so each label group is a scalar","Keep relabels rules 1:1 to avoid folding multiple values into one label group"],"tags":["mqe","query-engine","labels","binary-op"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}