apache/druid · error · AggregatorFactoryNotMergeableException

AggregatorFactoryNotMergeableException(this, other)

Error message

AggregatorFactoryNotMergeableException(this, other)

What it means

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.

Source

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

  {
    return COMPARATOR;
  }

  @Override
  public AggregatorFactory getMergingFactory(final AggregatorFactory other)
      throws AggregatorFactoryNotMergeableException
  {
    if (other.getName().equals(this.getName()) && other instanceof KllFloatsSketchAggregatorFactory) {
      // 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 KllFloatsSketchMergeAggregatorFactory(
          getName(),
          Math.max(getK(), ((KllFloatsSketchAggregatorFactory) other).getK()),
          Math.max(getMaxStreamLength(), ((KllFloatsSketchAggregatorFactory) other).getMaxStreamLength())
      );
    } else {
      throw new AggregatorFactoryNotMergeableException(this, other);
    }
  }

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

  @Override
  KllFloatsSketch getEmptySketch()
  {
    return KllFloatsSketchOperations.EMPTY_SKETCH;
  }

  @Override
  KllFloatsSketch newHeapInstance(final int k)
  {

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use kllFloatsSketch aggregators consistently for columns that must merge; fix 'type' typos in the aggregation spec
  2. Give incompatible aggregators distinct output names so they are never merged together
  3. Separate legacy and KLL aggregations into different queries, or re-ingest to a uniform sketch type

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

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

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

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/eb3bec314ebffcd7. Report an issue: GitHub.