apache/druid · error · AggregatorFactoryNotMergeableException

AggregatorFactoryNotMergeableException(this, other)

Error message

AggregatorFactoryNotMergeableException(this, other)

What it means

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.

Source

Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchAggregatorFactory.java:98

  {
    return COMPARATOR;
  }

  @Override
  public AggregatorFactory getMergingFactory(final AggregatorFactory other)
      throws AggregatorFactoryNotMergeableException
  {
    if (other.getName().equals(this.getName()) && other instanceof KllDoublesSketchAggregatorFactory) {
      // KllSketch supports merging with different k.
      // The result will have effective k between the specified k and the minimum k from all input sketches
      // to achieve higher accuracy as much as possible.
      return new KllDoublesSketchMergeAggregatorFactory(
          getName(),
          Math.max(getK(), ((KllDoublesSketchAggregatorFactory) other).getK()),
          Math.max(getMaxStreamLength(), ((KllDoublesSketchAggregatorFactory) other).getMaxStreamLength())
      );
    } else {
      throw new AggregatorFactoryNotMergeableException(this, other);
    }
  }

  @Override
  public AggregatorFactory getCombiningFactory()
  {
    return new KllDoublesSketchMergeAggregatorFactory(getName(), getK(), getMaxStreamLength());
  }

  @Override
  KllDoublesSketch getEmptySketch()
  {
    return KllDoublesSketchOperations.EMPTY_SKETCH;
  }

  @Override
  KllDoublesSketch newHeapInstance(final int k)
  {

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Ensure both aggregators being merged are kllDoublesSketch aggregators on the same field family; use one aggregator per query for merging to succeed
  2. Check the 'type' field in the aggregation spec for typos (e.g. 'kllFloatsSketch' vs 'kllDoublesSketch')
  3. If migrating from quantiles DoublesSketch to KLL, re-ingest or keep the aggregators in separate queries
  4. Wrap the query merge path with a check that factory.getClass() matches before calling getMergingFactory

Example fix

// before
{ "type": "kllFloatsSketch", "name": "s", "fieldName": "v" }, { "type": "kllDoublesSketch", "name": "s2", "fieldName": "v" }
// after
{ "type": "kllDoublesSketch", "name": "s", "fieldName": "v" }, { "type": "kllDoublesSketch", "name": "s2", "fieldName": "v" }
Defensive patterns

Strategy: validation

Validate before calling

if (!(other instanceof KllDoublesSketchAggregatorFactory)) {
  throw new IllegalArgumentException("Cannot merge " + other.getClass() + " with KllDoublesSketchAggregatorFactory");
}

Type guard

boolean mergeable(AggregatorFactory f) { return f instanceof KllDoublesSketchAggregatorFactory; }

Try / catch

try { merged = factory.getMergingFactory(other); } catch (AggregatorFactoryNotMergeableException e) { log.error("Incompatible aggregators: {} vs {}", e, other); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/dbe76da4bfd31502. Report an issue: GitHub.