{"record":{"id":"9bec3dc007f8ab23","repo":"apache/druid","slug":"cannot-define-both-uri-and-fileregex","errorCode":null,"errorMessage":"Cannot define both uri and fileRegex","messagePattern":"Cannot define both uri and fileRegex","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/lookups-cached-global/src/main/java/org/apache/druid/query/lookup/namespace/UriExtractionNamespace.java","lineNumber":125,"sourceCode":"      throw new IAE(\"Either uri xor uriPrefix required\");\n    }\n    this.namespaceParseSpec = Preconditions.checkNotNull(namespaceParseSpec, \"namespaceParseSpec\");\n    if (pollPeriod == null) {\n      // Warning because if UriExtractionNamespace is being used for lookups, any updates to the database will not\n      // be picked up after the node starts. So for use casses where nodes start at different times (like streaming\n      // ingestion with peons) there can be data inconsistencies across the cluster.\n      LOG.warn(\"No pollPeriod configured for UriExtractionNamespace - entries will be loaded only once at startup\");\n      this.pollPeriod = Period.ZERO;\n    } else {\n      this.pollPeriod = pollPeriod;\n    }\n    this.fileRegex = fileRegex == null ? versionRegex : fileRegex;\n    if (fileRegex != null && versionRegex != null) {\n      throw new IAE(\"Cannot specify both versionRegex and fileRegex. versionRegex is deprecated\");\n    }\n\n    if (uri != null && this.fileRegex != null) {\n      throw new IAE(\"Cannot define both uri and fileRegex\");\n    }\n\n    if (this.fileRegex != null) {\n      try {\n        Pattern.compile(this.fileRegex);\n      }\n      catch (PatternSyntaxException ex) {\n        throw new IAE(ex, \"Could not parse `fileRegex` [%s]\", this.fileRegex);\n      }\n    }\n    this.maxHeapPercentage = maxHeapPercentage == null ? DEFAULT_MAX_HEAP_PERCENTAGE : maxHeapPercentage;\n  }\n\n  public String getFileRegex()\n  {\n    return fileRegex;\n  }\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/lookups-cached-global/src/main/java/org/apache/druid/query/lookup/namespace/UriExtractionNamespace.java#L107-L143","documentation":"fileRegex (a filename filter pattern) can only be used with uriPrefix-based loading, where multiple files are listed and filtered. When a single `uri` is given together with a fileRegex, the constructor throws this IAE because a regex makes no sense for a single explicitly named file.","triggerScenarios":"Constructing UriExtractionNamespace with `uri` set (non-null) and a non-null fileRegex (or deprecated versionRegex, which is folded into fileRegex).","commonSituations":"Configs that previously used uriPrefix switched to a single uri without removing fileRegex; users adding a filter \"just in case\" to a single-file lookup; generated configs that always emit fileRegex.","solutions":["Remove the `fileRegex` field from the lookup config when using `uri`.","If filtering is actually needed, switch from `uri` to `uriPrefix` and keep the regex.","Fix generators/templates to emit fileRegex only for prefix-based lookups.","For the deprecated path, also ensure versionRegex is not set, since it maps onto fileRegex."],"exampleFix":"// before\n{\"uri\":\"file:///data/l.csv\", \"fileRegex\":\".*csv\"}\n// after\n{\"uri\":\"file:///data/l.csv\"}","handlingStrategy":"validation","validationCode":"// java\nif (cfg.hasNonNull(\"uri\") && cfg.hasNonNull(\"fileRegex\")) {\n  throw new IllegalArgumentException(\"fileRegex requires uriPrefix, not uri\");\n}","typeGuard":null,"tryCatchPattern":"// java\ntry { mapper.readValue(json, UriExtractionNamespace.class); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().equals(\"Cannot define both uri and fileRegex\")) { /* remove one */ }\n}","preventionTips":["Use fileRegex only with uriPrefix-based lookups.","Schema-validate lookup JSON: uri is incompatible with fileRegex.","When switching to a single-file uri, remove filters."],"tags":["lookup","configuration","validation","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}