{"record":{"id":"9b421bc0c9e6f263","repo":"apache/beam","slug":"the-right-side-cep-operation-is-not-legal-class","errorCode":null,"errorMessage":"the right side CEP operation is not legal: ${class}","messagePattern":"the right 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":551,"sourceCode":"      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:\n            return prev(operands.get(0), (CEPLiteral) operands.get(1), ptr, curEvent, 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 right side CEP operation is not legal: \" + inputOperation.getClass().toString());\n      }\n    }\n\n    /* below are function implementations */\n\n    // represents the PREV operation\n    private CEPLiteral prev(\n        CEPOperation opr1,\n        CEPLiteral opr2,\n        EventPointer curPointer,\n        Event curEvent,\n        Event inputEvent) {\n      if (opr1.getClass() != CEPFieldRef.class) {\n        throw new IllegalStateException(\n            \"the first argument of the PREV operation should be a field reference. Provided: \"\n                + opr1.getClass().toString());\n      }","sourceCodeStart":533,"sourceCodeEnd":569,"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#L533-L569","documentation":"Beam SQL's CEP (complex event processing) NFA engine evaluates the right-side operand of a MATCH_RECOGNIZE pattern's quantifier/condition. evalRightSideCondition only understands CEPOperation node types it knows (e.g. CEPLiteral, CEPFieldRef with specific operators); anything else means the parsed pattern produced an operand shape the NFA cannot interpret. The library throws IllegalStateException because this reflects an unhandled AST node class, not a user-data problem.","triggerScenarios":"A MATCH_RECOGNIZE PATTERN clause contains a right-side operand whose CEPOperation subclass is not one of the types handled by the switch in evalRightSideCondition (e.g. an unsupported operator kind or nested operation), or a CEP operator kind hits the preceding UnsupportedOperationException default.","commonSituations":"Writing an exotic or newly added CEP pattern syntax that the parser accepts but the NFA evaluator has not implemented; using a Beam version where the CEP feature is still experimental and only a subset of operators is supported.","solutions":["Inspect the PATTERN clause and simplify it to supported constructs (literals, field refs, supported quantifier operators)","Print the class named in the message and compare against the switch in NFA.evalRightSideCondition to see which case is missing","Check the Beam version's CEP documentation for supported operators and upgrade to a release that adds the operator you need","If the operator should be supported, file/patch an issue adding a case in NFA.java's evalRightSideCondition"],"exampleFix":"// before\nPATTERN (e1 e2 e3+) -- uses an operator the NFA does not implement on the right side\n// after\nPATTERN (e1 e2 e3) -- restrict to supported operators/operands","handlingStrategy":"validation","validationCode":"// before running the CEP query, check pattern operands\nfor (CEPOperation op : operands) {\n  if (!(op instanceof CEPLiteral || op instanceof CEPFieldRef)) {\n    throw new IllegalArgumentException(\"Unsupported CEP operand: \" + op.getClass());\n  }\n}","typeGuard":"boolean isSupportedOperand(CEPOperation op) {\n  return op instanceof CEPLiteral || op instanceof CEPFieldRef;\n}","tryCatchPattern":"try {\n  runCepQuery(pattern);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"right side CEP operation is not legal\")) {\n    // fall back to a simplified pattern or surface a clear query-authoring error\n  } else throw e;\n}","preventionTips":["Restrict MATCH_RECOGNIZE patterns to documented operators and operand shapes","Keep CEP patterns simple; test each DEFINE expression on a bounded sample first","Pin a Beam version with known CEP support and review its limitations before authoring patterns"],"tags":["sql","cep","pattern-matching","unsupported"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}