{"record":{"id":"17db1c4c59e818b8","repo":"apache/druid","slug":"comparing-arrays-of-estimate-values-is-not-support","errorCode":null,"errorMessage":"Comparing arrays of estimate values is not supported","messagePattern":"Comparing arrays of estimate values is not supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchToMetricsSumEstimatePostAggregator.java","lineNumber":84,"sourceCode":"      for (int i = 0; i < values.length; i++) {\r\n        stats[i].addValue(values[i]);\r\n      }\r\n    }\r\n    final double[] estimates = new double[sketch.getNumValues()];\r\n    Arrays.setAll(estimates, i -> (stats[i].getSum()) / (sketch.getTheta()));\r\n    return estimates;\r\n  }\r\n\r\n  @Override\r\n  public ColumnType getType(ColumnInspector signature)\r\n  {\r\n    return ColumnType.DOUBLE_ARRAY;\r\n  }\r\n\r\n  @Override\r\n  public Comparator<double[]> getComparator()\r\n  {\r\n    throw new IAE(\"Comparing arrays of estimate values is not supported\");\r\n  }\r\n\r\n  @Override\r\n  public byte[] getCacheKey()\r\n  {\r\n    return new CacheKeyBuilder(AggregatorUtil.ARRAY_OF_DOUBLES_SKETCH_TO_METRICS_SUM_ESTIMATE_CACHE_TYPE_ID)\r\n        .appendCacheable(getField())\r\n        .build();\r\n  }\r\n}\r\n","sourceCodeStart":66,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchToMetricsSumEstimatePostAggregator.java#L66-L95","documentation":"ArrayOfDoublesSketchToMetricsSumEstimatePostAggregator emits a double[] (estimate plus error bounds of the summed metrics). Arrays of estimate values have no defined natural order, so getComparator() throws IAE unconditionally.","triggerScenarios":"Calling getComparator(), e.g. using this post-aggregator as a sort key in an orderBy spec or in tooling that requests comparators for all post-aggregators in a query.","commonSituations":"Users sorting query output by the sum-estimate array; generic framework code sorting post-aggregator columns.","solutions":["Sort on a single-value estimate post-aggregator or a plain numeric aggregator instead","Remove any ordering spec referencing this post-aggregator","Apply custom ordering in application code after fetching results"],"exampleFix":"// before\n.addOrderBy(new OrderByColumnSpec(\"metricsSumEstimate\"))\n// after\n.addOrderBy(new OrderByColumnSpec(\"sumEstimate\")) // single-value post-agg","handlingStrategy":"try-catch","validationCode":"if (orderByColumns.stream().anyMatch(c -> \"metricsSumEstimate\".equals(c.getDimension()))) {\n  throw new IllegalArgumentException(\"Cannot order by metrics-sum-estimate array output\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return queryClient.run(query);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"estimate values\")) {\n    return runQueryWithAlternateOrdering(query, \"sumEstimateScalar\");\n  }\n  throw e;\n}","preventionTips":["Prefer single-value estimate post-aggregators for sort keys","Keep array-valued post-aggregators out of ordering clauses","Type-check orderBy references against post-aggregator output types"],"tags":["druid","datasketches","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-17T15:17:12.973Z"}