apache/druid · error · RE

function '%s' is not defined.

Error message

function '%s' is not defined.

What it means

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.'

Source

Thrown at processing/src/main/java/org/apache/druid/math/expr/ExprListenerImpl.java:94

      case ExprParser.MINUS:
        nodes.put(ctx, new UnaryMinusExpr(ctx.getChild(0).getText(), (Expr) nodes.get(ctx.getChild(1))));
        break;
      case ExprParser.NOT:
        nodes.put(ctx, new UnaryNotExpr(ctx.getChild(0).getText(), (Expr) nodes.get(ctx.getChild(1))));
        break;
      default:
        throw new RE("Unrecognized unary operator %s", ctx.getChild(0).getText());
    }
  }

  @Override
  public void exitApplyFunctionExpr(ExprParser.ApplyFunctionExprContext ctx)
  {
    String fnName = ctx.getChild(0).getText();
    // Built-in functions.
    final ApplyFunction function = Parser.getApplyFunction(fnName);
    if (function == null) {
      throw new RE("function '%s' is not defined.", fnName);
    }

    nodes.put(
        ctx,
        new ApplyFunctionExpr(function, fnName, (LambdaExpr) nodes.get(ctx.lambda()), (List<Expr>) nodes.get(ctx.fnArgs()))
    );
  }


  @Override
  public void exitDoubleExpr(ExprParser.DoubleExprContext ctx)
  {
    nodes.put(
        ctx,
        new DoubleExpr(Double.parseDouble(ctx.getText()))
    );
  }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Correct the function name to a registered apply function (map, filter, fold, cart_product, array_... as applicable)
  2. Check Parser.getApplyFunction/available apply functions to confirm the exact name
  3. Enable/load the extension that registers the custom function, or upgrade Druid if the function is newer

Example fix

// before
"mapp(x -> x * 2)"
// after
"map(x -> x * 2)"
Defensive patterns

Strategy: validation

Validate before calling

if (org.apache.druid.math.expr.Parser.getApplyFunction(fnName) == null) {
  throw new IllegalArgumentException("apply function not defined: " + fnName);
}

Try / catch

try {
  expr = Expr.parse(exprStr);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("is not defined")) {
    // surface a friendly 'unknown function' message
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/7197d8f98b5abc5c. Report an issue: GitHub.