{"record":{"id":"dbe76da4bfd31502","repo":"apache/druid","slug":"aggregatorfactorynotmergeableexception-this-other","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/KllDoublesSketchAggregatorFactory.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 KllDoublesSketchAggregatorFactory) {\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 KllDoublesSketchMergeAggregatorFactory(\n          getName(),\n          Math.max(getK(), ((KllDoublesSketchAggregatorFactory) other).getK()),\n          Math.max(getMaxStreamLength(), ((KllDoublesSketchAggregatorFactory) other).getMaxStreamLength())\n      );\n    } else {\n      throw new AggregatorFactoryNotMergeableException(this, other);\n    }\n  }\n\n  @Override\n  public AggregatorFactory getCombiningFactory()\n  {\n    return new KllDoublesSketchMergeAggregatorFactory(getName(), getK(), getMaxStreamLength());\n  }\n\n  @Override\n  KllDoublesSketch getEmptySketch()\n  {\n    return KllDoublesSketchOperations.EMPTY_SKETCH;\n  }\n\n  @Override\n  KllDoublesSketch 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/KllDoublesSketchAggregatorFactory.java#L80-L116","documentation":"KllDoublesSketchAggregatorFactory.getMergingFactory throws AggregatorFactoryNotMergeableException when asked to produce a merged factory with an aggregator factory of a different/incompatible type. Merging only works between factories of the same sketch aggregation type, since the merged factory must combine sketches of the same kind and parameters. This typically surfaces during query fan-out (distributed) processing when merging partial results from segments.","triggerScenarios":"Calling getMergingFactory(AggregatorFactory other) where other is not an instance of KllDoublesSketchAggregatorFactory (e.g. a KllFloatsSketchAggregatorFactory, quantiles DoublesSketch factory, or any unrelated aggregator). Also occurs when mixing sketch types in a query whose results must be merged across segments or subqueries.","commonSituations":"Mixing kllDoublesSketch and kllFloatsSketch aggregators that Druid tries to merge in a distributed (native) query with multiple segments or two-level query processing; upgrading from the older quantiles DoublesSketch extension to KLL and combining old/new aggregation columns in one query.","solutions":["Ensure both aggregators being merged are kllDoublesSketch aggregators on the same field family; use one aggregator per query for merging to succeed","Check the 'type' field in the aggregation spec for typos (e.g. 'kllFloatsSketch' vs 'kllDoublesSketch')","If migrating from quantiles DoublesSketch to KLL, re-ingest or keep the aggregators in separate queries","Wrap the query merge path with a check that factory.getClass() matches before calling getMergingFactory"],"exampleFix":"// before\n{ \"type\": \"kllFloatsSketch\", \"name\": \"s\", \"fieldName\": \"v\" }, { \"type\": \"kllDoublesSketch\", \"name\": \"s2\", \"fieldName\": \"v\" }\n// after\n{ \"type\": \"kllDoublesSketch\", \"name\": \"s\", \"fieldName\": \"v\" }, { \"type\": \"kllDoublesSketch\", \"name\": \"s2\", \"fieldName\": \"v\" }","handlingStrategy":"validation","validationCode":"if (!(other instanceof KllDoublesSketchAggregatorFactory)) {\n  throw new IllegalArgumentException(\"Cannot merge \" + other.getClass() + \" with KllDoublesSketchAggregatorFactory\");\n}","typeGuard":"boolean mergeable(AggregatorFactory f) { return f instanceof KllDoublesSketchAggregatorFactory; }","tryCatchPattern":"try { merged = factory.getMergingFactory(other); } catch (AggregatorFactoryNotMergeableException e) { log.error(\"Incompatible aggregators: {} vs {}\", e, other); }","preventionTips":["Use one sketch type consistently per output column in aggregation specs","Review aggregation specs for kllDoublesSketch vs kllFloatsSketch typos before submitting queries","Give conflicting aggregators unique output names to avoid implicit merging"],"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-14T05:17:10.506Z"}