{"record":{"id":"eb3bec314ebffcd7","repo":"apache/druid","slug":"aggregatorfactorynotmergeableexception-this-other-eb3bec","errorCode":null,"errorMessage":"AggregatorFactoryNotMergeableException(this, other)","messagePattern":"AggregatorFactoryNotMergeableException\\(this, other\\)","errorType":"exception","errorClass":"AggregatorFactoryNotMergeableException","httpStatus":500,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllFloatsSketchAggregatorFactory.java","lineNumber":98,"sourceCode":"  {\n    return COMPARATOR;\n  }\n\n  @Override\n  public AggregatorFactory getMergingFactory(final AggregatorFactory other)\n      throws AggregatorFactoryNotMergeableException\n  {\n    if (other.getName().equals(this.getName()) && other instanceof KllFloatsSketchAggregatorFactory) {\n      // KllSketch supports merging with different k.\n      // The result will have effective k between the specified k and the minimum k from all input sketches\n      // to achieve higher accuracy as much as possible.\n      return new KllFloatsSketchMergeAggregatorFactory(\n          getName(),\n          Math.max(getK(), ((KllFloatsSketchAggregatorFactory) other).getK()),\n          Math.max(getMaxStreamLength(), ((KllFloatsSketchAggregatorFactory) other).getMaxStreamLength())\n      );\n    } else {\n      throw new AggregatorFactoryNotMergeableException(this, other);\n    }\n  }\n\n  @Override\n  public AggregatorFactory getCombiningFactory()\n  {\n    return new KllFloatsSketchMergeAggregatorFactory(getName(), getK(), getMaxStreamLength());\n  }\n\n  @Override\n  KllFloatsSketch getEmptySketch()\n  {\n    return KllFloatsSketchOperations.EMPTY_SKETCH;\n  }\n\n  @Override\n  KllFloatsSketch newHeapInstance(final int k)\n  {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllFloatsSketchAggregatorFactory.java#L80-L116","documentation":"KllFloatsSketchAggregatorFactory.getMergingFactory throws AggregatorFactoryNotMergeableException when the other factory is not a KllFloatsSketchAggregatorFactory. Merge operations require both factories to produce the same sketch kind, since merging combines partial sketches of identical type and parameters.","triggerScenarios":"Calling getMergingFactory with a non-KllFloatsSketch factory (e.g. KllDoublesSketchAggregatorFactory or quantiles FloatsSketch factory); queries that mix kllFloatsSketch with other aggregator types where Druid must merge partial aggregation state across segments.","commonSituations":"Distributed queries spanning segments where incompatible sketch aggregators with the same output name get merged; typos in aggregation 'type' (kllDoublesSketch vs kllFloatsSketch); mixing legacy quantiles FloatsSketch columns with KLL ones in one query.","solutions":["Use kllFloatsSketch aggregators consistently for columns that must merge; fix 'type' typos in the aggregation spec","Give incompatible aggregators distinct output names so they are never merged together","Separate legacy and KLL aggregations into different queries, or re-ingest to a uniform sketch type"],"exampleFix":"// before\n{ \"type\": \"kllDoublesSketch\", \"name\": \"s\", \"fieldName\": \"v\" }, { \"type\": \"kllFloatsSketch\", \"name\": \"s\", \"fieldName\": \"v2\" }\n// after\n{ \"type\": \"kllFloatsSketch\", \"name\": \"s1\", \"fieldName\": \"v\" }, { \"type\": \"kllFloatsSketch\", \"name\": \"s2\", \"fieldName\": \"v2\" }","handlingStrategy":"validation","validationCode":"if (!(other instanceof KllFloatsSketchAggregatorFactory)) {\n  throw new IllegalArgumentException(\"Cannot merge \" + other.getClass() + \" with KllFloatsSketchAggregatorFactory\");\n}","typeGuard":"boolean mergeable(AggregatorFactory f) { return f instanceof KllFloatsSketchAggregatorFactory; }","tryCatchPattern":"try { merged = factory.getMergingFactory(other); } catch (AggregatorFactoryNotMergeableException e) { log.error(\"Cannot merge aggregators\", e); }","preventionTips":["Standardize on kllFloatsSketch for float sketch columns","Audit aggregation specs for type mismatches before distributed queries","Use distinct output names for genuinely different aggregators"],"tags":["druid","datasketches","kll","aggregation"],"backgroundTag":"incompatible-source-type","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}