apache/druid · error · IllegalArgumentException

Comparing histograms is not supported

Error message

Comparing histograms is not supported

What it means

KllDoublesSketchToHistogramPostAggregator.getComparator always throws IllegalArgumentException because a histogram (array of bin counts) has no defined ordering. The post-aggregator interface requires a comparator, but comparing histograms is intentionally unsupported.

Source

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

  @JsonProperty
  @JsonInclude(JsonInclude.Include.NON_NULL)
  public double[] getSplitPoints()
  {
    return splitPoints;
  }

  @JsonProperty
  @JsonInclude(JsonInclude.Include.NON_NULL)
  public Integer getNumBins()
  {
    return numBins;
  }

  @Override
  public Comparator<double[]> getComparator()
  {
    throw new IAE("Comparing histograms is not supported");
  }

  @Override
  public Set<String> getDependentFields()
  {
    return field.getDependentFields();
  }

  @Override
  public String toString()
  {
    return getClass().getSimpleName() + "{" +
        "name='" + name + '\'' +
        ", field=" + field +
        ", splitPoints=" + Arrays.toString(splitPoints) +
        ", numBins=" + numBins +
        "}";
  }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Do not sort on the histogram output; sort by a scalar such as a quantile or the underlying metric
  2. Compute a single statistic (e.g. kllDoublesSketchToQuantiles with a fraction) and order by that
  3. Guard generic code: check whether the post-aggregator supports comparison before calling getComparator

Example fix

// before
ORDER BY histogramOutput
// after
ORDER BY median  -- from kllDoublesSketchToQuantiles with fraction 0.5
Defensive patterns

Strategy: validation

Validate before calling

if (postAgg instanceof KllDoublesSketchToHistogramPostAggregator) {
  throw new IllegalArgumentException("Histogram output is not sortable");
}

Try / catch

try { cmp = postAgg.getComparator(); } catch (IllegalArgumentException e) { cmp = null; /* disable sorting for this column */ }

Prevention

When it happens

Trigger: Any code path that requests ordering of this post-aggregator's output, e.g. ORDER BY on the histogram column, or framework code that calls getComparator() to sort results.

Common situations: Sorting query output by the histogram column; generic post-aggregator processing that assumes every comparator is valid; building derived queries that order on array-valued post-aggregators.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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