{"record":{"id":"54bbbcdcf9658bf1","repo":"apache/druid","slug":"comparing-sketch-summaries-is-not-supported-54bbbc","errorCode":null,"errorMessage":"Comparing sketch summaries is not supported","messagePattern":"Comparing sketch summaries is not supported","errorType":"exception","errorClass":"org.apache.druid.java.util.common.IAE","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/DoublesSketchToStringPostAggregator.java","lineNumber":83,"sourceCode":"  }\n\n  @JsonProperty\n  public PostAggregator getField()\n  {\n    return field;\n  }\n\n  @Override\n  public Object compute(final Map<String, Object> combinedAggregators)\n  {\n    final DoublesSketch sketch = (DoublesSketch) field.compute(combinedAggregators);\n    return sketch.toString();\n  }\n\n  @Override\n  public Comparator<String> getComparator()\n  {\n    throw new IAE(\"Comparing sketch summaries is not supported\");\n  }\n\n  @Override\n  public byte[] getCacheKey()\n  {\n    final CacheKeyBuilder builder = new CacheKeyBuilder(\n        AggregatorUtil.QUANTILES_DOUBLES_SKETCH_TO_STRING_CACHE_TYPE_ID).appendCacheable(field);\n    return builder.build();\n  }\n\n  @Override\n  public PostAggregator decorate(final Map<String, AggregatorFactory> map)\n  {\n    return this;\n  }\n\n  @Override\n  public Set<String> getDependentFields()","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/DoublesSketchToStringPostAggregator.java#L65-L101","documentation":"DoublesSketchToStringPostAggregator outputs a human-readable sketch summary String. Strings could be compared alphabetically, but the summary is diagnostic text whose ordering is meaningless, so getComparator() deliberately throws IllegalArgumentException('Comparing sketch summaries is not supported').","triggerScenarios":"Using the string post-aggregator output as an ORDER BY key, topN metric, or sorting column in a limit spec.","commonSituations":"ORDER BY on the sketch summary column in SQL or native queries; treating the toString output as a sortable dimension.","solutions":["Sort by a scalar post-aggregator (quantile/histogram-derived value) from the same sketch.","Remove the ORDER BY / metric reference to the string post-aggregator.","If you just need the summary for display, keep it in postAggregators but exclude it from sorting specs."],"exampleFix":"// before\n{\"queryType\":\"topN\",\"metric\":\"sketchSummary\", ...}\n// after\n{\"queryType\":\"topN\",\"metric\":\"quantile50\", \"postAggregators\":[{\"type\":\"quantilesDoublesSketchToString\",...}]}","handlingStrategy":"validation","validationCode":"if (sortKeys.contains(toStringPostAggName)) { throw new IllegalArgumentException(\"Sketch summaries are not sortable\"); }","typeGuard":null,"tryCatchPattern":"try { druidClient.run(query); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Comparing sketch summaries\")) { /* drop sort key and rerun */ } }","preventionTips":["Use the string post-agg only for display/diagnostics.","Choose numeric post-aggs for ordering."],"tags":["druid","datasketches","unsupported-operation","sorting"],"backgroundTag":"operation-not-supported","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}