{"record":{"id":"40672d1c79b671b7","repo":"apache/beam","slug":"the-other-cepliteral-should-have-type-given","errorCode":null,"errorMessage":"The other CEPLiteral should have type , given: ","messagePattern":"The other CEPLiteral should have type , given: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPLiteral.java","lineNumber":79,"sourceCode":"        throw new SqlConversionException(\"SQL type not supported: \" + lit.getTypeName().toString());\n    }\n  }\n\n  public static CEPLiteral of(Byte myByte) {\n    return new CEPLiteral(Schema.TypeName.BYTE) {\n      @Override\n      public Byte getByte() {\n        return myByte;\n      }\n\n      @Override\n      public int compareTo(Object other) {\n        if (!(other instanceof CEPLiteral)) {\n          throw new IllegalStateException(\"The other object should be an instance of CEPLiteral\");\n        }\n        CEPLiteral otherLit = (CEPLiteral) other;\n        if (getTypeName() != otherLit.getTypeName()) {\n          throw new IllegalStateException(\n              \"The other CEPLiteral should have type \"\n                  + getTypeName().toString()\n                  + \", given: \"\n                  + otherLit.getTypeName().toString());\n        }\n        return myByte.compareTo(otherLit.getByte());\n      }\n    };\n  }\n\n  public static CEPLiteral of(Short myShort) {\n    return new CEPLiteral(Schema.TypeName.INT16) {\n      @Override\n      public Short getInt16() {\n        return myShort;\n      }\n\n      @Override","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPLiteral.java#L61-L97","documentation":"After confirming the other object is a CEPLiteral, the Byte-typed CEPLiteral's compareTo additionally requires both literals to have the same SqlTypeName (both SMALLINT/TINYINT byte-typed). If the other literal was created with a different type, the library throws this IllegalStateException with the expected and actual type names. It guards against silently comparing literals of different SQL types.","triggerScenarios":"Calling compareTo/equals (or evalCondition during pattern matching) with two CEPLiteral objects whose getTypeName() differ, e.g. comparing a Byte literal against an Integer or VarChar literal; CEP condition code pairing a pattern parameter with a column value of a different SQL type.","commonSituations":"Event-pattern conditions comparing literal constants against fields whose inferred Calcite type differs (TINYINT vs INTEGER); tests building literals with mismatched factory methods; schema evolution changing a field's type so existing literals no longer match.","solutions":["Create the other CEPLiteral with the same SqlTypeName as this literal","Cast/convert the value to the expected SQL type before wrapping it in a CEPLiteral","Log/inspect both getTypeName() values in the exception message and align the condition definition in the SQL pattern","Update the CEP pattern's parameter typing so operands of a comparison share one type"],"exampleFix":"// before\nCEPLiteral other = CEPLiteral.of(42, Integer.class); // INTEGER\nbyteLiteral.compareTo(other); // throws\n// after\nCEPLiteral other = CEPLiteral.of((byte) 42, Byte.class); // matching TINYINT\nbyteLiteral.compareTo(other);","handlingStrategy":"validation","validationCode":"// before comparing two literals\nif (a.getTypeName() != b.getTypeName()) {\n  throw new IllegalArgumentException(\"type mismatch: \" + a.getTypeName() + \" vs \" + b.getTypeName());\n}","typeGuard":"static boolean sameType(CEPLiteral a, Object b) {\n  return b instanceof CEPLiteral\n      && a.getTypeName().equals(((CEPLiteral) b).getTypeName());\n}","tryCatchPattern":"try {\n  int cmp = byteLiteral.compareTo(otherLit);\n} catch (IllegalStateException e) {\n  // handle type mismatch: convert other literal or skip comparison\n}","preventionTips":["Pair literals of identical SqlTypeName in pattern conditions","Convert column values to the literal's SQL type before wrapping in CEPLiteral","Check Calcite-inferred field types when writing MATCH_RECOGNIZE conditions","Add assertions in tests that compared literals share getTypeName()"],"tags":["java","cep","sql","comparable","sql-type"],"backgroundTag":"type-mismatch","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"}