apache/druid · error · IllegalArgumentException

Should only have one interval, got

Error message

Should only have one interval, got[%s]

What it means

SearchStrategy's constructor converts the query filter to CNF and requires the query's querySegmentSpec to contain exactly one interval; otherwise it throws IAE('Should only have one interval, got[...]'). Search strategies index-scan a single segment interval, so multi-interval specs are unsupported there. Multi-interval segment specs on a search query trigger it.

Solutions

  1. Provide exactly one interval in the query's querySegmentSpec
  2. Split a multi-range request into separate search queries, one per interval
  3. Use the default interval spec (MaxTimeSpec / universal) if you don't need a time bound

Example fix

// before
new MultipleIntervalSegmentSpec(ImmutableList.of(i1, i2))
// after
new MultipleIntervalSegmentSpec(ImmutableList.of(i1)) // or issue one query per interval
Defensive patterns

Strategy: validation

Validate before calling

List<Interval> intervals = query.getQuerySegmentSpec().getIntervals(); if (intervals.size() != 1) { throw new IllegalArgumentException("search query requires exactly one interval, got " + intervals.size()); }

Type guard

boolean hasSingleInterval(SearchQuery q) { return q.getQuerySegmentSpec().getIntervals().size() == 1; }

Try / catch

try { return strategy.strategize(query).getExecutionPlan(query, segment); } catch (IAE e) { if (e.getMessage().startsWith("Should only have one interval")) { splitAndRetryPerInterval(); } else throw e; }

Prevention

When it happens

Trigger: Submitting a search query whose 'intervals' list has zero or multiple entries; programmatic construction of SearchQuery with a multiple-interval QuerySegmentSpec; query rewriting that splits intervals.

Common situations: Hand-built search queries with several time ranges; tools generating interval lists generically for all query types; callers translating time-series-style multi-interval specs to search queries.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/query/search/SearchStrategy.java:54

import org.joda.time.Interval;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public abstract class SearchStrategy
{
  protected final Filter filter;
  protected final Interval interval;

  protected SearchStrategy(SearchQuery query)
  {
    this.filter = Filters.convertToCNFFromQueryContext(query, Filters.toFilter(query.getDimensionsFilter()));
    final List<Interval> intervals = query.getQuerySegmentSpec().getIntervals();
    if (intervals.size() != 1) {
      throw new IAE("Should only have one interval, got[%s]", intervals);
    }
    this.interval = intervals.get(0);
  }

  public abstract List<SearchQueryExecutor> getExecutionPlan(SearchQuery query, Segment segment);

  static List<DimensionSpec> getDimsToSearch(Segment segment, List<DimensionSpec> dimensions)
  {
    if (dimensions == null || dimensions.isEmpty()) {
      final Set<String> dims = new LinkedHashSet<>();
      final QueryableIndex index = segment.as(QueryableIndex.class);
      if (index != null) {
        for (String dim : index.getAvailableDimensions()) {
          dims.add(dim);
        }
      } else {
        // fallback to RowSignature and Metadata if QueryableIndex not available
        final Metadata metadata = segment.as(Metadata.class);

View on GitHub (pinned to 9b90983fd2)