{"record":{"id":"7b4d3f8d0a75c96d","repo":"apache/druid","slug":"duplicate-output-name-s-7b4d3f","errorCode":null,"errorMessage":"Duplicate output name[%s]","messagePattern":"Duplicate output name\\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/groupby/GroupByQuery.java","lineNumber":900,"sourceCode":"      return this;\n    }\n    final List<AggregatorFactory> optimizedAggs = new ArrayList<>(aggregatorSpecs.size());\n    for (AggregatorFactory aggregatorFactory : aggregatorSpecs) {\n      optimizedAggs.add(aggregatorFactory.optimizeForSegment(optimizationContext));\n    }\n    return withAggregatorSpecs(optimizedAggs);\n  }\n\n  private static void verifyOutputNames(\n      List<DimensionSpec> dimensions,\n      List<AggregatorFactory> aggregators,\n      List<PostAggregator> postAggregators\n  )\n  {\n    final Set<String> outputNames = new HashSet<>();\n    for (DimensionSpec dimension : dimensions) {\n      if (!outputNames.add(dimension.getOutputName())) {\n        throw new IAE(\"Duplicate output name[%s]\", dimension.getOutputName());\n      }\n    }\n\n    for (AggregatorFactory aggregator : aggregators) {\n      if (!outputNames.add(aggregator.getName())) {\n        throw new IAE(\"Duplicate output name[%s]\", aggregator.getName());\n      }\n    }\n\n    for (PostAggregator postAggregator : postAggregators) {\n      if (!outputNames.add(postAggregator.getName())) {\n        throw new IAE(\"Duplicate output name[%s]\", postAggregator.getName());\n      }\n    }\n\n    if (outputNames.contains(ColumnHolder.TIME_COLUMN_NAME)) {\n      throw new IAE(\n          \"'%s' cannot be used as an output name for dimensions, aggregators, or post-aggregators.\",","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/groupby/GroupByQuery.java#L882-L918","documentation":"The GroupByQuery constructor validates that all dimension output names are unique across the whole query. Adding a second dimension whose getOutputName() duplicates an already-seen name throws IAE 'Duplicate output name[%s]'.","triggerScenarios":"Building a GroupByQuery (or deserializing JSON) with two dimensions resolving to the same output name, e.g. two DefaultDimensionSpecs with the same outputName, or a dimension whose outputName duplicates another dimension's.","commonSituations":"Copy-pasted dimension specs in hand-written JSON queries; programmatic query builders appending dimensions without name checks; column aliasing mistakes (same alias used twice).","solutions":["Rename one dimension's outputName so each is unique","Use a different extraction/alias for the duplicate dimension or drop the redundant one","If the same underlying column is needed twice with different logic, give each spec a distinct outputName"],"exampleFix":"// before\nnew DefaultDimensionSpec(\"page\", \"page\"), new DefaultDimensionSpec(\"page\", \"page\")\n// after\nnew DefaultDimensionSpec(\"page\", \"page\"), new DefaultDimensionSpec(\"page\", \"page2\")","handlingStrategy":"validation","validationCode":"Set<String> names = new HashSet<>(); for (DimensionSpec d : dims) { if (!names.add(d.getOutputName())) throw new IllegalArgumentException(\"Duplicate dimension output name: \" + d.getOutputName()); }","typeGuard":"null","tryCatchPattern":"try { new GroupByQuery.Builder()...build(); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Duplicate output name\")) { /* fix query spec */ } throw e; }","preventionTips":["Deduplicate dimension aliases when building queries programmatically","Use distinct outputNames when aliasing the same column multiple times"],"tags":["groupby","duplicate-name","query-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}