{"record":{"id":"f4be4ac19f8398c3","repo":"apache/druid","slug":"comparing-sketch-summaries-is-not-supported","errorCode":null,"errorMessage":"Comparing sketch summaries is not supported","messagePattern":"Comparing sketch summaries is not supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchToStringPostAggregator.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 KllDoublesSketch sketch = (KllDoublesSketch) 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        PostAggregatorIds.KLL_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/kll/KllDoublesSketchToStringPostAggregator.java#L65-L101","documentation":"KllDoublesSketchToStringPostAggregator.getComparator always throws IllegalArgumentException because a sketch's string summary is descriptive text, not an ordered value. The method satisfies the post-aggregator interface but comparison is deliberately unsupported.","triggerScenarios":"Requesting ordering on the string output of kllDoublesSketchToString, e.g. ORDER BY on the summary column, or framework code calling getComparator() for sorting.","commonSituations":"Sorting results by sketch summary text; generic result-table sorting in UI over string post-aggregator columns; SQL ORDER BY on the summary output.","solutions":["Do not ORDER BY on the sketch summary; order by a scalar metric or quantile instead","If text ordering is truly needed, extract the summary client-side and sort in application code","Have generic frameworks treat comparator-throwing post-aggregators as non-sortable"],"exampleFix":"// before\nORDER BY sketchSummary\n// after\nORDER BY sketchSummary IN CLIENT CODE  -- fetch rows, then sort strings in the app","handlingStrategy":"validation","validationCode":"if (postAgg instanceof KllDoublesSketchToStringPostAggregator) {\n  throw new IllegalArgumentException(\"Sketch summary output is not sortable\");\n}","typeGuard":null,"tryCatchPattern":"try { cmp = postAgg.getComparator(); } catch (IllegalArgumentException e) { cmp = null; }","preventionTips":["Treat string summaries as display-only, never sort keys","Sort client-side if text ordering is required","Skip comparator requests for descriptive post-aggregators"],"tags":["druid","datasketches","kll","post-aggregator","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}