apache/druid · error · IllegalArgumentException
Cannot define both uri and fileRegex
Error message
Cannot define both uri and fileRegex
What it means
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.
Source
Thrown at extensions-core/lookups-cached-global/src/main/java/org/apache/druid/query/lookup/namespace/UriExtractionNamespace.java:125
throw new IAE("Either uri xor uriPrefix required");
}
this.namespaceParseSpec = Preconditions.checkNotNull(namespaceParseSpec, "namespaceParseSpec");
if (pollPeriod == null) {
// Warning because if UriExtractionNamespace is being used for lookups, any updates to the database will not
// be picked up after the node starts. So for use casses where nodes start at different times (like streaming
// ingestion with peons) there can be data inconsistencies across the cluster.
LOG.warn("No pollPeriod configured for UriExtractionNamespace - entries will be loaded only once at startup");
this.pollPeriod = Period.ZERO;
} else {
this.pollPeriod = pollPeriod;
}
this.fileRegex = fileRegex == null ? versionRegex : fileRegex;
if (fileRegex != null && versionRegex != null) {
throw new IAE("Cannot specify both versionRegex and fileRegex. versionRegex is deprecated");
}
if (uri != null && this.fileRegex != null) {
throw new IAE("Cannot define both uri and fileRegex");
}
if (this.fileRegex != null) {
try {
Pattern.compile(this.fileRegex);
}
catch (PatternSyntaxException ex) {
throw new IAE(ex, "Could not parse `fileRegex` [%s]", this.fileRegex);
}
}
this.maxHeapPercentage = maxHeapPercentage == null ? DEFAULT_MAX_HEAP_PERCENTAGE : maxHeapPercentage;
}
public String getFileRegex()
{
return fileRegex;
}
View on GitHub (pinned to 9b90983fd2)
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.
Example fix
// before
{"uri":"file:///data/l.csv", "fileRegex":".*csv"}
// after
{"uri":"file:///data/l.csv"} Defensive patterns
Strategy: validation
Validate before calling
// java
if (cfg.hasNonNull("uri") && cfg.hasNonNull("fileRegex")) {
throw new IllegalArgumentException("fileRegex requires uriPrefix, not uri");
} Try / catch
// java
try { mapper.readValue(json, UriExtractionNamespace.class); }
catch (IllegalArgumentException e) {
if (e.getMessage().equals("Cannot define both uri and fileRegex")) { /* remove one */ }
} Prevention
- 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.
When it happens
Trigger: Constructing UriExtractionNamespace with `uri` set (non-null) and a non-null fileRegex (or deprecated versionRegex, which is folded into fileRegex).
Common situations: 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.
Related errors
- Either uri xor uriPrefix required
- Cannot specify both versionRegex and fileRegex. versionRegex
- Could not parse `fileRegex` [%s]
- Set only one of 'key' or 'sharedAccessStorageToken' or 'useA
- Invalid pod adapter [%s], only pod adapter [%s] can be speci
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/9bec3dc007f8ab23.
Report an issue: GitHub.