{"record":{"id":"b8aca89c84e5e39f","repo":"apache/skywalking","slug":"many-to-one-single-result-is-empty-or-has-more-th","errorCode":null,"errorMessage":"Many to One, single result is empty or has more than one value.","messagePattern":"Many to One, single 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":163,"sourceCode":"                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            }\n        }\n\n        return singleLeft;\n    }\n\n    //series or list or labeled single value with scalar\n    private static ExpressionResult many2OneBinaryOp(ExpressionResult manyResult,\n                                                     ExpressionResult singleResult,\n                                                     int opType, LROp calculate) throws IllegalExpressionException {\n        if (singleResult.getResults().isEmpty() ||\n            singleResult.getResults().get(0).getValues().size() != 1) {\n            throw new IllegalExpressionException(\"Many to One, single result is empty or has more than one value.\");\n        }\n        for (MQEValues mqeValues : manyResult.getResults()) {\n            for (MQEValue mqeValue : mqeValues.getValues()) {\n                if (!mqeValue.isEmptyValue()) {\n                    double newValue = calculate.apply(\n                        mqeValue.getDoubleValue(), singleResult.getResults()\n                                                               .get(0)\n                                                               .getValues()\n                                                               .get(0)\n                                                               .getDoubleValue(), opType);\n                    mqeValue.setDoubleValue(newValue);\n                }\n            }\n        }\n        return manyResult;\n    }\n\n    //scalar with series or list or labeled single value","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/mqe-rt/src/main/java/org/apache/skywalking/mqe/rt/operation/LROp.java#L145-L181","documentation":"Thrown by LROp.many2OneBinaryOp, used when a collection-typed operand (TIME_SERIES_VALUES, SORTED_LIST, RECORD_LIST, or a labeled SINGLE_VALUE via single2SingleBinaryOp) is combined with a scalar. The SCALAR side (here the right/single operand) must have exactly one result with exactly one value; otherwise the operation is undefined.","triggerScenarios":"MQE expression like 'time_series_metric + 100' fails only if the scalar side's results are empty or its first MQEValues has != 1 values — a plain literal is fine, so in practice this is a computed scalar (nested aggregation, parenthesized expression, relabeled scalar) that is empty or multi-valued.","commonSituations":"The scalar operand is a sub-query returning no data in the time range; a nested expression on the scalar side producing multiple values; a labeled scalar routed through single2SingleBinaryOp into many2OneBinaryOp with a malformed group; version changes altering nested expression result shapes.","solutions":["Run the scalar (right) operand alone and verify it returns exactly one value","Wrap the scalar operand in an aggregation or latest() to force a single value","If the scalar may be empty, restructure the query to avoid the binary op when data is missing","Check nested parentheses: make sure the single-value side is the one you intend, not a series"],"exampleFix":"// before\nquery: service_resp_time + (sum(other) / sum(total))  // parenthesized scalar empty\n// after\nquery: service_resp_time + latest(other_total_ratio)","handlingStrategy":"validation","validationCode":"ExpressionResult scalar = mqeService.eval(scalarExpr);\nboolean ok = !scalar.getResults().isEmpty()\n    && scalar.getResults().get(0).getValues().size() == 1;","typeGuard":null,"tryCatchPattern":"catch (IllegalExpressionException e) { /* message says 'Many to One, single result...' — audit the scalar side */ }","preventionTips":["Audit the scalar operand of series+scalar expressions first when this fires","Force single values with aggregation or latest()"],"tags":["mqe","query-engine","metrics","binary-op"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}