{"record":{"id":"8c43eab3d8111a04","repo":"apache/druid","slug":"second-argument-must-be-a-registered-lookup-name","errorCode":null,"errorMessage":"second argument must be a registered lookup name","messagePattern":"second argument must be a registered lookup name","errorType":"validation","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/expression/LookupExprMacro.java","lineNumber":69,"sourceCode":"\n  @Override\n  public String name()\n  {\n    return FN_NAME;\n  }\n\n  @Override\n  public Expr apply(final List<Expr> args)\n  {\n    validationHelperCheckArgumentRange(args, 2, 3);\n\n    final Expr arg = args.get(0);\n    final Expr lookupExpr = args.get(1);\n    final Expr replaceMissingValueWith = getReplaceMissingValueWith(args);\n\n    validationHelperCheckArgIsLiteral(lookupExpr, \"second argument\");\n    if (lookupExpr.getLiteralValue() == null) {\n      throw validationFailed(\"second argument must be a registered lookup name\");\n    }\n\n    final String lookupName = lookupExpr.getLiteralValue().toString();\n    final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(\n        lookupExtractorFactoryContainerProvider,\n        lookupName,\n        false,\n        replaceMissingValueWith != null && replaceMissingValueWith.isLiteral()\n        ? Evals.asString(replaceMissingValueWith.getLiteralValue())\n        : null,\n        null,\n        null\n    );\n\n    class LookupExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr\n    {\n      private LookupExpr(final List<Expr> args)\n      {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/expression/LookupExprMacro.java#L51-L87","documentation":"The LOOKUP expression macro's second argument must be a non-null string literal naming a registered lookup. Druid throws a validation failure when the literal is null (or otherwise not a usable lookup name), because the macro compiles to a RegisteredLookupExtractionFn that needs a concrete lookup name at compile time.","triggerScenarios":"Calling LOOKUP(col, <literal>) where the second argument's literal value is null, e.g. LOOKUP(col, NULL), or passing a non-literal (column/expression) as the lookup name, or an unquoted identifier that evaluates to null.","commonSituations":"Generated SQL where the lookup name came from an empty config/template variable; users trying to parameterize the lookup name with a column reference; SQL NULL literals submitted for the lookup argument.","solutions":["Pass the lookup name as a quoted string literal: LOOKUP(col, 'country_code_to_name').","Confirm the lookup is actually registered in the cluster (the name must be non-null and resolvable by the lookup coordinator).","Fix the query generator/template so the lookup-name variable is populated before query submission."],"exampleFix":"-- before\nSELECT LOOKUP(country, NULL) FROM t\n-- after\nSELECT LOOKUP(country, 'country_code_to_name') FROM t","handlingStrategy":"validation","validationCode":"// JS/TS before emitting SQL\nif (typeof lookupName !== 'string' || lookupName.length === 0) throw new Error('LOOKUP requires a registered lookup name literal');","typeGuard":"function isLookupName(x) { return typeof x === 'string' && x.trim().length > 0; }","tryCatchPattern":"try {\n  return runDruidQuery(query);\n} catch (ExpressionValidationException e) {\n  if (e.getMessage().contains(\"registered lookup name\")) {\n    throw new UserInputException(\"LOOKUP second argument must be a non-null lookup name string\");\n  }\n  throw e;\n}","preventionTips":["Always quote the lookup name as a string literal in SQL.","Resolve lookup-name template variables before query submission.","Verify lookup registration (coordination service) before using a name in queries."],"tags":["druid","expression","lookup","validation"],"backgroundTag":"missing-required-argument","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"}