{"record":{"id":"7f768c2c83dd93ea","repo":"apache/beam","slug":"types-do-not-match-type1-type2","errorCode":null,"errorMessage":"Types do not match: ${type1}, ${type2}","messagePattern":"Types do not match: (.+?), (.+?)","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":639,"sourceCode":"          case BYTE:\n            return CEPLiteral.of(opr1.getByte() + opr2.getByte());\n          case INT16:\n            return CEPLiteral.of(opr1.getInt16() + opr2.getInt16());\n          case INT32:\n            return CEPLiteral.of(opr1.getInt32() + opr2.getInt32());\n          case INT64:\n            return CEPLiteral.of(opr1.getInt64() + opr2.getInt64());\n          case DECIMAL:\n            return CEPLiteral.of(opr1.getDecimal().add(opr2.getDecimal()));\n          case FLOAT:\n            return CEPLiteral.of(opr1.getFloat() + opr2.getFloat());\n          case DOUBLE:\n            return CEPLiteral.of(opr1.getDouble() + opr2.getDouble());\n          default:\n            throw new UnsupportedOperationException(\"Type is not supported: \" + type1.toString());\n        }\n      } else {\n        throw new IllegalStateException(\n            \"Types do not match: \" + type1.toString() + \", \" + type2.toString());\n      }\n    }\n  }\n\n  // State are determined directly by the PATTERN clause\n  private static class State implements Serializable {\n    private int index = 0; // number ith state (pointer value) in the NFA\n    private final String patternVar;\n    private final Quantifier quant;\n    private final CEPOperation\n        condition; // condition to evaluate when taking the \"begin\" action and \"proceed\" action\n    private State nextState = null;\n    public final boolean isFinal;\n    private final boolean\n        isKleenePlusSecondary; // whether is the second state for a Kleene Plus pattern variable\n\n    State(","sourceCodeStart":621,"sourceCodeEnd":657,"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#L621-L657","documentation":"The NFA arithmetic helper requires both operands of a binary operation to have the same Schema.TypeName. When type1 != type2 it throws IllegalStateException listing both types, because the implementation has no implicit coercion between literal types.","triggerScenarios":"An arithmetic operation in a DEFINE clause mixes operand types, e.g. DECIMAL + DOUBLE or INTEGER + DECIMAL literals/columns.","commonSituations":"Comparing/adding an integer column to a decimal literal; schema evolution changing a column type so pattern expressions no longer line up.","solutions":["Make both operands the same type, e.g. cast one side or use matching literal forms (1.0 vs 1)","Declare/adjust the column schema so related columns share a numeric type","Check both operand types at query-construction time before running the CEP query"],"exampleFix":"// before\nDEFINE e AS PRICE + 1 -- PRICE is DOUBLE, 1 is INTEGER\n// after\nDEFINE e AS PRICE + 1.0","handlingStrategy":"validation","validationCode":"if (type1 != type2) {\n  throw new IllegalArgumentException(\"CEP arithmetic operands must share a type: \" + type1 + \" vs \" + type2);\n}","typeGuard":"boolean sameNumericType(Schema.TypeName a, Schema.TypeName b) {\n  return a == b;\n}","tryCatchPattern":"try {\n  runCepQuery(pattern);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Types do not match:\")) {\n    // align operand types (cast or adjust literals) and retry\n  } else throw e;\n}","preventionTips":["Match literal forms to column types (1.0 for DOUBLE/DECIMAL columns, 1 for INTEGER)","Keep the input schema stable; update pattern expressions when column types change","Prefer a single numeric type across a pattern's DEFINE expressions"],"tags":["sql","cep","type-mismatch","arithmetic"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}