{"record":{"id":"7e3743e55e9fe653","repo":"apache/druid","slug":"specify-exactly-one-of-interval-and-segments","errorCode":null,"errorMessage":"Specify exactly one of 'interval' and 'segments'","messagePattern":"Specify exactly one of 'interval' and 'segments'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"indexing-service/src/main/java/org/apache/druid/indexing/input/DruidInputSource.java","lineNumber":211,"sourceCode":"  }\n\n  private DruidInputSource(\n      final String dataSource,\n      @Nullable Interval interval,\n      @Nullable List<WindowedSegmentId> segmentIds,\n      DimFilter dimFilter,\n      List<String> dimensions,\n      List<String> metrics,\n      IndexIO indexIO,\n      CoordinatorClient coordinatorClient,\n      SegmentCacheManagerFactory segmentCacheManagerFactory,\n      TaskConfig taskConfig,\n      @Nullable TaskToolbox toolbox\n  )\n  {\n    Preconditions.checkNotNull(dataSource, \"dataSource\");\n    if ((interval == null && segmentIds == null) || (interval != null && segmentIds != null)) {\n      throw new IAE(\"Specify exactly one of 'interval' and 'segments'\");\n    }\n    this.dataSource = dataSource;\n    this.interval = interval;\n    this.segmentIds = segmentIds;\n    this.dimFilter = dimFilter;\n    this.dimensions = dimensions;\n    this.metrics = metrics;\n    this.indexIO = Preconditions.checkNotNull(indexIO, \"null IndexIO\");\n    this.coordinatorClient = Preconditions.checkNotNull(coordinatorClient, \"null CoordinatorClient\");\n    this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, \"null segmentCacheManagerFactory\");\n    this.taskConfig = Preconditions.checkNotNull(taskConfig, \"null taskConfig\");\n    this.toolbox = toolbox;\n  }\n\n  @JsonIgnore\n  @Nonnull\n  @Override\n  public Set<String> getTypes()","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/indexing-service/src/main/java/org/apache/druid/indexing/input/DruidInputSource.java#L193-L229","documentation":"DruidInputSource's constructor validates that exactly one of the 'interval' and 'segments' properties is supplied when reading from a Druid datasource. Passing both, or neither, makes the segment selection ambiguous, so it throws IllegalArgumentException at construction time.","triggerScenarios":"Constructing DruidInputSource (e.g. from a DruidInputSourceSerDe JSON spec in a reindex/compaction task) with both 'interval' and 'segments' set, or with both null.","commonSituations":"Copy-pasting a reindex spec and adding 'segments' while forgetting to remove 'interval'; building specs programmatically and leaving both fields null; template reuse carrying over an interval.","solutions":["Remove the 'interval' field from the inputSource spec if you intend to read specific segments via 'segments'.","Remove the 'segments' field if you intend to read a time range via 'interval'.","To read everything, keep exactly one field covering the full range (e.g. a wide interval)."],"exampleFix":"// before\n\"inputSource\": {\"type\":\"druid\",\"dataSource\":\"wikipedia\",\"interval\":\"2020-01-01/2020-02-01\",\"segments\":[\"wikipedia_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2020-01-02T01:00:00.000Z_1\"]}\n// after\n\"inputSource\": {\"type\":\"druid\",\"dataSource\":\"wikipedia\",\"segments\":[\"wikipedia_2020-01-01T00:00:00.000Z_2020-01-02T00:00:00.000Z_2020-01-02T01:00:00.000Z_1\"]}","handlingStrategy":"validation","validationCode":"boolean hasInterval = spec.getInterval() != null;\nboolean hasSegments = spec.getSegments() != null && !spec.getSegments().isEmpty();\nif (hasInterval == hasSegments) {\n  throw new IllegalArgumentException(\"Specify exactly one of 'interval' and 'segments'\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  DruidInputSource s = jsonMapper.readValue(specJson, DruidInputSource.class);\n} catch (IllegalArgumentException e) {\n  // fix inputSource spec: keep only 'interval' or only 'segments'\n}","preventionTips":["When targeting specific segments, delete the 'interval' key rather than leaving both.","Validate inputSource JSON with the Jackson mapper before submitting the task.","Build specs with mutually exclusive setters that clear the sibling field."],"tags":["druid","input-source","validation","illegal-argument"],"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"}