{"record":{"id":"af4b9e49d2416e83","repo":"apache/druid","slug":"duplicate-output-name-s","errorCode":null,"errorMessage":"Duplicate output name[%s]","messagePattern":"Duplicate output name\\[(.+?)\\]","errorType":"validation","errorClass":"IAE","httpStatus":null,"severity":"error","filePath":"extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/MovingAverageQuery.java","lineNumber":167,"sourceCode":"          postProcFn,\n          sequence -> Sequences.filter(sequence, MovingAverageQuery.this.havingSpec::eval)\n      );\n    }\n\n    this.limitFn = postProcFn;\n  }\n\n  private static void verifyOutputNames(\n      List<DimensionSpec> dimensions,\n      List<AggregatorFactory> aggregators,\n      List<PostAggregator> postAggregators\n  )\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\n  /**\n   * A private constructor that avoids all of the various state checks.  Used by the with*() methods where the checks","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/MovingAverageQuery.java#L149-L185","documentation":"MovingAverageQuery.verifyOutputNames enforces that every dimension output name is unique across the query result signature. When two DimensionSpec entries resolve to the same output name, the constructor throws IllegalArgumentException with 'Duplicate output name'.","triggerScenarios":"Constructing a MovingAverageQuery (via JSON or Java API) whose dimensions list contains two DimensionSpecs with the same getOutputName(), e.g. two specs on different columns both defaulting their output name to the column name or both using the same explicit outputName.","commonSituations":"Hand-written JSON queries where a dimension is listed twice, programmatic query building that appends dimensions without deduplication, or group-by dimensions where one spec's outputName collides with another (e.g. extraction specs sharing a default output name).","solutions":["Remove or rename the duplicate dimension so each DimensionSpec has a unique outputName","Set a distinct outputName on the colliding DimensionSpec (e.g. new DimensionSpec(column, \"alias\", extractionFn))","Deduplicate the dimensions list before constructing the query"],"exampleFix":"// before\n\"dimensions\": [\"country\", {\"type\": \"default\", \"dimension\": \"country\", \"outputName\": \"country\"}]\n// after\n\"dimensions\": [\"country\", {\"type\": \"default\", \"dimension\": \"region\", \"outputName\": \"region\"}]","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (DimensionSpec d : dimensions) {\n  if (!seen.add(d.getOutputName())) throw new IllegalArgumentException(\"Duplicate dimension: \" + d.getOutputName());\n}","typeGuard":null,"tryCatchPattern":"try { MovingAverageQuery q = new MovingAverageQuery(...); } catch (IllegalArgumentException e) { log.error(\"Invalid query dimensions: {}\", e.getMessage()); }","preventionTips":["Deduplicate dimension output names when building queries programmatically","Always set explicit unique outputName on DimensionSpecs","Review hand-written query JSON for repeated dimension columns"],"tags":["java","query-validation","duplicate-names"],"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-14T05:17:10.506Z"}