{"record":{"id":"7197d8f98b5abc5c","repo":"apache/druid","slug":"function-s-is-not-defined","errorCode":null,"errorMessage":"function '%s' is not defined.","messagePattern":"function '(.+?)' is not defined\\.","errorType":"validation","errorClass":"RE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java","lineNumber":94,"sourceCode":"      case ExprParser.MINUS:\n        nodes.put(ctx, new UnaryMinusExpr(ctx.getChild(0).getText(), (Expr) nodes.get(ctx.getChild(1))));\n        break;\n      case ExprParser.NOT:\n        nodes.put(ctx, new UnaryNotExpr(ctx.getChild(0).getText(), (Expr) nodes.get(ctx.getChild(1))));\n        break;\n      default:\n        throw new RE(\"Unrecognized unary operator %s\", ctx.getChild(0).getText());\n    }\n  }\n\n  @Override\n  public void exitApplyFunctionExpr(ExprParser.ApplyFunctionExprContext ctx)\n  {\n    String fnName = ctx.getChild(0).getText();\n    // Built-in functions.\n    final ApplyFunction function = Parser.getApplyFunction(fnName);\n    if (function == null) {\n      throw new RE(\"function '%s' is not defined.\", fnName);\n    }\n\n    nodes.put(\n        ctx,\n        new ApplyFunctionExpr(function, fnName, (LambdaExpr) nodes.get(ctx.lambda()), (List<Expr>) nodes.get(ctx.fnArgs()))\n    );\n  }\n\n\n  @Override\n  public void exitDoubleExpr(ExprParser.DoubleExprContext ctx)\n  {\n    nodes.put(\n        ctx,\n        new DoubleExpr(Double.parseDouble(ctx.getText()))\n    );\n  }\n","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java#L76-L112","documentation":"When parsing an apply-function expression (lambda call), ExprListenerImpl.exitApplyFunctionExpr looks up the function name in the registered apply functions via Parser.getApplyFunction. If the name is not registered, it throws 'function %s is not defined.'","triggerScenarios":"Parsing an expression that applies an unknown lambda/apply function name, e.g. 'unknown_fn(x -> x + 1)', or a valid apply function when the parser's function registry was initialized without it.","commonSituations":"Typos in apply function names like 'map', 'filter', 'fold' (e.g. 'map()' misspelled); expressions copied from other engines using unsupported function names; custom expression modules not loaded so registry lacks the function.","solutions":["Correct the function name to a registered apply function (map, filter, fold, cart_product, array_... as applicable)","Check Parser.getApplyFunction/available apply functions to confirm the exact name","Enable/load the extension that registers the custom function, or upgrade Druid if the function is newer"],"exampleFix":"// before\n\"mapp(x -> x * 2)\"\n// after\n\"map(x -> x * 2)\"","handlingStrategy":"validation","validationCode":"if (org.apache.druid.math.expr.Parser.getApplyFunction(fnName) == null) {\n  throw new IllegalArgumentException(\"apply function not defined: \" + fnName);\n}","typeGuard":null,"tryCatchPattern":"try {\n  expr = Expr.parse(exprStr);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"is not defined\")) {\n    // surface a friendly 'unknown function' message\n  } else { throw e; }\n}","preventionTips":["Check Parser.getApplyFunction before emitting apply expressions","Watch for typos in map/filter/fold style functions","Load extensions that register custom functions"],"tags":["expressions","parsing","functions"],"backgroundTag":"function-not-defined","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}