{"record":{"id":"5acbc406efd5127e","repo":"apache/druid","slug":"aggregatorfactorynotmergeableexception-5acbc4","errorCode":null,"errorMessage":"AggregatorFactoryNotMergeableException","messagePattern":"AggregatorFactoryNotMergeableException","errorType":"exception","errorClass":"AggregatorFactoryNotMergeableException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/SimpleLongAggregatorFactory.java","lineNumber":186,"sourceCode":"  {\n    return object;\n  }\n\n  @Override\n  public List<String> requiredFields()\n  {\n    return fieldName != null\n           ? Collections.singletonList(fieldName)\n           : fieldExpression.get().analyzeInputs().getRequiredBindingsList();\n  }\n\n  @Override\n  public AggregatorFactory getMergingFactory(AggregatorFactory other) throws AggregatorFactoryNotMergeableException\n  {\n    if (other.getName().equals(this.getName()) && this.getClass() == other.getClass()) {\n      return getCombiningFactory();\n    } else {\n      throw new AggregatorFactoryNotMergeableException(this, other);\n    }\n  }\n\n  @Override\n  public int hashCode()\n  {\n    return Objects.hash(fieldName, expression, name);\n  }\n\n  @Override\n  public boolean equals(Object o)\n  {\n    if (this == o) {\n      return true;\n    }\n    if (o == null || getClass() != o.getClass()) {\n      return false;\n    }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/SimpleLongAggregatorFactory.java#L168-L204","documentation":"SimpleLongAggregatorFactory.getMergingFactory throws AggregatorFactoryNotMergeableException when the other factory has a different name or a different class. Native queries merge partial aggregation results from each segment; this only works if both factories are identical long-based aggregators with the same output name. The exception tells the planner it cannot produce a combined factory.","triggerScenarios":"Query fan-out across segments/subqueries where the same output name maps to a SimpleLongAggregatorFactory on one side and a different aggregator class or name on the other, causing merge code to call getMergingFactory.","commonSituations":"Subquery/outer query with mismatched long aggregation names; ingestion specs changed a metric from long to float/double over time; inline datasources (JOIN results) that don't carry the same aggregator setup as base segments.","solutions":["Ensure both sides use the same output name for the long aggregator","Use identical long aggregator classes (longSum/longMin/longMax/longFirst/longAny) on both sides","Rewrite the query to align inner and outer aggregations, or let the subquery perform its own final aggregation (use finalizeOuterAggregate=true where appropriate)","Re-ingest or normalize schema if historical segments use a different metric type under the same name"],"exampleFix":"// before\n inner:  longSum s ; outer: doubleSum s\n// after\n inner:  longSum s ; outer: longSum s (or rename the outer metric)","handlingStrategy":"validation","validationCode":"boolean mergeable(AggregatorFactory a, AggregatorFactory b) {\n  return a.getName().equals(b.getName()) && a.getClass() == b.getClass();\n}","typeGuard":"boolean isMergeableLongPair(AggregatorFactory other, SimpleLongAggregatorFactory self) {\n  return other instanceof SimpleLongAggregatorFactory && other.getName().equals(self.getName());\n}","tryCatchPattern":"try {\n  AggregatorFactory merged = factory.getMergingFactory(other);\n} catch (AggregatorFactoryNotMergeableException e) {\n  LOGGER.warn(e, \"Non-mergeable long aggregators: %s vs %s\", e.getFactory1(), e.getFactory2());\n}","preventionTips":["Align long aggregation names between inner and outer queries","Avoid mixing long/float/double aggregators under one output name","Normalize schema across segments (or re-ingest) when metric types change","Prefer letting subqueries finalize their own aggregation instead of cross-layer merging"],"tags":["aggregation","mergeability","druid"],"backgroundTag":"aggregator-factory-not-mergeable","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"}