{"record":{"id":"5877096f188c58da","repo":"apache/beam","slug":"the-function-in-measures-is-not-recognized","errorCode":null,"errorMessage":"the function in Measures is not recognized.","messagePattern":"the function in Measures is not recognized\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPUtils.java","lineNumber":210,"sourceCode":"      return streamSchema.getField(field.getIndex()).getType();\n    } else if (measureOperation.getClass() == CEPCall.class) {\n\n      CEPCall call = (CEPCall) measureOperation;\n      CEPKind oprKind = call.getOperator().getCepKind();\n\n      if (oprKind == CEPKind.SUM || oprKind == CEPKind.COUNT) {\n        return Schema.FieldType.INT32;\n      } else if (oprKind == CEPKind.AVG) {\n        return Schema.FieldType.DOUBLE;\n      }\n      CEPFieldRef refOpt;\n      for (CEPOperation i : call.getOperands()) {\n        refOpt = getFieldRef(i);\n        if (refOpt != null) {\n          return streamSchema.getField(refOpt.getIndex()).getType();\n        }\n      }\n      throw new UnsupportedOperationException(\"the function in Measures is not recognized.\");\n    } else {\n      throw new UnsupportedOperationException(\"the function in Measures is not recognized.\");\n    }\n  }\n}\n","sourceCodeStart":192,"sourceCodeEnd":216,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/cep/CEPUtils.java#L192-L216","documentation":"CEPUtils.getFieldType() resolves the SQL type of a MEASURES expression by locating a field reference (RexPatternFieldRef) among a RexCall's operands. If the call's operands contain no recognizable field ref, it throws UnsupportedOperationException, meaning the MEASURES function's output type cannot be inferred.","triggerScenarios":"A MEASURES clause expression (RexCall) whose operands include no RexPatternFieldRef reachable via getFieldRef() — e.g. constant-only expressions or functions over literals.","commonSituations":"MEASURES with expressions like 1+1, constant aggregates, or functions applied only to literals in a MATCH_RECOGNIZE query; Calcite rewrites stripping field refs.","solutions":["Reference at least one pattern variable field in each MEASURES expression (e.g. A.price instead of a constant).","Cast or wrap the constant so it is tied to a field, or compute it outside MATCH_RECOGNIZE.","If legitimate, extend CEPUtils.getFieldType() to fall back to the RexCall's own inferred type via the type factory.","Catch UnsupportedOperationException at query-translation time and report the unsupported MEASURES expression to the user."],"exampleFix":"// before\nMEASURES 1 + 1 AS two\n// after\nMEASURES A.quantity + 1 AS qtyPlusOne","handlingStrategy":"validation","validationCode":"// Ensure each MEASURES expr references at least one pattern field\nif (!referencesPatternField(measuresRexNode)) {\n  throw new IllegalArgumentException(\"MEASURES expression must reference a pattern field\");\n}","typeGuard":"boolean referencesPatternField(RexNode n) { return getFieldRef(n) != null; } // reuse CEPUtils.getFieldRef","tryCatchPattern":"try { return CEPUtils.getFieldType(call, schema); } catch (UnsupportedOperationException e) { throw new QueryValidationException(\"Unresolvable MEASURES expression\", e); }","preventionTips":["Always bind MEASURES expressions to at least one pattern-variable field.","Compute constant-only expressions outside MATCH_RECOGNIZE.","Cover MEASURES typing in query smoke tests."],"tags":["java","cep","sql","measures","unsupported"],"backgroundTag":"unsupported-operation","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"}