{"record":{"id":"ab691bad9c77cc85","repo":"apache/beam","slug":"calcfn-failed-to-evaluate-processelementblock","errorCode":null,"errorMessage":"CalcFn failed to evaluate: ${processElementBlock}","messagePattern":"CalcFn failed to evaluate: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java","lineNumber":350,"sourceCode":"        OutputReceiver<Row> outputReceiver,\n        MultiOutputReceiver multiOutputReceiver) {\n      assert se != null;\n      try {\n        Object[] v = (Object[]) se.evaluate(new Object[] {row, CONTEXT_INSTANCE});\n        if (v != null) {\n          final Row output = toBeamRow(Arrays.asList(v), outputSchema, verifyRowValues);\n          outputReceiver.output(output);\n        }\n\n      } catch (InvocationTargetException e) {\n        if (collectErrors) {\n          Schema schema = BeamSqlRelUtils.getErrorRowSchema(row.getSchema());\n          Row errorRow =\n              toBeamRow(Arrays.asList(row.getValues(), e.getCause().getMessage()), schema, true);\n          LOG.error(\"CalcFn failed to evaluate: {}\", processElementBlock, e.getCause());\n          multiOutputReceiver.get(errors).output(errorRow);\n        } else {\n          throw new RuntimeException(\n              \"CalcFn failed to evaluate: \" + processElementBlock, e.getCause());\n        }\n      }\n    }\n  }\n\n  private static List<String> getJarPaths(RexProgram program) {\n    ImmutableList.Builder<String> jarPaths = new ImmutableList.Builder<>();\n    for (RexNode node : program.getExprList()) {\n      if (node instanceof RexCall) {\n        SqlOperator op = ((RexCall) node).op;\n        if (op instanceof SqlUserDefinedFunction) {\n          Function function = ((SqlUserDefinedFunction) op).function;\n          if (function instanceof ScalarFunctionImpl) {\n            String jarPath = ((ScalarFunctionImpl) function).getJarPath();\n            if (!jarPath.isEmpty()) {\n              jarPaths.add(jarPath);\n            }","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCalcRel.java#L332-L368","documentation":"At runtime the compiled CalcFn evaluates each row; when evaluation throws and the pipeline is not configured with an error-output (error_fn/exception handling), the cause is rethrown as a RuntimeException naming the generated processElement block. It surfaces user-code failures inside SQL expressions such as NPEs, arithmetic errors, or UDF exceptions.","triggerScenarios":"A row hits the Calc operator and the generated expression throws — null operand for a non-null-safe operator, division by zero, a UDF throwing, or a type cast failing at runtime for a specific record (other records may succeed).","commonSituations":"Null field values feeding SQL functions; dirty data in streaming sources; UDF that assumes non-null or well-formed input; numeric overflow in arithmetic expressions.","solutions":["Read e.getCause() in the exception — it holds the real failure (NPE, UDF exception, etc.) and the failing row","Use Beam SQL's error-tolerant mode: configure the multi-output/errors collection (error row schema) so bad rows are routed instead of failing the pipeline","Null-guard expressions in the query (e.g. COALESCE/IFNULL) and in UDFs","Fix the offending input data or make the UDF defensive"],"exampleFix":"// before\nSELECT quantity / total AS ratio FROM orders;\n// after\nSELECT IFNULL(quantity / NULLIF(total, 0), 0) AS ratio FROM orders;","handlingStrategy":"try-catch","validationCode":"// Pre-validate rows: reject rows with nulls in columns used by the query\nboolean hasRequiredValues(Row r, List<String> cols) {\n  return cols.stream().noneMatch(c -> r.getValue(c) == null);\n}","typeGuard":null,"tryCatchPattern":"try {\n  rowOut = se.eval(...);\n} catch (Throwable e) {\n  // inspect e.getCause(); route row to errors output instead of failing pipeline\n}","preventionTips":["Use COALESCE/IFNULL in queries for nullable columns","Enable Beam SQL error-output so bad rows are captured, not fatal","Make UDFs null-safe and throw informative exceptions","Validate/scrub source data before the SQL transform"],"tags":["java","apache-beam","sql","runtime","udf"],"backgroundTag":"sql-query-failed","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"}