{"record":{"id":"eb50189f2eb392c4","repo":"apache/beam","slug":"the-left-side-cep-operation-is-not-legal-class","errorCode":null,"errorMessage":"the left side CEP operation is not legal: ${class}","messagePattern":"the left side CEP operation is not legal: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/nfa/NFA.java","lineNumber":526,"sourceCode":"        return inputEvent.toCEPLiteral((CEPFieldRef) inputOperation);\n      } else if (inputOperation.getClass() == CEPCall.class) {\n        CEPCall call = (CEPCall) inputOperation;\n        CEPOperator operator = call.getOperator();\n        List<CEPOperation> operands = call.getOperands();\n        switch (operator.getCepKind()) {\n          case LAST:\n            return last(\n                operands.get(0), evalLeftSideCondition(operands.get(1), inputEvent), inputEvent);\n          case PLUS:\n            return plus(\n                evalLeftSideCondition(operands.get(0), inputEvent),\n                evalLeftSideCondition(operands.get(1), inputEvent));\n          default:\n            throw new UnsupportedOperationException(\n                \"the function is not supported for now: \" + operator.getCepKind().toString());\n        }\n      } else {\n        throw new IllegalStateException(\n            \"the left side CEP operation is not legal: \" + inputOperation.getClass().toString());\n      }\n    }\n\n    // evaluates the condition value (right) given an input event\n    private CEPLiteral evalRightSideCondition(CEPOperation inputOperation, Event inputEvent) {\n      if (inputOperation instanceof CEPLiteral) {\n        return (CEPLiteral) inputOperation;\n      } else if (inputOperation.getClass() == CEPCall.class) {\n        CEPCall call = (CEPCall) inputOperation;\n        CEPOperator operator = call.getOperator();\n        List<CEPOperation> operands = call.getOperands();\n        switch (operator.getCepKind()) {\n          case PLUS:\n            return plus(\n                evalRightSideCondition(operands.get(0), inputEvent),\n                evalRightSideCondition(operands.get(1), inputEvent));\n          case PREV:","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/nfa/NFA.java#L508-L544","documentation":"In NFA.evalLeftSideCondition, the input CEPOperation must be a CEPOperator (RexCall-derived) to be reduced; if it is some other CEPOperation subclass (e.g. an unexpected literal or field-ref wrapper) the else branch throws IllegalStateException with the operation's class name.","triggerScenarios":"The left operand of a DEFINE comparison resolves to a CEPOperation that is neither CEPLiteral, CEPFieldRef, nor CEPOperator — typically an unexpected expression shape produced during translation of the MATCH_RECOGNIZE query.","commonSituations":"Complex/nested expressions in DEFINE that the CEPOperation converter mapped to an unexpected class; internal bugs or version mismatches between Calcite translation and the NFA evaluator.","solutions":["Inspect the named class in the message and simplify the DEFINE expression to standard field-vs-literal comparisons.","Use only supported patterns: field refs, literals, and supported operators on each side of the comparison.","File/patch an issue in CEPOperation.of() if a valid RexNode shape is being converted to the wrong CEPOperation type.","Upgrade Beam — newer versions broaden CEP expression support."],"exampleFix":"// before\nDEFINE A AS CASE WHEN A.x > 0 THEN 1 ELSE 0 END > 0\n// after\nDEFINE A AS A.x > 0","handlingStrategy":"validation","validationCode":"if (!(inputOperation instanceof CEPOperator || inputOperation instanceof CEPLiteral || inputOperation instanceof CEPFieldRef)) {\n  throw new IllegalArgumentException(\"Unexpected CEPOperation class: \" + inputOperation.getClass());\n}","typeGuard":"boolean isKnownCepOperation(CEPOperation op) { return op instanceof CEPOperator || op instanceof CEPLiteral || op instanceof CEPFieldRef; }","tryCatchPattern":"try { return evalLeftSideCondition(op, event); } catch (IllegalStateException e) { throw new QueryTranslationException(\"Malformed CEP operation in DEFINE\", e); }","preventionTips":["Keep DEFINE expressions simple; avoid constructs that may convert to unexpected CEPOperation classes.","Add a translation-time assert that converted operations are of known subclasses.","Track Beam CEP improvements and upgrade when complex expressions become supported."],"tags":["java","nfa","cep","internal-invariant","sql"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}